Docker Community Forums

Share and learn in the Docker community.

Can a container know it's own name

(Drewv) #1

I’m using Amazon to automatically create docker containers. Amazon adds it’s own name to the container so I don’t know the name before hand.

I would like my containers to include it’s own container name in things like logging and when it adds things to a database.

Is there a way for a container to know it’s own name?

(Drewv) #2

I used this to get the container ID.

docker_container_id = gethostname()

I’m going to use this for now but I’d rather have the container name. Any idea if this is possible?