title: How run composer install from dockerfile in php container
body: <p>Good day I have php container which seting up in Dockerfile</p>
  
  <p>I am trying to run composer install with this command</p>
  
  <pre><code>WORKDIR '/app'
  RUN curl -sS https://getcomposer.org/installer | \
              php -- --install-dir=/usr/bin/ --filename=composer
          CMD bash -c "composer install &amp;&amp; php artisan serve --host 0.0.0.0 --port 80"
      EXPOSE 80
      EXPOSE 22
      CMD ["php-fpm"]
  </code></pre>
  
  <p>But I didnt get the error, and can not run application because of the composer install didnt worked.Just white screen of laravel which mean composer was not installed.</p>
  
  <p>If I run after docker compose up</p>
  
  <pre><code>docker run -it --rm -v $(pwd):/app composer/composer install
  </code></pre>
  
  <p>I receive an error
  Composer could not find a composer.json file in /app
  To initialize a project, please create a composer.json file as described in the <a href="https://getcomposer.org/" rel="nofollow noreferrer">https://getcomposer.org/</a> "Getting Started" section</p>
  
  <p>If I trying to COPY project dirrectory I receive an error</p>
  
  <pre><code>COPY /var/www/docker/project /app
  </code></pre>
  
  <p>ERROR: Service 'php' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder091462376/var/www/docker/project: no such file or directory
  While I have the volumes in php container in docker-compose.yml</p>
  
  <pre><code>volumes:
              - ${APP_PATH_HOST}:${APP_PATH_CONTAINER}
              - /app/vendor/
  </code></pre>
  
  <p>Here is my docker-compose.yml</p>
  
  <pre><code>version: '2'
  services:
      nginx:
       image: nginx:latest
       container_name: "${PROJECT_NAME}_nginx"
       environment:
         NGINX_STATIC_OPEN_FILE_CACHE: "off"
         NGINX_ERROR_LOG_LEVEL: debug
         NGINX_BACKEND_HOST: php
         NGINX_VHOST_PRESET: php
         NGINX_SERVER_ROOT: /app/public
       ports:
          - "80:80"
          - "443:443"
       volumes:
          - ./hosts:/etc/nginx/conf.d
          - ${APP_PATH_HOST}:${APP_PATH_CONTAINER}
          - ./logs:/var/log/nginx
       links:
          - php
  
       labels:
         - 'traefik.backend=nginx'
         - 'traefik.port=80'
         - 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'  
      php:
          build: ./images/php
          links:
              - mariadb
          #command: bash -c 'cd /app composer install'    
          volumes:
              - ${APP_PATH_HOST}:${APP_PATH_CONTAINER}
              - /app/vendor/
  
      mariadb:
       image: wodby/mariadb:$MARIADB_TAG
       container_name: "${PROJECT_NAME}_mariadb"
       stop_grace_period: 30s
       environment:
        MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
        MYSQL_DATABASE: $DB_NAME
        MYSQL_USER: $DB_USER
        MYSQL_PASSWORD: $DB_PASSWORD
  
      pma:
       image: phpmyadmin/phpmyadmin
       container_name: "${PROJECT_NAME}_pma"
       ports:
          - "9000:80"
       environment:
         PMA_HOST: $DB_HOST
         PMA_USER: $DB_USER
         PMA_PASSWORD: $DB_PASSWORD
         PHP_UPLOAD_MAX_FILESIZE: 1G
         PHP_MAX_INPUT_VARS: 1G
       labels:
        - 'traefik.backend=pma'
        - 'traefik.port=80'
        - 'traefik.frontend.rule=Host:pma.${PROJECT_BASE_URL}'
  </code></pre>
  
  <p>Here is completely Dockerfile</p>
  
  <pre><code>FROM php:7.2-fpm-alpine3.6
  WORKDIR '/app'
  RUN apk update &amp;&amp; apk upgrade\
      &amp;&amp; apk add --no-cache curl libbz2 php7-bz2 php7-pdo php7-pgsql php7-bcmath php7-zmq php7-curl bash php7-pear php7-imagick openssh imap-dev\
      libtool \
      postgresql-dev \
      libpng-dev \
      imagemagick-c++ \
      imagemagick-dev \
      libmcrypt-dev \
      libxml2-dev \
      yaml-dev \
      bzip2 \
      aspell-dev \
      autoconf \
      build-base \
      linux-headers \
      libaio-dev \
      zlib-dev \
      git \
      subversion \
      freetype-dev \
      libjpeg-turbo-dev \
      libmcrypt-dev \
      bzip2-dev \
      libstdc++ \
      libxslt-dev \
      openldap-dev \
      hiredis-dev \
      make \
      unzip \
      ffmpeg \
      wget
  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  RUN docker-php-ext-configure imap --with-imap --with-imap-ssl \
    &amp;&amp; docker-php-ext-install -j 4 imap 
  
  
  RUN docker-php-ext-install gd bcmath zip bz2 pdo pdo_mysql simplexml opcache sockets mbstring pcntl xsl pspell
  RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ 
  RUN pecl install imagick
  RUN docker-php-ext-enable imagick 
  RUN pecl install xdebug
  RUN wget http://xdebug.org/files/xdebug-2.6.1.tgz
  RUN tar -xvzf xdebug-2.6.1.tgz
  RUN cd xdebug-2.6.1 \
      &amp;&amp; phpize \
      &amp;&amp; ./configure --enable-xdebug \
      &amp;&amp; make \
      &amp;&amp; make install \
      &amp;&amp; cp modules/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718 \
      &amp;&amp; echo 'zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so' &gt;&gt; /usr/local/etc/php/php.ini \
      &amp;&amp; echo 'zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so' &gt;&gt; /etc/php7/php.ini \
      &amp;&amp; echo 'xdebug.remote_enable=true' &gt;&gt; /etc/php7/php.ini \
      &amp;&amp; echo 'xdebug.remote_host=127.0.0.1' &gt;&gt; /etc/php7/php.ini \
      &amp;&amp; echo 'xdebug.remote_port=9000' &gt;&gt; /etc/php7/php.ini \
      &amp;&amp; echo 'xdebug.remote_handler=dbgp' &gt;&gt; /etc/php7/php.ini \
      &amp;&amp; echo 'xdebug.max_nesting_level=512' &gt;&gt; /etc/php7/php.ini
  
  ENV COMPOSER_ALLOW_SUPERUSER 1
  
  RUN echo "Install ZeroMQ library and PHP extension"
  RUN apk add --update autoconf gcc libzmq zeromq-dev zeromq coreutils build-base
  RUN pecl install zmq-beta \
    &amp;&amp; docker-php-ext-enable zmq
  #COPY ./project /app
  RUN curl -sS https://getcomposer.org/installer | \
      php -- --install-dir=/usr/bin/ --filename=composer
  #RUN "composer install"
  
  
  EXPOSE 80
  
  EXPOSE 22
  #CMD php artisan serve --host=0.0.0.0 --port=80
  #CMD php artisan migrate --seed
  
  CMD ["php-fpm"]
  USER root
  copy run.sh /run.sh
  RUN chmod +x /run.sh  
  RUN ls
  #RUN ["chmod", "+x", "/run.sh"]
  COPY ./././project app/
  RUN composer install --no-dev --no-interaction -o
  
  CMD ["/run.sh"]
  </code></pre>