Skip to content

Instantly share code, notes, and snippets.

@bloodearnest
Created February 11, 2025 11:59
Show Gist options
  • Save bloodearnest/9f813cc88dcc04f9f58ff4d636ebdfc0 to your computer and use it in GitHub Desktop.
Save bloodearnest/9f813cc88dcc04f9f58ff4d636ebdfc0 to your computer and use it in GitHub Desktop.
Simple multiprocess dockerfile
$ docker build . -t multiprocess-image # must use --init to get proper signal propagation to background process
$ docker run --init --name multiprocess-container --detach multiprocess-image
$ docker kill -s SIGINT multiprocess-container # signal will be sent to both processes
# Sometimes, you want to run a simple background process, as well as your main process, e.g. webserver.
# You can run multiple instances of your container, or you can use s6 or other supervisor tool
#
# Or, you can use a couple of simple tools
FROM ubuntu:22.04
RUN apt update && apt install run-one # for run-one-constantly
# set up your app here
# tell tini to kill the whole process group, not just the one process
ENV TINI_KILL_PROCESS_GROUP=1
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
#!/bin/bash
set -eu
# restart worker-process if it exists, with backoff
run-one-constantly worker-process &
exec main-process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment