Docker文件
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文件添加到工作目录中.我可以确认这两个文件在工作目录中.
我需要的是Dockerfile(或其他位置)也将依赖项自动安装到工作目录中.
根据Docker Hub的https://hub.docker.com/r/composer/composer/,
我应该能够docker运行-v ${pwd):/ app composer / composer install来安装依赖项,但是我该如何在Dockerfile中做到这一点呢?
我也很困惑,因为-v标志https://docs.docker.com/engine/userguide/dockervolumes/与将指定的主机目录装入容器有关,但是我已经将必要的文件添加到了工作目录中.我要做的就是安装依赖项.
谢谢您的帮助.
最佳答案
运行作曲家容器时,只需要将当前目录挂载到/ app即可.我整理了一个简单的示例来说明在https://gist.github.com/andyshinn/e2c428f2cd234b718239下的工作情况.
原文链接:https://www.f2er.com/docker/532602.html这里的关键部分是应用程序的作曲家部分和重新启动的卷:在主程序上为“是”(该应用程序可能要到Composer运行后才能运行,因此您希望它重新启动).