Osama Sarwar
Osama Sarwar

Reputation: 43

Getting Docker ID in Flask Application

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

Answers (1)

Rich
Rich

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

Related Questions