Skip to content
Discussion options

You must be logged in to vote

You can handle this by modifying your Docker image to include the init script via CMD or ENTRYPOINT, and using a custom environment variable like IS_MASTER to control whether the script runs.

🔧 Example Approach:

  1. Add the init script to your image, and make your init script check for a flag:
# entrypoint.sh
if [ "$IS_MASTER" = "true" ]; then
  ./run-the-code
fi
  1. Set the IS_MASTER env var when running just one container:

docker run -e IS_MASTER=true true your-image

And for the others:

docker run your-image

This way, you keep a single image but control behavior cleanly through environment variables.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by qwertyarpit
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development
3 participants