(Docker)如何在 WordPress 容器中使用单独的 Composer 容器安装依赖项? [英] (Docker) How to install dependencies, using separate Composer container, in WordPress container?
问题描述
FROM wordpress
ENV REFRESHED_AT 2015-08-12
ADD
composer.json /var/www/html
ADD
composer.lock /var/www/html
# install the PHP extensions
RUN
apt-get -qq update &&
apt-get -y upgrade &&
apt-get install -y vim wget &&
rm -rf /var/lib/apt/lists/*
# Symlink User's "wp-content" folder into the newly installed Wordpress
RUN
rm -rf /usr/src/wordpress/wp-content/plugins/* &&
rm -rf /usr/src/wordpress/wp-content/themes/* &&
cp -fr /usr/src/wordpress/* /var/www/html/ &&
chown -R www-data:www-data /var/www/html/
# volume for mysql database and wordpress install
VOLUME ["/var/www/html/wp-content/plugins", "/var/www/html/wp-content/themes"]
# Define working directory.
WORKDIR /var/www/html/
EXPOSE 80 3306
CMD ["apache2-foreground"]
Docker 编写文件
wordpress:
build: .
links:
- mysql
- composer
volumes:
- wp-content/plugins/:/var/www/html/wp-content/plugins
- wp-content/themes/:/var/www/html/wp-content/themes
environment:
- WORDPRESS_DB_PASSWORD=__WORDPRESS_DB_PASSWORD__
- WORDPRESS_DB_NAME=__WORDPRESS_DB_NAME__
# - WORDPRESS_DB_USER=__WORDPRESS_DB_USER__
ports:
- "9888:80"
mysql:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=__WORDPRESS_DB_PASSWORD__
- MYSQL_DATABASE=__WORDPRESS_DB_NAME__
composer:
image: composer/composer
问题详情
我能够将 composer.json
和 composer.lock
文件ADD
到工作目录.我可以确认这两个文件在工作目录中.
Question details
I'm able to ADD
the composer.json
and composer.lock
files to the working directory. I can confirm that these two files are in the working directory.
我需要的是 Dockerfile(或任何地方)也自动将依赖项安装到工作目录中.
What I need is for the Dockerfile (or wherever) to also automatically install the dependencies into the working directory.
根据 Docker Hub,https://hub.docker.com/r/composer/作曲家/,我应该能够 docker run -v $(pwd):/app composer/composer install
来安装依赖项,但是如何在 Dockerfile 中执行此操作?
According to Docker Hub, https://hub.docker.com/r/composer/composer/,
I should be able to docker run -v $(pwd):/app composer/composer install
to install the dependencies but how do I do this in Dockerfile?
我也很困惑,因为 -v
标志 https://docs.docker.com/engine/userguide/dockervolumes/,与将指定的主机目录挂载到容器中有关,但我已经 ADD
ed 必要的文件到工作目录.我要做的就是安装依赖项.
Also I'm confused because the -v
flag, https://docs.docker.com/engine/userguide/dockervolumes/, has to do with mounting the specified host directory into the a container but I've already ADD
ed the necessary files to the working directory. All I want to do is install the dependencies.
感谢您的帮助.
推荐答案
您只需在运行 composer
容器时将当前目录挂载到 /app
即可.我在 https://gist.github.com/andyshinn/整理了一个简单的例子来说明这个工作e2c428f2cd234b718239.
You just need to mount the current directory to /app
when running your composer
container. I've put together a simple example to illustrate this working at https://gist.github.com/andyshinn/e2c428f2cd234b718239.
这里的关键部分是应用程序 composer
部分的 volumes
和主要 PHP 应用程序上的 restart: 'yes'
(应用程序可能在 Composer 运行之前不会运行,因此您希望它重新启动).
The key parts here are the volumes
for the composer
part of the application and the restart: 'yes'
on the primary PHP application (the application likely will not run until Composer has run so you will want it to restart).
这篇关于(Docker)如何在 WordPress 容器中使用单独的 Composer 容器安装依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!