-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Description
Description
A few days ago a new docker version (v26) released a new feature to allow mounting sub-directories of named volumes. volumes: Implement subpath mount was implemented.
It works when using the docker run command.
However, when using the long syntax on docker compose files, it seems to mount everything on the root path and not on the sub-directory specified in the volume options section. The subpath seems to be ignored
Reproduce
I have two servers (client = 10.0.0.3 and manager = 10.0.0.2) in the docker swarm.
-
On the client 10.0.0.3 create and share the directory
/var/web. Create also an empty sub directory/var/web/portainer_datathere -
Go to swarm manager (10.0.0.2) and create the shared named volume:
docker volume create --driver local \
--opt type=nfs \
--opt o=addr=10.0.0.3,rw \
--opt device=:/var/web \
vol-web
- Then create a compose file:
services:
portainer:
container_name: portainer
image: portainer/portainer-ce:latest
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- type: volume
source: vol-web
target: /data
# volume options
volume:
subpath: portainer_data
ports:
- "9443:9443"
- "8000:8000"
volumes:
vol-web:
external: true
-
Run the service on the server manager (10.0.0.2)
docker compose -f portainer.yml up -d -
Confirm in the client that all the portainer files are created under
/var/web(WRONG = BUG)
Confirm also in the client that the sub directory/var/web/portainer_datais empty (WRONG = BUG) -
Remove the container on the manager and the wrong files created on the client
-
Now, run the same command above using
docker run:
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock --mount source="vol-web",target=/data,volume-subpath=portainer_data portainer/portainer-ce:latest
- Confirm on the client that the sub directory
/var/web/portainer_datais NOT empty.
Expected behavior
After running the command docker compose -f portainer.yml up -d the following behavior is expected:
- Confirm in the client that all the portainer files are NOT created under
/var/web - Confirm also in the client that the sub directory
/var/web/portainer_datais NOT empty
docker version
Client: Docker Engine - Community
Version: 26.0.0
API version: 1.45
Go version: go1.21.8
Git commit: 2ae903e
Built: Wed Mar 20 15:17:48 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 26.0.0
API version: 1.45 (minimum version 1.24)
Go version: go1.21.8
Git commit: 8b79278
Built: Wed Mar 20 15:17:48 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.28
GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0docker info
Client: Docker Engine - Community
Version: 26.0.0
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.13.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.25.0
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 26.0.0
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 splunk syslog
Swarm: active
NodeID: ss6qmb47kypsuqw1e4l2x2ow1
Is Manager: false
Node Address: 10.0.0.3
Manager Addresses:
10.0.0.2:2377
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 5.15.0-101-generic
Operating System: Ubuntu 22.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.871GiB
Name: maxib-swarm-client-001
ID: bab05a66-00f8-4cc1-a15b-6e352186673a
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: falseAdditional Info
Just ignore the word "swarm" for test / reproduction purposes. The files above do not need a swarm to be tested (I think).
However, at the end I will use the solution for a swarm cluster and need to use compose files to deploy many services that point to different sub directories on the shared named volume.