Skip to content

Instantly share code, notes, and snippets.

@acaranta
Created September 9, 2014 14:16
Show Gist options
  • Save acaranta/ddf80e1f9be7b51216e2 to your computer and use it in GitHub Desktop.
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
#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