Container always return exited with code 0 when composer install or update command

My container always exit while i try to run the composer command below

CMD ["composer", "update"]

It is a php container and i would like to install the vendor folder of my application
Here is my Dockerfile

FROM php:7.4-fpm-alpine

WORKDIR /var/www

COPY . /var/www

ENV COMPOSER_HOME /composer
ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer

EXPOSE 9000

CMD ["composer", "update"]

If i don’t run the composer update command no error occur and the container runs well

I have tried to separate the composer container but exit as well while i run composer update command

I am running with a nginx container

Does someone where does the problem is coming from?

Thank you

Can you maybe try and “docker run -ti IMAGE bash”
and in the container, try and run compose update, to see if that provides any usefull output

@terpz , thanks for your answer
Yes I have tried and it is working but I would like to automize it while running the container…

Do you have anything in the PHP container log?

If composer stops the container, it could mean it sends signal to the main process. If it happens during the update before finishing it, I can imagine memory issue, but it should not exit with 0 in that case.

During development, you can move the vendor folder to a volume and mount it to an other container which runs composer. In production, I would not run composer update at all. I would create an image that contains everything.

I just realized something, what is your goal here?

Because when you run composer update as CMD, it shoud exit when it completes, because the program you asked it to run, is complete.

i belive you need to change your composer update to a RUN instead of CMD.

CMD (together with entrypoint) defines what should run when the container starts, if your goal is to mount a folder and update its contents, and then exit, then i guess it will work?

But if you plan to make a webserver in that container, this wont work, you then need to set CMD to something like “php -S 0.0.0.0:8080”

1 Like

Thanks @rimelek for your answer
I just needed to RUN instead of CMD…
For the automation, i was thinking about composer install (not update) to install all the php packages required for the application

@terpz
oh, that was it, i just wanted to install the php packages from composer
i just needed to RUN and not CMD it…
thanks a lot!