Using long syntax for bind mount does create inexistent folders
This issue is (pretty much) the opposite of #8533.
Description
The compose file reference documentation states that:
When creating bind mounts, using the long syntax requires the referenced folder to be created beforehand. Using the short syntax creates the folder on the fly if it doesn’t exist. See the bind mounts documentation for more information.
This is the behavior I actually want to happen (Docker should report a warning that the folder doesn't exist and stop, as using docker directly from the command line with the --mount flag does). However, it seems that even when using a bind mount with the long syntax, the referenced folder always gets created.
Steps to reproduce the issue:
- Create a
docker-compose.yamlfile with the following content:
version: '3'
services:
repro:
image: hello-world
volumes:
- type: bind
source: ./non-existent
target: /opt/non-existent
- Run it with
docker compose up. - Notice that the
non-existentfolder gets created locally, even though the documentation claims this should produce an error.
Output of docker compose version:
Docker Compose version v2.2.1
Output of docker info:
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.7.1)
compose: Docker Compose (Docker Inc., v2.2.1)
scan: Docker Scan (Docker Inc., v0.11.0)
Server:
Containers: 3
Running: 0
Paused: 0
Stopped: 3
Images: 6
Server Version: 20.10.11
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.10.60.1-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 12.4GiB
Name: docker-desktop
ID: 3HAM:ON7X:6FFG:7DXC:EV7A:HSYF:QAVL:76NM:ZEMA:EQFW:GYSJ:7GRI
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
Additional environment details:
Windows 10 Pro, version 21H2 with WSL2 back end.
I'm seeing the same behavior on Ubuntu 20.04 with docker-compose v 1.25.0
This distinct behavior between short and long syntax is a weird legacy decision.
It has been excluded from the Compose Specification as "implementation specific".
The actual reason for this is that docker engine has two distinct APIs to either define a bind or a mount, the later won't trigger source folder creation if non existent.
I'd be in favor of introducing an explicit flag in the compose specification for those who rely on this behavior, so that one can opt-in/out for source path to be created if missing, then implementation can select the adequate API to be used.
@ndeloof agreed, this solution would be satisfactory. I wasn't familiar with the Compose spec. I'm just looking for a way to explicitly say that I want a folder to not be created if missing :sweat_smile:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Just checked, the behavior is the same with the latest Docker for Windows version 4.10.1.
This issue has been automatically closed because it had not recent activity during the stale period.
I'd be in favor of introducing an explicit flag in the compose specification for those who rely on this behavior, so that one can opt-in/out for source path to be created if missing, then implementation can select the adequate API to be used.
@ndeloof Would it be possible to mark this issue then as an enhancement, so that it doesn't get closed as stale? Thank you!