nerdctl
nerdctl copied to clipboard
`nerdctl stop` should release rootless ports (OCI `poststop` event should be called on `nerdctl stop`)
$ nerdctl --version
nerdctl version 0.12.1-58-g757f823
$ nerdctl run -d --name nginx -p 8080:80 nginx:alpine
5debf438f4632aaf6346d022b8a98c89c36b03e729f21f5e3f89b718a370f2da
$ nerdctl stop nginx
nginx
$ lsof -i -P
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rootlessk 131938 suda 12u IPv6 3543002 0t0 TCP *:8080 (LISTEN)
$ rootlessctl --socket /run/user/1001/containerd-rootless/api.sock list-ports
ID PROTO PARENTIP PARENTPORT CHILDIP CHILDPORT
7 tcp 0.0.0.0 8080 8080
The port should be released after nerdctl stop.
It looks like the OCI poststop event hook is not executed for nerdctl stop.
poststop event hook seems to be a post-delete hook.
A workaround for this issue when using nerdctl for development, if removing the container is okay in your usecase than using nerdctl run --rm will remove all traces of the container after running including the port.
It's against the definition of poststop.
IMHO, the runtime-spec is for k8s pod, and there is no stop action in k8s pod.