skip to Main Content

I’m trying to make a multistage Dockerfile that has a stage for testing. When I run the container, after the command end the container didn’t stop.

My expectation is, I will have a testing stage that will be use to run PHPUnit command inside the docker, that stage is only going to be used as a helper and after it run it will exit automatically. But for some reason the container never exit even after the command end.

This is my Dockerfile snippet:

FROM php:8.2-fpm AS final
WORKDIR /var/www/html
# Do some setup here

FROM final AS tester
RUN pecl install pcov 
    && echo "extension=pcov.so" >> /usr/local/etc/php/php.ini
RUN echo "alias ppc='php artisan test --parallel --coverage --coverage-text'" >> ~/.bashrc
ENTRYPOINT []
CMD ["/bin/bash", "-c", "php artisan test --parallel --coverage --coverage-text"]

2

Answers


  1. You may try to add this at the end of the command:

    && docker stop <your container name>
    
    Login or Signup to reply.
  2. Remove ENTRYPOINT [] in the tester stage and update the CMD as follows:

    FROM final AS tester
    RUN pecl install pcov 
        && echo "extension=pcov.so" >> /usr/local/etc/php/php.ini
    RUN echo "alias ppc='php artisan test --parallel --coverage --coverage-text'" >> ~/.bashrc
    CMD ["php", "artisan", "test", "--parallel", "--coverage", "--coverage-text"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search