Startup behaviour

Startup behaviour

Containerized processes are configured using environment variables:

docker run -d --name mysql mysql
docker logs mysql

The container read environment variables and changes its behaviour:

docker run -d --name mysql2 --env MYSQL_RANDOM_ROOT_PASSWORD=yes mysql
docker logs mysql2


CMD configured the default command:

$ cat Dockerfile.cmd
FROM ubuntu
CMD [ "ps" ]
$ docker build --file Dockerfile.cmd --tag cmd .
$ docker run -it --rm cmd

ENTRYPOINT receives CMD as parameters:

$ cat Dockerfile.entrypoint
FROM ubuntu
CMD [ "faux" ]
$ docker build --file Dockerfile.entrypoint --tag entrypoint .
$ docker run -it --rm entrypoint

My first entrypoint

Add an entrypoint to change the behaviour

Example: Change text in web page

docker build \
    --tag my-nginx \
docker run --detach \
    --publish \
    --env WELCOME_TO_TEXT="Haufe X360" \
curl localhost

More use cases

Change configuration of nginx in /etc/nginx