16

I'm trying to start a mysql container with a host directory mounted. I'm running a single-node swarm in Docker for AWS. But I can't mount a directory...

This is the section of the docker-compose file I'm using:

mysql:
    image: mysql-custom
    volumes:
        - /mysql:/var/lib/mysql
    ports:
        - "3307:3306"

And this is the launch command I'm trying:

docker stack deploy --compose-file docker-compose.yml stack12

When I launch however, docker swarm rejects the image, saying "invalid mount config for type \"bind\": bind source path does not exist". However, /mysql is a valid directory, I can cd to it and everything, so why is docker saying it does not exist?

7
  • Did you tried to remove the / at the beginning? Commented Jul 7, 2017 at 15:50
  • @FrankNoel I'm trying to mount a folder, not use a docker volume Commented Jul 7, 2017 at 15:53
  • 3
    Please edit the question to add: Docker version, host OS, how Docker was installed, and what commands are producing the error.
    – Andy Shinn
    Commented Jul 7, 2017 at 16:06
  • 3
    You're talking about swarm: is the folder available on any node of your cluster? Or are-you using affinity constraint?
    – zigarn
    Commented Jul 7, 2017 at 16:06
  • 2
    ERROR: for jenkinsdocker_master_1 Cannot create container for service master: invalid mount config for type "bind": bind source path does not exist ... How could someone possibly not display what path Compose expects to see is beyond me.
    – Christophe
    Commented Mar 2, 2018 at 10:33

4 Answers 4

0

According to what you are trying, mysql needs to be in root directory. You can try this

mysql:
    image: mysql-custom
    volumes:
        - ./mysql:/var/lib/mysql
    ports:
        - "3307:3306"

Notice the . before mysql. And directory structure for this can be:

.
|__docker-compose.yml
|__mysql
   |__(Your content)
   |__(some more files)
2
  • 1
    Nope, adding the "." did not change anything. Commented Jul 10, 2017 at 14:02
  • Can you provide the directory structure! I still have doubts regarding the exact location of mysql directory which this compose file is trying to mount
    – Ayushya
    Commented Jul 10, 2017 at 17:36
0

I experienced the same issue due to permissions. I recommend you make a test where you grant 777 to /mysql to see if it works -> then tweak the permissions to match your security requirements

0

when using host docker volumes you need check directory permissions and if its root you must exec to container and fix the issue using chown command in other hand you can use below config that work fine for me

services:
  mysql:
    image: mysql-custom
    volumes:
      - mysql:/var/lib/mysql
    ports:
      - "3307:3306"
volumes:
  mysql:
    driver: local
1
  • The question is about mounting a folder, not a docker volume. Commented Jan 19 at 14:36
0

I'm assuming /mysql/ is a directory that exists at the root of your local machine.

try changing your docker-compose file as follows:

volumes:
    - /mysql/:/var/lib/mysql

Notice the trailing / that tells docker you're referring to directory /mysql/ and not file /mysql that exists at the root of the disk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.