Settings are most often passed to an application in a container through environment variables.
The main process gets its environment variables from Docker. Some are set in the image, such as PATH. You add your own with the -e NAME=value option of docker run, one -e per variable. Many ready-made images are configured this way: the operating mode, a database address, a user name.
There are two ways to see what the process got. docker exec <name> env prints the environment inside a running container. docker inspect <name> prints the full description of the container as JSON, and the --format option picks a field from it — here the list of variables:
Like ports, the environment is set at creation: you cannot change it on an existing container, only re-create the container with the right -e options.
The server runs a worker container from the worker:1 image, a practice application that checks a task queue every 5 seconds. It takes its operating mode from the APP_MODE variable and writes it to its log.
Switch worker to prod mode
Look at the log and the environment of the worker container, then switch the application to prod mode: a line with mode=prod must appear in the worker log. The image is worker:1, the container name stays the same.
Goals · 0 of 2
- Give the application the prod mode not done yet
- Keep worker running on the worker:1 image not done yet