Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker compose fails to mount sub-directories of named volumes #47687

Closed
jocafi opened this issue Apr 6, 2024 · 2 comments · Fixed by #47711
Closed

docker compose fails to mount sub-directories of named volumes #47687

jocafi opened this issue Apr 6, 2024 · 2 comments · Fixed by #47711
Labels
kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage

Comments

@jocafi
Copy link

jocafi commented Apr 6, 2024

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.

  1. On the client 10.0.0.3 create and share the directory /var/web. Create also an empty sub directory /var/web/portainer_data there

  2. 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
  1. 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
  1. Run the service on the server manager (10.0.0.2) docker compose -f portainer.yml up -d

  2. 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_data is empty (WRONG = BUG)

  3. Remove the container on the manager and the wrong files created on the client

  4. 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
  1. Confirm on the client that the sub directory /var/web/portainer_data is NOT empty.

Expected behavior

After running the command docker compose -f portainer.yml up -d the following behavior is expected:

  1. Confirm in the client that all the portainer files are NOT created under /var/web
  2. Confirm also in the client that the sub directory /var/web/portainer_data is 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:        de40ad0

docker 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: false

Additional 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.

@jocafi jocafi added kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage labels Apr 6, 2024
@vvoland
Copy link
Contributor

vvoland commented Apr 8, 2024

Volume subpath mount is supported on compose >= v2.26.0.

Swarm doesn't support it yet.

@reynhartono
Copy link

Volume subpath mount is supported on compose >= v2.26.0.

Swarm doesn't support it yet.

Thanks! I also had this issue and fixed it by manually installing the newest docker compose from the release page (as v2.26.0 isn't available yet via the apt repository). Initially, I thought the feature was supported in compose v2.25.0 (since it already uses compose-go v2.0.0). Turns out there was an additional PR to enable the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Bugs are bugs. The cause may or may not be known at triage time so debugging may be needed. status/0-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants