Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-stack.yml invalid volume type bind

This is my docker-stack.yml file

    version: "3"

    services:
      mysql:
        image: mysql:latest
        deploy:
          replicas: 1
          update_config:
            parallelism: 1
          restart_policy:
            condition: on-failure
        ports:
          - "3306:3306"
        environment:
          MYSQL_ROOT_PASSWORD: <Censored>
          MYSQL_USER: <Censored>
          MYSQL_PASSWORD: <Censored>
        volumes:
          - ./db/data:/var/lib/mysql
          - ./db/logs:/var/log/mysql
          - ./db/config:/etc/mysql/conf.d
      php:
        image: wiput1999/php
        volumes:
          - ./web:/web
      nginx:
        image: nginx:latest
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - ./code:/code:ro
          - ./site.conf:/etc/nginx/conf.d/default.conf
          - /etc/letsencrypt:/etc/letsencrypt
          - ./nginx/log:/var/log/nginx

When I run this following stack I got mysql and nginx with this error "invalid mount config for type "bind": bind source path does not exist"

I have no idea what wrong with my code.

like image 748
wiput1999 Avatar asked Dec 03 '22 22:12

wiput1999


2 Answers

bind is a type of mount that is used to mount a directory (or a file) on the host into the container. All of your volumes are set up like that. So one of your source directories (or files) do not exists on the host. Check each of these:

  • ./db/data
  • ./db/logs
  • ./db/config
  • ./web
  • ./code
  • ./site.conf
  • /etc/letsencrypt
  • ./nginx/log

You could execute ls -ld ./db/data ./db/logs ./db/config ./web ./code ./site.conf /etc/letsencrypt ./nginx/log >/dev/null and look at the error message to find out which one.

like image 50
Janos Lenart Avatar answered Dec 31 '22 13:12

Janos Lenart


Please consider to use docker configs and docker secrets in place of volumes.

version: "3.3"

services:
  nginx:
    configs:
      - source: nginx_vhost
        target: /etc/nginx/conf.d/default.conf
    secrets:
      - ssl_private_key
...

configs:
  nginx_vhost:
    file: ./site.conf

secrets:
  ssl_private_key:
    file: /etc/letsencrypt/private.key

https://docs.docker.com/engine/swarm/configs/ and https://docs.docker.com/compose/compose-file/#configs

like image 31
Florian Wininger Avatar answered Dec 31 '22 11:12

Florian Wininger