Reputation: 43
I've created a simple Flask Application and running it in the Docker Container. I want to access that container's ID in my Flask App (python script). Is there any way to get the Container's ID?
Upvotes: 4
Views: 919
Reputation: 12663
The hostname in the docker container is a short hash of its id. In turn you can use this to get the hostname in Python/Flask:
import socket
docker_short_id = socket.gethostname()
Upvotes: 4