Created
October 30, 2016 17:26
-
-
Save anantkamath/623ce7f5432680749e087cf8cfba9b69 to your computer and use it in GitHub Desktop.
Check if you're running inside a Docker container in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Sometimes fields[1] is reported as 'docker-ce' and fields=['13:name=systemd:', 'docker-ce', 'docker', 'blah']
Should we instead use: