Skip to content

How to access the container's name inside the container? #3517

Answered by cyphar
Zhenshan-Jin asked this question in Q&A
Discussion options

You must be logged in to vote

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:

% runc run -b bundle ctr
# cat /proc/self/cgroup
0::/user.slice/user-1000.slice/ctr

(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.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@Zhenshan-Jin
Comment options

@cyphar
Comment options

@Zhenshan-Jin
Comment options

Answer selected by cyphar
Comment options

You must be logged in to vote
1 reply
@cyphar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3516 on June 20, 2022 02:30.