Container with multiple processes

ctop showing multiple processes

Last week, I needed to create a docker image doing a simple thing:

  • downloading 1 XML file
  • converting it to JSON
  • serve both files

But I’ve a hard part: every 15 minutes, I need to look if a new version of the XML file is available and in case, running the entire process.

Let’s go to see how I did it

Requirements

Docker image creation

I use Python container based on alpine linux as the base, adding an environment variable to avoid PIP cache (Dockerfile: line 2).

To have multiple processes inside the contianer, I use s6-overlay and I think to rewrite the global path (Dockerfile: line 13) because by default it’s not including the path where Python binaries (pip, python) are installed.

Process with dependencies and type of run

S6-overlay permits to define dependencies between processus and it’s exactly what I need because:

  • docker-entrypoint needs to run before running the real nginx daemon but without persistance, it’s a oneshot at boot
  • cron daemon needs to run in background and has 0 dependency
  • nginx unit needs to run in background when docker-entrypoint has ended the configuration

cron

To setup cron, we have few steps inside the Dockerfile:

  • copy the shell script (Dockerfile: line 7) to execute cron as the daemon
  • set this script (Dockerfile: line 21) has “longrun”
  • add it (Dockerfile: line 28) to be run at boot

nginx unit

Steps:

  • copy the shell script (Dockerfile: line 8) to execute nginx unit as a daemon
  • set unit log file (Dockerfile: line 18) to output on /dev/stdout
  • set nginx access log (Dockerfile: line 19) to output on /dev/stdout
  • set this script (Dockerfile: line 22) has “longrun”
  • add docker-entrypoint (Dockerfile: line 23) has a dependency
  • add it (Dockerfile: line 27) to be run at boot

docker-entrypoint

Steps:

  • create the directory (Dockerfile: line 24) where we’ll had config files
  • set this script (Dockerfile: line 25) has “oneshot”
  • set the command (Dockerfile: line 26) to execute the docker-entrypoint (I don’t copy the file like for other service)

Entrypoint

Finally, we’ll use s6 has the entrypoint (Dockerfile: line 39) for this container

The repository: xmltv_tnt_json_unit