Skip to content
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

Mounting cgroups in a container #66

Closed
mrunalp opened this issue Jul 9, 2015 · 21 comments
Closed

Mounting cgroups in a container #66

mrunalp opened this issue Jul 9, 2015 · 21 comments

Comments

@mrunalp
Copy link
Contributor

mrunalp commented Jul 9, 2015

This issue has been created to continue the discussion in #65

@mrunalp
Copy link
Contributor Author

mrunalp commented Jul 10, 2015

The main feature that we are asking for is introspection so that the container process can see its own cgroups. The could be mounted RO, so the container can't modify its own cgroups. The main contention here is where should these be mounted and if we can come up with a standard location then there could be some tooling that could benefit from it.

@philips @crosbymichael

@philips
Copy link
Contributor

philips commented Jul 15, 2015

Are there applications today that expect to have a sub-tree cgroup mount? If not I would suggest that we make the container cgroup path easily discoverable via an environment variable.

The basic process would be to mount the entire heirarchy as RO and then via an environment variable like, CGROUP_SUBTREE=/foo, the user can find their container location by appending /sys/fs/cgroup to that subtree path.

If in the future we are able to fix-up the Kernel we could then make CGROUP_SUBTREE=/ and always mount a subtree to /sys/fs/cgroup and no code changes would be required.

Thoughts?

@alban
Copy link
Contributor

alban commented Jul 15, 2015

I think the canonical way to know the container cgroup path should be to parse /proc/1/cgroup (pid 1 refers to the pid leader in the container). For example,

cat /proc/1/cgroup | grep ^1: | sed 's/^[^:]*:[^:]*://'

On the host, this returns /. In containers, this would return a longer path such as /system.slice/docker-ca590ce841b7a8f66b41a85fc170540ce9d219dbd03b1086528945117d276612.scope.

Applications should expect to find /sys/fs/cgroup/$CONTROLLER/$CGROUP_SUBTREE where $CONTROLLER is for example systemd.

If in the future the kernel implements cgroup namespacing, then /proc/1/cgroup would show the path / in the container.

@mrunalp
Copy link
Contributor Author

mrunalp commented Jul 15, 2015

The downside of mounting the entire cgroups hierarchy is that the container can read the limits of all the other containers.

I agree that it will be great if we see / when the kernel namespacing is implemented. However, what we are proposing is an approximation of that as the container can only see its own cgroups and not of other containers/processes on the host.

@philips
Copy link
Contributor

philips commented Jul 16, 2015

I understand the downside and fully sympathize with the "annoyingness" of being able to read the limits of other cgroups. But, I would rather wait for the Kernel to correctly virtualize/namespace this and then enable the Kernel namespacing instead of working around the lack of namespaces and making things internally inconsistent.

@iaguis
Copy link

iaguis commented Jul 16, 2015

I understand the downside and fully sympathize with the "annoyingness" of being able to read the limits of other cgroups. But, I would rather wait for the Kernel to correctly virtualize/namespace this and then enable the Kernel namespacing instead of working around the lack of namespaces and making things internally inconsistent.

👍

@mrunalp
Copy link
Contributor Author

mrunalp commented Jul 16, 2015

@philips I agree.

@vmarmol
Copy link

vmarmol commented Jul 22, 2015

/cc @vmarmol

@vishh
Copy link
Contributor

vishh commented Jul 22, 2015

Mounting cgroups would impact checkpoint - restore functionality. FYI.

@LK4D4
Copy link
Contributor

LK4D4 commented Jul 22, 2015

@vishh Yeah, we mounting subtree in runc. And I believe @avagin handled that stuff.

@philips
Copy link
Contributor

philips commented Jul 28, 2015

So, I am going to put up a PR that will spec out mounting the system cgroup as a read-only bind-mount and the 'sub-cgroup' of the container optionally as a read-write bind-mount.

This should be backwards compatible once the cgroup namespace is merged and requires no "magic". @vmarmol Can you ping Aditya about: https://lkml.org/lkml/2014/10/19/4

@vmarmol
Copy link

vmarmol commented Jul 29, 2015

I pinged Aditya and he mentioned he has mostly not had time to continue the patch set and he wasn't getting any pressure to get it in. The only negative feedback he received on the patch set was that it only worked on unified hierarchy. He says he can make it work with the split hierarchy, but that it'd be more work overall.

@LK4D4
Copy link
Contributor

LK4D4 commented Jul 29, 2015

Here we have sorta implementation detail. For example in runc you can specify Type for Mount as cgroup and then cgroups will be mounted inside container. So, theoretically mounts isn't very well standardized :)

@philips
Copy link
Contributor

philips commented Aug 6, 2015

@vmarmol If we can push for just unified that would work for me.

@vmarmol
Copy link

vmarmol commented Aug 7, 2015

That was a primary complaint from reviewers, maybe the can be convinced
otherwise
On Aug 6, 2015 1:03 PM, "Brandon Philips" notifications@github.com wrote:

@vmarmol https://github.com/vmarmol If we can push for just unified
that would work for me.


Reply to this email directly or view it on GitHub
#66 (comment)
.

@mrunalp
Copy link
Contributor Author

mrunalp commented Nov 17, 2015

cgroups namespaces patch has been revived http://lists.linuxfoundation.org/pipermail/containers/2015-November/036378.html :)

@vishh
Copy link
Contributor

vishh commented Nov 17, 2015

I chatted briefly with Aditya about this patch. This should get merged
(hopefully) soon :)

On Mon, Nov 16, 2015 at 4:29 PM, Mrunal Patel notifications@github.com
wrote:

cgroups namespaces patch has been revived
http://lists.linuxfoundation.org/pipermail/containers/2015-November/036378.html
:)


Reply to this email directly or view it on GitHub
#66 (comment)
.

@vbatts
Copy link
Member

vbatts commented Nov 19, 2015

SUPER!

On Mon, Nov 16, 2015 at 11:04 PM, Vish Kannan notifications@github.com
wrote:

I chatted briefly with Aditya about this patch. This should get merged
(hopefully) soon :)

On Mon, Nov 16, 2015 at 4:29 PM, Mrunal Patel notifications@github.com
wrote:

cgroups namespaces patch has been revived

http://lists.linuxfoundation.org/pipermail/containers/2015-November/036378.html
:)


Reply to this email directly or view it on GitHub
<
https://github.com/opencontainers/specs/issues/66#issuecomment-157219568>
.


Reply to this email directly or view it on GitHub
#66 (comment)
.

@philips
Copy link
Contributor

philips commented Nov 25, 2015

OK, the patch is super exciting. Thanks for the update @mrunalp and @vishh.

This makes it easy to argue for mounting cgroup hierarchy read-only with the sub-cgroup as read-write (#66 (comment)). So, lets push forward on that.

@ashahab-altiscale
Copy link

Hmm, why is this part of the spec? Isn't this just a mount config as @LK4D4 says?

@hqhq
Copy link
Contributor

hqhq commented Dec 24, 2016

cgroup namespace support was added by: #397

I think we can close this.

@hqhq hqhq closed this as completed Dec 24, 2016
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 22, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Nov 23, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Dec 7, 2017
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

- Also added couple of APIs to return container type and name.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Feb 19, 2018
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
ashu-mehra pushed a commit to ashu-mehra/omr that referenced this issue Feb 20, 2018
Add support in port library for detecting if we are running in
docker container or not.
This is required for cgroup related APIs in port library,
such as omrsysinfo_cgroup_get_memlimit, to work properly.
This is because when running in a docker container,
the cgroups listed in /proc/self/cgroup do not match the cgroups
of the process in the container. /proc/self/cgroup actually
shows the cgroups as seen from the host.

Eg if a process is running in a docker container,
its /proc/PID/cgroup on docker will show something like:

$ cat /proc/8364/cgroup
11:cpuset:/docker/<container id>
10:perf_event:/docker/<container id>
9:memory:/dockera/<container id>
...

but the actual cgroup of the process would be "/".

Once we figure out that we are running in docker container,
then cgroup APIs in port library would use "/" as cgroup name
for reading resource limits.

Note that as and when docker containers start supporting
cgroup namespace, then above mentioned mismatch would also be fixed.
Following issues and PRs are related to adding support for
cgroup namespace in docker container:
opencontainers/runc#1184
opencontainers/runtime-spec#62
opencontainers/runtime-spec#66

There is no direct mechanism to detect if we are running in
docker container.
Most reliable mechanism that I have come across is
by checking the cgroup for PID 1 (by reading /proc/1/cgroup file)
for all subsystems. If all cgroups are "/", then it indicates the
process is running on host system.
Else we conclude it to be running in a docker container.
Note that this mechanism will break when docker containers start
supporting cgroup namespace.

Signed-off-by: Ashutosh Mehra <asmehra1@in.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants