Skip to content

nerdctl is leaking host files when a container fails to start #2993

@apostasie

Description

@apostasie

Description

While investigating #2992, I noticed that AllocHostsFile is called before we verify that the requested --name for the container to be started is actually available.

If the name is not free, we bail out, but we leave the allocated host file in place.

Steps to reproduce the issue

# Just repeatedly run containers with the exact same name
sudo ./nerdctl-patch run -d --name whatevername debian bash
sudo ./nerdctl-patch run -d --name whatevername debian bash
sudo ./nerdctl-patch run -d --name whatevername debian bash

Describe the results you received and expected

Now, /var/lib/nerdctl/XXXX/etchosts/default will start filling up with orphaned files.

This is also true for /var/lib/nerdctl/1935db59/containers/default.

Looking at create.go shows why.

What version of nerdctl are you using?

1.7.6

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

None

Host information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions