Saturday, March 5, 2022

[FIXED] Composer in php-fpm docker from composer:1.8.4

Issue

I have a .dockerfile that builds a php-fpm image and I try to install composer from a docker image like so:

FROM php:7.3.3-fpm-alpine as base

WORKDIR /var/www

# Override Docker configuration: listen on Unix socket instead of TCP
RUN sed -i "s|listen = 9000|listen = /var/run/php/fpm.sock\nlisten.mode = 0666|" /usr/local/etc/php-fpm.d/zz-docker.conf

# Install dependencies
RUN set -xe \
    && apk add --no-cache bash icu-dev \
    && docker-php-ext-install pdo pdo_mysql intl pcntl

CMD ["php-fpm"]

FROM composer:1.8.4 as composer

RUN rm -rf /var/www && mkdir /var/www
WORKDIR /var/www

COPY composer.* /var/www/

ARG APP_ENV=dev

RUN set -xe \
    && if [ "$APP_ENV" = "prod" ]; then export ARGS="--no-dev"; fi \
    && composer install --prefer-dist --no-scripts --no-progress --no-suggesthere

The problem is that the COPY composer.* /var/www/ does not seem to work properly because it throws the error:

  • composer install --prefer-dist --no-scripts --no-progress --no-suggest --no-interaction --no-dev Composer could not find a composer.json file in /var/www

It seems like either the composer image is missing something or I skip some step, could you please assist, I am both new to docker and php.


Solution

Problem in the

WORKDIR /var/www

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile.

Any RUN, CMD, ADD, COPY, or ENTRYPOINT command will be executed in the specified working directory.

Source: https://www.educative.io/edpresso/what-is-the-workdir-command-in-docker



Answered By - Simbirsky

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.