How to access the container's name inside the container? #3517
-
I am wondering if it is possible to access the container's name inside the container? For example, I create a container with
is it possible to access MY_CONTAINER inside the container? The use case is that in each of the created container, I will create a unix socket so that the server in the container coud be called by the outside. Any help is appreciated : ) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
There is no guaranteed way of getting that information, since the container name is just used by runc for managing its containers. However (unless the container is configured with custom cgroup configuration) you can find the name of the container as the final component of the cgroup pathnames in
(On cgroupv1 systems there will be more cgroup entries.) Please note this is not guaranteed -- it is possible to specify a custom cgroup path which will hide this information. |
Beta Was this translation helpful? Give feedback.
-
How about passing it through an env variable in “config.json”? |
Beta Was this translation helpful? Give feedback.
There is no guaranteed way of getting that information, since the container name is just used by runc for managing its containers.
However (unless the container is configured with custom cgroup configuration) you can find the name of the container as the final component of the cgroup pathnames in
/proc/self/cgroup
inside the container:(On cgroupv1 systems there will be more cgroup entries.) Please note this is not guaranteed -- it is possible to specify a custom cgroup path which will hide this information.