New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A more reliable way to get the container id. #1919
Conversation
627209d
to
98c28b4
Compare
what happens if the container is configured with cgroup options? does that affect this value also tests need to be fixed |
If I understand your question correctly, it doesn't matter if the container is created with or without setting any resource limits, the control group is created anyway. From my experience, this is the most reliable way to get the container id from inside the container itself. I'll see what needs to be fixed in the tests. Thanks for the quick reply. |
I meant more https://docs.docker.com/engine/reference/run/#specify-custom-cgroups -- does this not affect the contents of |
I did the following test:
So it seems that the container ID is still there as expected. I'll go over the failing tests in the weekend. |
c934b4e
to
94c4cd5
Compare
908e38a
to
1de2410
Compare
@asottile I think I addressed everything and tests are now passing. |
according to this SO post the method you're using is not consistent on all kernel versions: https://stackoverflow.com/q/20995351/812183 |
You're going to make this on me, are you? 😜
And here's the content in Ubuntu Xenial (Docker 18.09 and kernel version 4.4):
From these tests I see that the first line doesn't always have the container id, however the line that starts with |
57ed17d
to
ba7f9c8
Compare
b2efbcc
to
a8f7e12
Compare
a001d1d
to
3d80a30
Compare
1161890
to
247373a
Compare
@asottile I think it's ready now. |
The hostname is not always the container id. Get the container id from /proc/1/cgroup. Fixes pre-commit#1918.
247373a
to
3e10209
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hostname is not always the container id. Get the container id from
/proc/1/cgroup. Fixes #1918.