Skip to content

Mounting a nonexistent host path, even as readonly, creates a directory on the host #13121

@rohansingh

Description

@rohansingh

This behavior seems to have been around for a while but is unexpected. Try mounting a nonexistent host path as a volume:

docker run -v /abc:/mnt busybox

The /abc directory will be created on the host:

docker@dev:/$ ls
abc/     dev/     home/    lib/     linuxrc  opt/     root/    sbin/    tmp      var/
bin/     etc/     init     lib64    mnt/     proc/    run/     sys/     usr/

This happens even if you attempted to mount the host path as readonly (-v /abc:/mnt:ro), which is even more unexpected. This behavior is particularly problematic when attempting to mount a file which may or may not exist — Docker creates a directory at the file path, which can cause problems down the road.

This behavior seems to be quite old (since at least 1.2.0), but doesn't seem to be documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementEnhancements are not bugs or new features but can improve usability or performance.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions