Skip to content

daemon: re-mount image layer on restart to fix subpath access - #52734

Open
notandruu wants to merge 1 commit into
moby:masterfrom
notandruu:daemon/fix-image-mount-subpath-after-restart
Open

notandruu wants to merge 1 commit into
moby:masterfrom
notandruu:daemon/fix-image-mount-subpath-after-restart

Conversation

@notandruu

Copy link
Copy Markdown
Contributor

Description

Containers with type: image volumes and a subpath fail to start after a daemon restart:

cannot access path /var/lib/docker/overlay2/{id}/merged/usr: lstat ... no such file or directory

This only affects graphdriver (overlay2); the containerd snapshotter is not affected.

Root cause: prepareMountPoints restores the Layer reference via GetLayerByID but never re-mounts the layer. With graphdriver, the overlay2 merged/ directory is removed on daemon shutdown, leaving config.Source pointing to a stale path. When setupMounts calls safepath.Join(ctx, m.Source, subpath), evaluatePath calls filepath.EvalSymlinks(m.Source) and fails with ENOENT.

Fix: Call layer.Mount("") for stopped containers (alive=false) to re-mount the overlay and update config.Source with the live path. The alive guard avoids double-mounting live-restored running containers where the overlay is still active. The existing Unmount in removeMountPoints balances this Mount at deletion time.

Enables the regression test TestRunMountImageSubpathDaemonRestart (added in #51831) which was previously skipped for graphdriver.

Fixes: #50999

How to verify

make test-integration TESTFLAGS="-run TestRunMountImageSubpathDaemonRestart" TEST_FILTER=volume

Release notes (optional)

Fixed a bug where containers with `type=image` volume mounts and a `subpath` failed to start after a daemon restart when using graphdriver (overlay2).

A picture of a cute animal

🦦

Created with: Claude Code

@thaJeztah
thaJeztah requested a review from vvoland June 1, 2026 13:44
@thaJeztah thaJeztah closed this Jun 8, 2026
@thaJeztah thaJeztah reopened this Jun 8, 2026
On daemon restart, prepareMountPoints restores the Layer reference for
type=image mount points but does not re-mount the layer. With graphdriver
(overlay2), the merged/ directory is removed on daemon shutdown, leaving
config.Source pointing to a stale path. When setupMounts subsequently
calls safepath.Join with a subpath, evaluatePath calls
filepath.EvalSymlinks on config.Source and fails with ENOENT.

Fix by calling layer.Mount("") for stopped containers (alive=false) to
re-mount the overlay and update config.Source with the live path. The
alive guard avoids double-mounting live-restored running containers where
the overlay is still active. The existing Unmount in removeMountPoints
balances this Mount at container deletion time.

Enable the regression test TestRunMountImageSubpathDaemonRestart which
was previously skipped for graphdriver.

Fixes: moby#50999
Signed-off-by: Andrew Liu <[email protected]>
Signed-off-by: Andrew Liu <[email protected]>
@notandruu
notandruu force-pushed the daemon/fix-image-mount-subpath-after-restart branch from f8afa11 to 6a069c6 Compare June 15, 2026 19:36
@notandruu

Copy link
Copy Markdown
Contributor Author

Rebased on current master to refresh CI. I also noticed this branch had accidentally been based on top of my #52722 (it was carrying that PR's TestInspectAPIImageResponse migration as an extra commit); I've dropped it, so this PR is now just the image-mount fix: daemon/mounts.go plus un-skipping the existing TestRunMountImageSubpathDaemonRestart for the graphdriver path.

Recap of the fix: after a daemon restart, an image-mount source points at the overlay2 merged/ directory, which does not survive shutdown. safepath.Join (used for subpath mounts) then calls EvalSymlinks on the stale source and fails with ENOENT, so containers with image subpath mounts can't restart. prepareMountPoints now re-mounts the layer for non-alive containers to get a valid source path, balanced by the existing Unmount in removeMountPoints. The previously-skipped integration test now exercises exactly this on the graphdriver path.

Would appreciate a look when someone has a moment.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Container with volume type: image and subpath fails to start after dockerd restart

2 participants