Skip to content

SIGTERM sent to docker run command doesn't send a SIGTERM to the main process running inside the container anymore. #5241

Description

@shambhushrestha-bpi

Description

In Docker version 26.1.4, sending a SIGTERM to the docker run process would also send a SIGTERM to the main process inside the container. However, in version 27.0.3, this behavior has changed. Now, the process exits with the message context canceled without the main process receiving a SIGTERM.

Reproduce

  1. Save the following as $HOME/test/handle_sigterm.sh and make it executable.
#!/bin/sh
# Function to handle SIGTERM
handle_sigterm() {
echo "Received SIGTERM, exiting..."
exit 0
}
trap 'handle_sigterm' TERM
while true; do
echo "Waiting for sigterm"
sleep 10
done
  1. Run it as follows in a container
docker run -i \
-v $HOME/test:$HOME/test:ro \
alpine:latest \
$HOME/test/handle_sigterm.sh
  1. Now find the pid of this process as follows (in a separate terminal) and send a sigterm
ps -ef | grep 'handle_sigterm.sh' | grep 'docker run'
kill -15 <pid from above>
  1. You should see the following output
Waiting for sigterm
context canceled

Expected behavior

Up until version 26.x , the SIGTERM would be received by the main process and it would output the following:

Waiting for sigterm
Received SIGTERM, exiting...

docker version

Client: Docker Engine - Community
Version: 27.0.3
API version: 1.46
Go version: go1.21.11
Git commit: 7d4bcd8
Built: Sat Jun 29 00:02:33 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 27.0.3
API version: 1.46 (minimum version 1.24)
Go version: go1.21.11
Git commit: 662f78c
Built: Sat Jun 29 00:02:33 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.18
GitCommit: ae71819c4f5e67bb4d5ae76a6b735f29cc25774e
runc:
Version: 1.7.18
GitCommit: v1.1.13-0-g58aa920
docker-init:
Version: 0.19.0
GitCommit: de40ad0

docker info

Client: Docker Engine - Community
Version: 27.0.3
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.15.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.28.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 22
Running: 8
Paused: 0
Stopped: 14
Images: 9
Server Version: 27.0.3
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: ae71819c4f5e67bb4d5ae76a6b735f29cc25774e
runc version: v1.1.13-0-g58aa920
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.5.0-1022-aws
Operating System: Ubuntu 22.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.718GiB
Name: <removed>
ID: 2b79cfde-c13d-466d-bea6-96ef75d4d0d7
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

Additional Info

Tried in both Ubuntu 20 and Ubuntu 22 with Docker 26.1.4 and Docker 27.0.3.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions