Created
September 9, 2014 14:16
-
-
Save acaranta/ddf80e1f9be7b51216e2 to your computer and use it in GitHub Desktop.
Python am I running in a docker and if so what is its ID
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
#Determines if we run within a docker container | |
#Might not be truly cleany as a way to check but it works ;) | |
def dockerized(): | |
if 'docker' in open('/proc/1/cgroup').read(): | |
return True | |
def getowndockerid(): | |
dockerid = "" | |
for line in open('/proc/1/cgroup'): | |
if "docker" in line: | |
dockerid = re.search(r".*/docker/(.*)$",line) | |
return dockerid.group(1) | |
if dockerid == "": | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment