Skip to content

Instantly share code, notes, and snippets.

@albertzak
Created November 29, 2017 22:58
Show Gist options
  • Save albertzak/6c28d9a76a536c810b0ca033dcd6bace to your computer and use it in GitHub Desktop.
Save albertzak/6c28d9a76a536c810b0ca033dcd6bace to your computer and use it in GitHub Desktop.
Running Inside Container?
#!/bin/bash
is_container () {
cgroup_output=$(cat /proc/self/cgroup 2>&1)
echo "$cgroup_output" | grep -E '/docker/|/lxc/' > /dev/null
return $?
}
if is_container; then
echo "I'm trapped inside a container."
else
echo "Wohoo, I'm free!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment