Skip to content

Mount API can't fully replace the legacy Bind API #42332

@ndeloof

Description

@ndeloof

Description
docker -v short notation for volume mounts uses the HostConfig.Bind field on ContainerCreate API, and can't be fully translated into --mount flags (Volumes in ContainerCreate API) because the latter does not offer option to create missing host path on bind mount.

The --mount flag exposes many advanced options that can be used to tweak the binding, which are not available with the short -v notation. This prevents user to benefit those advanced features with the same "create if missing" behaviour.

I suggest an additional option is introduce on mount, so that user can get best of both, and tools can adopt the mount API.

Steps to reproduce the issue:

  1. docker run --rm --mount type=bind,src=/does_not_exists,target=/foo,non_recursive=true hello-world
  2. docker run --rm -v /does_not_exists:/foo hello-world

Describe the results you received:

  1. fails with bind source path does not exist
  2. creates host path but volume is created without non_recursive flag set

Describe the results you expected:
I get an option to run 1. and get the source path created on host
or I get an option to run 2. and set the non_recursive flag

Additional information you deem important (e.g. issue happens only occasionally):

see discussion on docker-archive/compose-cli#1563 (comment) as initial reason I had to look into this :P

Output of docker version:

20.10.6

Additional environment details (AWS, VirtualBox, physical, etc.):

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/apiAPIarea/volumesVolumeskind/enhancementEnhancements are not bugs or new features but can improve usability or performance.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions