title: Docker - Execute command after mounting a volume
body: <p>I have the following Dockerfile for a php runtime based on the official <code>[php][1]</code> image.</p>
  <pre class="lang-docker prettyprint-override"><code>FROM php:fpm
  WORKDIR /var/www/root/
  RUN apt-get update &amp;&amp; apt-get install -y \
          libfreetype6-dev \
          libjpeg62-turbo-dev \
          libmcrypt-dev \
          libpng12-dev \
          zip \
          unzip \
      &amp;&amp; docker-php-ext-install -j$(nproc) iconv mcrypt \
      &amp;&amp; docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
      &amp;&amp; docker-php-ext-install -j$(nproc) gd \
      &amp;&amp; docker-php-ext-install mysqli \
      &amp;&amp; docker-php-ext-enable opcache \
      &amp;&amp; php -r &quot;copy('https://getcomposer.org/installer', 'composer-setup.php');&quot; \
      &amp;&amp; php -r &quot;if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;&quot; \
      &amp;&amp; php composer-setup.php \
      &amp;&amp; php -r &quot;unlink('composer-setup.php');&quot; \
      &amp;&amp; mv composer.phar /usr/local/bin/composer
  </code></pre>
  <p>I am having trouble running <code>composer install</code>.</p>
  <p>I am guessing that the Dockerfile runs before a volume is mounted because I receive a <code>composer.json</code> file not found error if adding:</p>
  <pre><code>...
  &amp;&amp; mv composer.phar /usr/local/bin/composer \
  &amp;&amp; composer install
  </code></pre>
  <p>to the above.</p>
  <p>But, adding the following property to <code>docker-compose.yml</code>:</p>
  <pre><code>command: sh -c &quot;composer install &amp;&amp; composer require drush/drush&quot;
  </code></pre>
  <p>seems to terminate the container after the command finishes executing.</p>
  <p>Is there a way to:</p>
  <ul>
  <li>wait for a volume to become mounted</li>
  <li>run <code>composer install</code> using the mounted <code>composer.json</code> file</li>
  <li>have the container keep running afters</li>
  </ul>
  <p>?</p>