Naveen Vijay
Naveen Vijay

Reputation: 16492

Right way to use ENTRYPOINT to enable container start and stop

I am having a custom image built using the Dockerfile. Apparently a fresh run works fine however when I stop the container and start it again - it doesn't start and remain in the state of Exit 0.

The image is composed of apache2 and bunch of php modules for symfony web application.

This is how Dockerfile end

RUN a2enmod rewrite
CMD service apache2 restart
ENTRYPOINT ["/usr/sbin/apache2ctl"]
CMD ["-D", "FOREGROUND"]
EXPOSE 80

I see containers commonly using docker-entrypoint.sh but unsure of what goes in and the role it plays.

Upvotes: 1

Views: 2342

Answers (1)

BMitch
BMitch

Reputation: 263716

The entrypoint shouldn't have anything to do with your container not restarting. Your problem is most likely elsewhere and you need to look at the logs from the container to debug. The output of docker diff ... may also help to see what has changed in the container filesystem.

If an ENTRYPOINT isn't defined, docker runs the CMD by default. If an ENTRYPOINT is defined, anything in CMD becomes a cli argument to the entrypoint script. So in your above example, it will start (or restart) the container with /usr/sbin/apache2ctl -D FOREGROUND. Anything you append after the container name in the docker run command will override the value of CMD. And you can override the value of the ENTRYPOINT with docker run --entrypoint ....

See Docker's documentation on the entrypoint option for more details.

Upvotes: 4

Related Questions