Reputation: 135
I need to get the containers name, from within the running container in python
i could easily get the container id from inside the container in python with
bashCommand = """head -1 /proc/self/cgroup|cut -d/ -f3"""
output = subprocess.check_output(['bash','-c', bashCommand])
print output
now i need the containername
Upvotes: 4
Views: 11433
Reputation: 1158
Just set the Name at runtime like:
docker run --name MYCOOLCONTAINER alpine:latest
Then:
bashCommandName = `echo $NAME`
output = subprocess.check_output(['bash','-c', bashCommandName])
print output
Upvotes: 2