Skip to content

container: allow an empty --cidfile path from mktemp - #7239

Open
locker95 wants to merge 2 commits into
docker:masterfrom
locker95:fix/cidfile-allow-empty-mktemp
Open

container: allow an empty --cidfile path from mktemp#7239
locker95 wants to merge 2 commits into
docker:masterfrom
locker95:fix/cidfile-allow-empty-mktemp

Conversation

@locker95

Copy link
Copy Markdown

--cidfile currently errors if the path already exists, even when the file is empty.

that's a pain with mktemp, which creates the file first:

t=$(mktemp)
docker run --rm --cidfile=$t debian

only refuse the path if it already has content (another container's id). empty files get reused.

Fixes#5954

newCIDFile currently errors if the path already exists, even when the
file is empty. mktemp creates that empty file first, so
`docker run --cidfile=$(mktemp)` always fails.
Keep refusing a path that already holds a container ID. Open/create
otherwise so an empty file can be reused.
Fixesdocker#5954
Signed-off-by: Dean Chen <862469039@qq.com>
Comment threadcli/command/container/create.go Outdated
return nil, errors.New("container ID file found, make sure the other container isn't running or delete " + cidPath)
// mktemp (and similar) create an empty file first. Only refuse the path
// when it already holds a container ID from another run.
f, err := os.OpenFile(cidPath, os.O_RDWR|os.O_CREATE, 0o644)

@hydrargyrumhydrargyrumAug 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pkg.go.dev/os#Create

If the file does not exist, it is created with mode 0o666 (before umask)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, os.Create uses 0o666 before umask — switched to that.

Match os.Create's mode so a newly created --cidfile still gets 0o666
before umask, instead of a hardcoded 0o644.
Signed-off-by: Dean Chen <862469039@qq.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--cidfile fails if file exists even if empty

2 participants

@locker95@hydrargyrum