Getting Docker ID in Flask Application

Viewed 532

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?

1 Answers

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()
Related