title: (Docker) How to install dependencies, using separate Composer container, in WordPress container?
body: <h1>Dockerfile</h1>
  
  <pre><code>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 &amp;&amp; \
    apt-get -y upgrade &amp;&amp; \
    apt-get install -y vim wget &amp;&amp; \
    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/* &amp;&amp; \
    rm -rf /usr/src/wordpress/wp-content/themes/* &amp;&amp; \
    cp -fr /usr/src/wordpress/* /var/www/html/ &amp;&amp; \
    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"]
  </code></pre>
  
  <h1>Docker Compose File</h1>
  
  <pre><code>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
  </code></pre>
  
  <h1>Question details</h1>
  
  <p>I'm able to <code>ADD</code> the <code>composer.json</code> and <code>composer.lock</code> files to the working directory. I can confirm that these two files are in the working directory.</p>
  
  <p>What I need is for the Dockerfile (or wherever) to also automatically install the dependencies into the working directory.</p>
  
  <p>According to Docker Hub, <a href="https://hub.docker.com/r/composer/composer/" rel="nofollow">https://hub.docker.com/r/composer/composer/</a>,
  I should be able to <code>docker run -v $(pwd):/app composer/composer install</code> to install the dependencies but how do I do this in Dockerfile?</p>
  
  <p>Also I'm confused because the <code>-v</code> flag, <a href="https://docs.docker.com/engine/userguide/dockervolumes/" rel="nofollow">https://docs.docker.com/engine/userguide/dockervolumes/</a>, has to do with mounting the specified host directory into the a container but I've already <code>ADD</code>ed the necessary files to the working directory. All I want to do is install the dependencies.</p>
  
  <p>Thank you for your help.</p>