Skip to content

Instantly share code, notes, and snippets.

@leiless
Last active February 19, 2023 13:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leiless/a4558b67c9d7da7d64e32c00e06dda7a to your computer and use it in GitHub Desktop.
Save leiless/a4558b67c9d7da7d64e32c00e06dda7a to your computer and use it in GitHub Desktop.
Check if the script is running in the Docker/Podman/K8S
#!/bin/bash
# If you using sh, please remove the `-o pipefail`
set -eufo pipefail
#set -x
check_in_container() {
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ] && [ -z ${KUBERNETES_SERVICE_HOST+x} ]; then
echo "[ERR] This script should be run inside a container environment!"
exit 1
fi
}
check_in_container