Search code examples
docker-composedocker-swarm

How to configure volume path in docker-compose with docker swarm


I configure docker compose to create default volume but now i need to customize local path of volume, I try to do some driver_opts with binding and specifying path by device options but in that case swarm throw error in container 'Failed to mount ... directory does not exist'. So how I can configure local path of volume ?

This is my docker compose

version: '3'

services:
    xxx:
       image: image-xxx
       deploy:
           mode: replicated
           replicas: 2
       volumes:
         - xxxvolume:/usr/src/xxx/yyy/

volumes:
  xxxvolume:
    driver: 'local'

And the volume information is

[
    {
        "CreatedAt": "2019-11-24T19:05:03+01:00",
        "Driver": "local",
        "Labels": {
            "com.docker.stack.namespace": "XX"
        },
        "Mountpoint": "/var/lib/docker/volumes/xxx/_data",
        "Name": "XX_xxvolume",
        "Options": null,
        "Scope": "local"
    }
]


Solution

  • docker-compose.yml

    version: '3.7'
    
    services:
      jira:
        image: atlassian/jira-software
        volumes:
          - ./volumes/jira_vol:/var/atlassian/application-data/jira
        ports:
          - 8080:8080
    
    volumes:
      jira_vol:
        external: false
    

    And run this command;

    docker-compose up -d
    

    Finally volume directory added in same path!