docker-compose.yml

version: '3' services: web: build: . ports: - 80:80 volumes: - ./:/var/www/html 

Dockerfile

 FROM php:7.2-apache # Set public directory as root for Apache ENV APACHE_DOCUMENT_ROOT=/var/www/html/public RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf WORKDIR /var/www/html RUN apt-get update \ && apt-get install -y git \ && curl --silent --show-error https://getcomposer.org/installer | php \ && php composer.phar install 

Composer generates an error when installing dependencies

ERROR: Service 'web' failed to build: The command '/ bin / sh -c apt-get update && apt-get install -y git && curl --silent --show-error https://getcomposer.org/installer | php && php composer.phar install 'returned a non-zero code: 1

Moreover, if you go directly to the container and perform the installation through the composer, then everything works.

  • replace with FROM php:7.2-fpm - Senior Pomidor
  • @SeniorPomidor Well, I need an apache for me. - Hardc0re pm
  • you can’t install it because Composer could not find a composer.json file in /var/www/html . You can fix this by running ./composer.phar global require "laravel/installer" , but for this you need to install additional components again. Or, it will be easier if you use FROM php: 7.2-fpm - Senior Pomidor
  • There is no difference what to use, you just need to properly build the process of development and deployment. FPM has nothing to do with it. - diproart

1 answer 1

Build - build: ... , this is about the image. And volumes: ... it's about the container.

At the time of assembly, the directory is not mounted and, accordingly, there is no composer.json .

You can "drop" the composer.json file into an image at the build stage ( COPY ... ), but when you mount, in your case, the directory will overlap local and there is no point. That is, you need to think about what and how to mount.

Different approaches can be used for development and deployment. Usually, during the development phase, installation commands are executed via docker-compose run/exec ... And at the stage of assembling the image files are copied and then commands are executed. For example:

 RUN apt-get update -qq && apt-get install -y git ... WORKDIR /var/www/html COPY . /var/www/html RUN curl --silent --show-error https://getcomposer.org/installer | php \ && php composer.phar install 

Of course, you can cache / mount dependencies separately. You need to look carefully at the project and think about how to make it more convenient.