Skip to content

Instantly share code, notes, and snippets.

@jpbochi
Created June 13, 2025 11:59
Show Gist options
  • Save jpbochi/ba01d87a9c6faf4851d96b4f38334a36 to your computer and use it in GitHub Desktop.
Save jpbochi/ba01d87a9c6faf4851d96b4f38334a36 to your computer and use it in GitHub Desktop.
docker-run-loop-prevention.sh
# Prevent infinite loops - run `exec` when executed from within the container
# for containers started with --init
[ "$(cat /proc/1/comm)" == "docker-init" ] && exec env -- "$@"
# for other containers - inspired by https://github.com/starship/starship/blob/master/src/modules/container.rs#L58
[ "$(cat /run/systemd/container)" == "docker" ] && exec env -- "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment