Created
February 11, 2025 11:59
-
-
Save bloodearnest/9f813cc88dcc04f9f58ff4d636ebdfc0 to your computer and use it in GitHub Desktop.
Simple multiprocess dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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