Skip to content

[NET]: oci onCreateRuntime error will leave behind broken iptables rules #4253

Closed

Description

@apostasie

Description

Start a container:

dmp@lima-main-2025-05-15:/Users/dmp/Projects/go/nerd/nerdctl$ nerdctl run -d --name nerdctl-diagnostics2 -p 9044:80 nginx
d1364e3fb6f5bbc1de316656c9d7df483959e0c3e7202008f212ebe6c5bcd8d2

Check iptables:

dmp@lima-main-2025-05-15:/Users/dmp/Projects/go/nerd/nerdctl$ while read -r line; do sudo nsenter --net=$line iptables-save; done < <(lsns -n -u -t net -o PATH) | grep " 9044 "
-A CNI-DN-4095fe68ef51b84d4d4bd -s 10.4.0.0/24 -p tcp -m tcp --dport 9044 -j CNI-HOSTPORT-SETMARK
-A CNI-DN-4095fe68ef51b84d4d4bd -s 127.0.0.1/32 -p tcp -m tcp --dport 9044 -j CNI-HOSTPORT-SETMARK
-A CNI-DN-4095fe68ef51b84d4d4bd -p tcp -m tcp --dport 9044 -j DNAT --to-destination 10.4.0.83:80
-A CNI-HOSTPORT-DNAT -p tcp -m comment --comment "dnat name: \"bridge\" id: \"default-d1364e3fb6f5bbc1de316656c9d7df483959e0c3e7202008f212ebe6c5bcd8d2\"" -m multiport --dports 9044 -j CNI-DN-4095fe68ef51b84d4d4bd

So far, all fine.

Start a new container, different name, same port binding:

dmp@lima-main-2025-05-15:/Users/dmp/Projects/go/nerd/nerdctl$ nerdctl run -d --name nerdctl-diagnostics3 -p 9044:80 nginx
FATA[0000] failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running createRuntime hook #0: exit status 1, stdout: , stderr: time="2025-05-15T15:11:33-07:00" level=fatal msg="failed to expose ports in rootless mode: conflict with ID 16"

Not happy about port conflict - expected.

Now check iptables again:

dmp@lima-main-2025-05-15:/Users/dmp/Projects/go/nerd/nerdctl$ while read -r line; do sudo nsenter --net=$line iptables-save; done < <(lsns -n -u -t net -o PATH) | grep " 9044 "
-A CNI-DN-4095fe68ef51b84d4d4bd -s 10.4.0.0/24 -p tcp -m tcp --dport 9044 -j CNI-HOSTPORT-SETMARK
-A CNI-DN-4095fe68ef51b84d4d4bd -s 127.0.0.1/32 -p tcp -m tcp --dport 9044 -j CNI-HOSTPORT-SETMARK
-A CNI-DN-4095fe68ef51b84d4d4bd -p tcp -m tcp --dport 9044 -j DNAT --to-destination 10.4.0.83:80
-A CNI-DN-89454d63e9c74ec13be4f -s 10.4.0.0/24 -p tcp -m tcp --dport 9044 -j CNI-HOSTPORT-SETMARK
-A CNI-DN-89454d63e9c74ec13be4f -s 127.0.0.1/32 -p tcp -m tcp --dport 9044 -j CNI-HOSTPORT-SETMARK
-A CNI-DN-89454d63e9c74ec13be4f -p tcp -m tcp --dport 9044 -j DNAT --to-destination 10.4.0.84:80
-A CNI-HOSTPORT-DNAT -p tcp -m comment --comment "dnat name: \"bridge\" id: \"default-d1364e3fb6f5bbc1de316656c9d7df483959e0c3e7202008f212ebe6c5bcd8d2\"" -m multiport --dports 9044 -j CNI-DN-4095fe68ef51b84d4d4bd
-A CNI-HOSTPORT-DNAT -p tcp -m comment --comment "dnat name: \"bridge\" id: \"default-82214d1802aee04278e8410ac445e17610877d63eca40a5c2d25dace25b07271\"" -m multiport --dports 9044 -j CNI-DN-89454d63e9c74ec13be4f

Steps to reproduce the issue

^

Describe the results you received and expected

Left over iptables rules after failed container creation, possibly resulting in broken networking.

This is possibly the reason for #4246 and maybe other of our port binding issues.

What version of nerdctl are you using?

main

Are you using a variant of nerdctl? (e.g., Rancher Desktop)

None

Host information

No response

Activity

  1. changed the title [-][Network]: Failed container creation will f-up iptables rules[/-] [+][NET]: Failed container creation will f-up iptables rules[/+] on May 15, 2025
  2. added
    bug
    and removed
    kind/unconfirmed-bug-claim
    on May 16, 2025
  3. changed the title [-][NET]: Failed container creation will f-up iptables rules[/-] [+][NET]: oci onCreateRuntime error will leave behind broken iptables rules[/+] on May 17, 2025
  4. apostasie commented on Jun 6, 2025

    @apostasie
    ContributorAuthor

    Presumably fixed by #4255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/networkbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions