Skip to content

Instantly share code, notes, and snippets.

@cbitterfield
Created January 22, 2020 04:16
Show Gist options
  • Save cbitterfield/2fca92d19517d3466cffffc17f778060 to your computer and use it in GitHub Desktop.
Save cbitterfield/2fca92d19517d3466cffffc17f778060 to your computer and use it in GitHub Desktop.
Find out if the python program is running in a docker container
#!/usr/bin/env python3
def runningInDocker():
with open('/proc/self/cgroup', 'r') as procfile:
for line in procfile:
fields = line.strip().split('/')
if 'docker' in fields:
return True
return False
print(runningInDocker())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment