[BUG] docker-compose service with bind propagation set to rshared and create_host_path set to true not working as expected #12466
Description
Description
I have a docker-compose file (test.yml
) with the following content:
# cat test.yml
---
services:
test_db:
image: postgres:15.10-bullseye
volumes:
- type: bind
source: /tmp/postgres
target: /var/lib/postgresql/data
bind:
create_host_path: true
propagation: rshared
which I am trying to start but errors out with:
# docker-compose -f test.yml up -d
[+] Running 0/0
⠋ Container bundle_install-test_db-1 Creating 0.0s
Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /tmp/postgres
As per this doc I am expecting that the source path will be created by docker stating:
create_host_path
: Creates a directory at the source path on host if there is nothing present. Compose does nothing if there is something present at the path. This is automatically implied by short syntax for backward compatibility with docker-compose legacy.
However, this does not seem to be the case and it seems that create_host_path
defaults to true
and works only with the basic access modes - rw
or ro
.
As this is nowhere to be explained in the official docs my supposition is it is a bug.
Steps To Reproduce
- Create a
test.yml
with contents such as (make sure that the bind propagation is set torshared
):
---
services:
test_db:
image: postgres:15.10-bullseye
volumes:
- type: bind
source: /tmp/postgres
target: /var/lib/postgresql/data
bind:
create_host_path: true
propagation: rshared
- Try to start the service with
docker-compose -f test.yml up
- You should see the same error I am hitting, i.e.:
Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /tmp/postgres
Compose Version
./docker-compose --version
Docker Compose version v2.32.2
Docker Environment
# docker info
Client:
Version: 24.0.5
Context: default
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 162
Server Version: 24.0.5
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
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 runc
Default Runtime: runc
Init Binary: docker-init
containerd version:
runc version:
init version:
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.2.0-1016-aws
Operating System: Ubuntu 22.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.32GiB
Name: devops-testing-master01
ID: 0c39d9d9-1baf-4fbf-96e3-35996d09750d
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Anything else?
With docker-compose
v1.29.2
this worked OK.
Here is a dummy example:
test.yml
contents
$ cat test.yml
---
services:
test_db:
image: alpine:3.21.2
volumes:
- /tmp/postgres:/var/lib/postgresql/data:rshared
command: >
sh -c "echo test > /var/lib/postgresql/data/testfile.txt
- which creates the
/tmp/postgres
dir
$ sudo ls /tmp/postgres
testfile.txt
- docker-compose's version
$ ./docker-compose --version
docker-compose version 1.29.2, build 5becea4c