Render Config in the Entrypoint, Safely
The payouts image renders its config at start-up with /home/student/projects/payouts/docker-entrypoint.sh, from the template config.json.tmpl next to it. Problems seen in production:
/ crashed the container with a sed error, one with & produced a wrong password,"$schema" and the price format "$ 0.00" in the template got mangled,SIGTERM and its arguments lose their quoting.Fix docker-entrypoint.sh. It reads CONFIG_TEMPLATE (default /app/config.json.tmpl) and writes CONFIG_OUT (default /tmp/app/config.json, creating the directory if needed), then:
DB_HOST or DB_PASSWORD is unset or empty, prints missing required variable: NAME to stderr for each and exits 64 without running anything,PORT defaults to 8080,${PORT}, ${DB_HOST} and ${DB_PASSWORD} with the values as they are, and changes nothing else,600),Test it locally, for example: CONFIG_TEMPLATE=config.json.tmpl CONFIG_OUT=/tmp/t/config.json DB_HOST=db DB_PASSWORD='a/b&c' ./docker-entrypoint.sh cat /tmp/t/config.json.
About this machine
Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.
Part of Docker Fundamentals. Next step: Compute Image Tags in CI
Teaching or writing about this? Embed this lab on your page
Your machine is ready to start
A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.
No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.