Skip to content

Processes launched via docker exec are not placed into the correct cgroup #42704

@raxod502

Description

@raxod502

Description

Processes launched via docker exec are not placed into the correct cgroup when using --cgroup-parent option on docker run with systemd cgroup driver.

Steps to reproduce the issue:

Create /etc/systemd/system/my-example-cgroup.slice with contents:

[Unit]
Description=My example cgroup
Before=slices.target

[Slice]
TasksAccounting=true
TasksMax=10

Edit /etc/docker/daemon.json as follows:

{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "cgroup-parent": "my-example-cgroup.slice"
}

Reload systemd and Docker configuration, sudo systemctl daemon-reload and sudo systemctl restart docker.

Now start a container and run something within it, e.g.:

$ sudo docker run -it --rm alpine
/ # tail -f /dev/null this-will-show-in-ps
tail: can't open 'this-will-show-in-ps': No such file or directory
<command hangs>

From another terminal, we can verify the cgroup is set correctly:

$ pgrep -f this-will-show-in-ps
23770
$ systemctl status 23770 | grep CGroup
Warning: The unit file, source configuration file or drop-ins of docker-f903f3cc12f1d6c801d64c8ae04638faeb899c438d6f5d65f3352810d0181007.scope changed on disk. Run 'systemctl daemon-reload' to reload units.
     CGroup: /my-example-cgroup.slice/docker-f903f3cc12f1d6c801d64c8ae04638faeb899c438d6f5d65f3352810d0181007.scope

However, now let's use docker exec:

$ sudo docker ps | grep alpine | awk '{ print $1 }'
f903f3cc12f1
$ sudo docker exec -it f903f3cc12f1 sh
/ # tail -f /dev/null this-will-also-show-in-ps
tail: can't open 'this-will-also-show-in-ps': No such file or directory
<command hangs>

From another terminal, we can see the cgroup is not set correctly (should be the same as the previous process):

$ pgrep -f this-will-also-show-in-ps
24418
$ systemctl status 24418 | grep CGroup
     CGroup: /system.slice/containerd.service

Consequently, cgroup resource limits are not enforced for any processes launched via docker exec.

Describe the results you received:
cgroup of processes started via docker run are placed into the container --cgroup-parent, but processes started via docker exec are placed into the default /system.slice/containerd.service cgroup.

Describe the results you expected:
cgroup of all processes in the container, no matter how they are started, are placed into the container --cgroup-parent.

Output of docker version:

Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        f0df350
 Built:             Wed Jun  2 12:00:45 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:58:56 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker info:

Client:                                                                                        
 Context:    default              
 Debug Mode: false
 Plugins:                             
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc., v0.8.0)
                                               
Server:                     
 Containers: 5
  Running: 5             
  Paused: 0
  Stopped: 0
 Images: 226
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e25210fe30a0a703442421b0f60afac609f950a3
 runc version: v1.0.1-0-g4144b63
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.11.0-1014-aws
 Operating System: Ubuntu 21.04
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.895GiB
 Name: ip-172-31-8-109
 ID: P7WI:4PFY:EWY7:Z3SG:JZGL:KHEE:UC6J:KEB4:SOPD:5MX2:ZARW:HSK6
 Docker Root Dir: /mnt/riju/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.): This is on an EC2 instance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions