Skip to content

Instantly share code, notes, and snippets.

@anantkamath
Created October 30, 2016 17:26
Show Gist options
  • Select an option

  • Save anantkamath/623ce7f5432680749e087cf8cfba9b69 to your computer and use it in GitHub Desktop.

Select an option

Save anantkamath/623ce7f5432680749e087cf8cfba9b69 to your computer and use it in GitHub Desktop.
Check if you're running inside a Docker container in Python
def runningInDocker():
with open('/proc/self/cgroup', 'r') as procfile:
for line in procfile:
fields = line.strip().split('/')
if fields[1] == 'docker':
return True
return False
@scorpiodawg
Copy link

Does this work on Windows? Don't have a Windows machine handy to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment