`nerdctl kill -s <signal>` removes the network of a container that continues to run

Đang mở
#5,327 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@papidb đang làm issue này rồi.

Từ ngày 5/11/2026.

  • #5328 của @papidb — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
cli, networking

Hướng nghiên cứu

Start with pkg/cmd/container/kill.go and trace how Kill, cleanupNetwork, and killContainer handle signal and task status; compare the stop signal behavior with SIGKILL. Check the related issue #5323 for context, then run the container kill tests and reproduce the SIGHUP case with the steps in this report. Done means non-stopping signals preserve networking and health checks, while failed kills on stopped containers leave the network allocation intact.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Description

nerdctl kill removes the network of the container for every signal, not only for signals that stop the container. When the signal does not stop the container (for example SIGHUP to reload nginx), the container continues to run without its network setup:

  1. Published ports stop working.
  2. The IP address goes back to the IPAM pool. A new container can then get the same IP address while the first container still uses it.
Steps to reproduce the issue
sudo nerdctl run -d --name lab-hup -p 127.0.0.1:18080:80 --ip 10.4.0.240 nginx:alpine
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:18080   # 200

sudo nerdctl kill -s SIGHUP lab-hup
sudo nerdctl inspect lab-hup --format '{{.State.Status}}'          # running
curl -s -o /dev/null -w '%{http_code}\n' --max-time 3 http://127.0.0.1:18080   # 000
sudo ls /var/lib/cni/networks/bridge/10.4.0.240                    # No such file or directory

sudo nerdctl run -d --name lab-dup --ip 10.4.0.240 alpine sleep infinity   # succeeds
sudo nerdctl exec lab-hup ip -4 -o addr show eth0                  # 10.4.0.240/24
sudo nerdctl exec lab-dup ip -4 -o addr show eth0                  # 10.4.0.240/24
Describe the results you received and expected

Expected

A signal that does not stop the container does not change its network. The published port continues to work. The IP address stays allocated, so nerdctl run --ip 10.4.0.240 fails for a second container.

Received

After kill -s SIGHUP:

Check Result
Container status running
HTTP on the published port no response (000)
CNI lease file for 10.4.0.240 removed
Second container with --ip 10.4.0.240 starts, and both containers have 10.4.0.240
Cause

In pkg/cmd/container/kill.go, Kill calls cleanupNetwork before killContainer, for all signals. cleanupNetwork calls cni.Remove, which removes the port forwards and releases the IP address. The function does not check the signal or the task status.

The same order has a second effect. When the container is not running, cleanupNetwork runs first, and then killContainer fails with container is not running. The command fails, but the IP address is already released.

healthcheck.RemoveTransientHealthCheckFiles in killContainer also runs for every signal. So after kill -s SIGHUP, the container may continue to run without its health check. I did not test this part.

Possible fix
  1. Check the task status before cleanupNetwork. If the container is not running, return the error and do not change the network.
  2. Call cleanupNetwork only when the signal is SIGKILL or the stop signal of the container (SIGTERM by default).

With step 2, kill -s SIGTERM on a container that ignores SIGTERM still removes the network. That is the current behavior, and nerdctl stop has the same risk.

What version of nerdctl are you using?

main at dc841ac6. The result is the same with the fix for #5323 applied.

Host information
  • containerd v2.4.1, runc 1.5.2, rootful
  • Ubuntu 24.04, kernel 6.8, aarch64
  • Network: default bridge

Related: #5323. In that issue, nerdctl also releases the network at the wrong time. The fix for #5323 does not change this behavior.

Ngôn ngữ chính
Go
Star
10.5k
Fork
839
Merge trung bình
3 ngày 18 giờ
Pull request đã merge (30 ngày)
40

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của containerd/nerdctl

Tất cả issue của containerd/nerdctl

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.