Docker Community Forums

Share and learn in the Docker community.

Using "bind" volume mount inside of Docker Swarm with a docker-compose file


(Geoffw303) #1

My environment is using a 3 node Docker Swarm (all being managers) and I have a docker-compose.yaml that was created to deploy out to the Swarm. Inside my docker-compose.yaml I have two services being setup, one is a MySQL instance and the other is my custom Django App. What I am trying to do is twofold. One is that I need to mount a local directory (Example: /geofftest) into the container. This file does exist on the host/node/server and I am trying to mount it to a file that exists in the container (Example: /tmp). The second thing I am trying to do is create a persistent database folder so that our MySQL doesn’t get destroyed when the container exits.

My issue is that I am not able to get a local host file (something in this case /geofftest) to show inside the container. I have tried using both the long syntax and short syntax to create a “bind mount”.

Here is my docker-compose.yaml file:

version: '3.2'
services:
  project_mysql:
    environment:
      MYSQL_USER: 'project'
      MYSQL_PASSWORD: 'password1234'
    ports:
      - 3306:3306
    image: 'mysql/mysql-server'
    tty: true
    stdin_open: true
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: on-failure
      placement:
        constraints:
          - node.hostname == node1-dc1
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      interval: "5s"
      timeout: "1s"

  project_web:
    image: 'localhost:5123/project_web:0.1.5'
    tty: true
    stdin_open: true
    volumes:
      - type: bind
        source: /geofftest
        target: /tmp
    ports:
      - "8000:8000"
    depends_on:
      - project_mysql
    healthcheck:
      test: ["CMD-SHELL", "nc -z 127.0.0.1 8000 || exit 1"]
      interval: "5s"
      timeout: "1s"

networks:
  projectnet:
    driver: overlay
    ipam:
      config:
        - subnet: 10.2.0.0/24

Thanks for any assistance!