我正在使用docker为几个wordpress主题/插件运行开发环境。但是,我无法弄清楚如何在容器创建时自动启用我的主题。通常我只会使用wp-cli。我已经创建了一个扩展官方wordpress图像的自定义图像,但我无法弄清楚如何在/ var / www / html文件夹设置之后运行wp-cli命令(我认为这是由wordpress图像创建的)入口点脚本)。如果我将命令放在dockerfile中的“RUN”命令中,命令就会失败,因为/ var / www / html目录为空。但是,如果我在设置后连接到容器,则会填充目录,并且wp-cli可以正常工作。如何在运行父图像的entrypoint.sh后运行命令?
这是我的dockerfile的内容(不起作用):
FROM wordpress
MAINTAINER Me!
COPY docker-install/wp-cli.phar /usr/local/bin/wp
WORKDIR /var/www/html
RUN chmod u+x /usr/local/bin/wp
RUN /usr/local/bin/wp core install --title="Test WP Site" --admin_user=admin --admin_password=something --admin_email=my@cool.email --url=localhost:8080 --allow-root
RUN /usr/local/bin/wp theme activate mytheme --allow-root
答案 0 :(得分:1)
The short answer: You can't. The ENTRYPOINT
and CMD
is are used at Docker container runtime, not build time. In this case, the Wordpress environment is actually started at container runtime so you can't interact with it during a build.
The long answer: You might be able to help accomplish your goals by using Docker Compose to create two services, one for Wordpress and another for the Wordpress CLI variant (see the cli
tags at https://hub.docker.com/_/wordpress/) with a volumes_from
the first one. Then, you could use docker-compose run cli-service wp-cli command
to run your commands.
答案 1 :(得分:0)
我创建了一个prepare.sh
文件,其中包含我想在Apache启动之前运行的命令,然后将其添加到Dockerfile中:
COPY ./prepare.sh /prepare.sh
RUN chmod +x /prepare.sh
CMD /prepare.sh && apache2-foreground
答案 2 :(得分:0)
您应该创建一个在docker-entrypoint之后安装主题的脚本。该名称必须以apache2开头(docker-entrypoint检查CMD param https://github.com/docker-library/wordpress/blob/0a5405cca8daf0338cf32dc7be26f4df5405cfb6/php5.6/apache/docker-entrypoint.sh#L26的名称),例如apache2-setup-wordpress.sh。
Dockerfile就像这样
FROM wordpress:4.7.3
COPY apache2-setup-wordpress.sh /usr/local/bin
RUN chmod +x /usr/local/bin/apache2-setup-wordpress.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-setup-wordpress.sh", "apache2-foreground"]