简体   繁体   English

(Docker)如何在WordPress容器中使用单独的Composer容器安装依赖项?

[英](Docker) How to install dependencies, using separate Composer container, in WordPress container?

Dockerfile Dockerfile

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 Compose File 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

Question details 问题详情

I'm able to ADD the composer.json and composer.lock files to the working directory. 我能够ADDcomposer.jsoncomposer.lock文件的工作目录。 I can confirm that these two files are in the working directory. 我可以确认这两个文件都在工作目录中。

What I need is for the Dockerfile (or wherever) to also automatically install the dependencies into the working directory. 我需要的是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? 根据Docker Hub, https: //hub.docker.com/r/composer/composer/,我应该能够docker run -v $(pwd):/app composer/composer install来安装依赖项,但我该怎么做在Dockerfile中执行此操作?

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. 另外我很困惑,因为-v标志, https://docs.docker.com/engine/userguide/dockervolumes/ ,与将指定的主机目录安装到容器中有关,但我已经ADD了必要的文件到工作目录。 All I want to do is install the dependencies. 我想要做的就是安装依赖项。

Thank you for your help. 谢谢您的帮助。

You just need to mount the current directory to /app when running your composer container. 您只需要在运行composer容器时将当前目录挂载到/app I've put together a simple example to illustrate this working at https://gist.github.com/andyshinn/e2c428f2cd234b718239 . 我在https://gist.github.com/andyshinn/e2c428f2cd234b718239上汇总了一个简单的例子来说明这一点。

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). 这里的关键部分是应用程序的composer部分的volumesrestart: 'yes'主PHP应用程序上的restart: 'yes' (在Composer运行之前,应用程序可能无法运行,因此您希望它重新启动)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM