Muhammad Rehan Saeed
Muhammad Rehan Saeed

Reputation: 38437

Defining Shared Host Volumes using Docker Swarm

I am trying to use the following docker-stack.yml file to deploy my services to my Docker Swarm version 17.06-ce. I want to use volumes to map the C:/logs directory on my Windows host machine to the /var/log directory inside my container.

version: '3.3'

services:
  myapi:
    image: mydomain/myimage
    ports:
      - "5000:80"
    volumes:
      - "c:/logs:/var/log/bridge"

When I remove the volumes section, my containers start fine. After adding the volume, the container never even attempts to start i.e.

  1. docker container ps --all does not show my container.
  2. docker events does not show the container trying to start.

The following command works for me, so I know that my syntax is correct:

docker run -it -v "c:/logs:/var/log/bridge" alpine

I've read the volumes documentation a few times now. Is the syntax for my volume correct? Is this a supported scenario? Is this a Docker bug?

Upvotes: 2

Views: 3908

Answers (1)

Jinna Baalu
Jinna Baalu

Reputation: 7809

Docker run will work when you run it in version 2 and with docker-compose we can run the custom volume mounting.

In version three we have to use the named volumes with default volume path or custom path.

Here is the docker-compose with default volume

version: "3.3"

services:
  mysql:
    image: mysql
    volumes:
       - db-data:/var/lib/mysql/data
    networks:
       - overlay
    deploy:
      mode: replicated
      replicas: 2
      endpoint_mode: dnsrr

volumes:
  db-data:

volume is mounted to default /var/lib/docker/volumes/repo/_data

We have option to mount the custom path to the volume

version: "3.3"

services:
  mysql:
    image: mysql
    volumes:
       - db-data:/var/lib/mysql/data
    networks:
       - overlay
    deploy:
      mode: replicated
      replicas: 2
      endpoint_mode: dnsrr

volumes:
  db-data:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: /home/ubuntu/db-data/

VOLUMES FOR SERVICES, SWARMS, AND STACK FILES

Upvotes: 3

Related Questions