09 Entrypoint vs Cmd - dchantzis/sfh-docker-in-development-part-1 GitHub Wiki
Source: https://serversforhackers.com/c/div-entrypoint-vs-cmd
We see how to use an ENTRYPOINT instead of CMD within a Dockerfile in order to setup a script that is always run (no matter what) when a container is spun up from the image we make.
Create the new file start-container.sh
inside docker/app
:
vim docker/app/start-container.sh
Update the Dockerfile
by adding the following (remove or comment out the line CMD ["supervisord"]
):
ADD start-container.sh /usr/bin/start-container.sh
RUN chmod +x /usr/bin/start-container
ENTRYPOINT ["start-container"]
First make sure env
exists in the Container:
docker run -it --rm -p 8080:80 -v %cd%/application:/var/www/html/public shippingdocker/app:latest bash
which env
so env bash
will give us the correct bash.
Copy the location of the env
file (example: /usr/bin/env
).
Update the start-container.sh
:
#!/usr/bin/env bash
##
# Ensure /.composer exists and is writable
#
if [ ! -d /.composer ]; then
mkdir /.composer
fi
chmod -R ugo+rw /.composer
##
# Run a command or start supervisord (default to supervisord)
#
if [ $# -gt 0 ];then
# If we passed a command, run it
exec "$@"
else
# Otherwise start supervisord
/usr/bin/supervisord
fi