Why docker logs are stored in the system using container ID? Why not using name of the container?

696 views Asked by At

I'm able to find my docker logs stored in the system here: var/lib/docker/containers/container id/container id-json.log

Why logs are stored by using container ID ? why not using container names like container name-json.log?

2

There are 2 answers

0
RafaelJan On

Because the container ID is unique.

If you run another container and give it the same name, the first container will still have its own unique ID, but the name will be now givven to the second container, while the first container will have no name now (this is called Dangling Container)

0
rezshar On

As mentioned, the containers ID is unique and Docker uses the ID to store the logs of each container. But it is possible to configure the docker engine with log options to include labels in the logs. Here is your answers.

If you do the settings mentioned in the link above correctly, for example, with the following command, you can see the logs of your desired container.

docker logs --details c20