4

I've already tried the solution in this stackoverflow thread. It did not work for me, as shown below.

Here's my docker-compose.yml file:

version: "3.7"
services:
  db:
    image: mysql
    volumes:
     - data:/var/lib/mysql

volumes:
  data:
    driver_opts:
      type: none
      device: /usr/local/opt/mysql/mywebsite.com
      o: bind  

Here's the result of docker-compose up:

$ docker-compose up
Creating volume "mycontainer_data" with default driver
Recreating 45bc03b2c674_mycontainer_db_1 ... error

ERROR: for 45bc03b2c674_mycontainer_db_1  Cannot create container for service db: error while mounting volume with options: type='none' device='/usr/local/opt/mysql/mywebsite.com' o='bind': no such file or directory

ERROR: for db  Cannot create container for service db: error while mounting volume with options: type='none' device='/usr/local/opt/mysql/mywebsite.com' o='bind': no such file or directory
ERROR: Encountered errors while bringing up the project.

Instead of type: none, I have also tried type: volume and type: bind, but I got the same error.

The directory clearly exists:

$ ls -al /usr/local/opt/mysql/
...
drwxr-xr-x   2 cameronhudson  staff      64 Jun 10 10:32 mywebsite.com
...

Cameron Hudson
  • 3,190
  • 1
  • 26
  • 38

1 Answers1

1

There were 2 reasons why my configuration wasn't working.

First, Docker does not follow symlinks, and the mysql directory is a symlink:

$ ls -al /usr/local/opt | grep mysql
lrwxr-xr-x    1 cameronhudson  admin    22 Jan 23 17:42 mysql -> ../Cellar/mysql/8.0.13

However, even after using a path without any symlinks, /databases/mywebsite.com, I continued the experience the same no such file or directory error.

I found that if I changed my docker-compose.yml file to mount this directory as a nameless volume, I got a different, more reasonable error:

version: "3.7"
services:
  db:
    image: mysql
    volumes:
     - /databases/mywebsite.com:/var/lib/mysql

The new error:

ERROR: for mycontainer_db_1  Cannot start service db: b'Mounts denied: \r\nThe path /databases/mywebsite.com\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.\r\n.'

After I added this path in Docker Desktop, I was able to up the services using my original configuration. It also worked with type: none, type: volume, type: bind, or leaving type out altogether.

Cameron Hudson
  • 3,190
  • 1
  • 26
  • 38
  • What do you mean "added this path in Docker Desktop"? – Slav Feb 06 '20 at 07:05
  • @Slav Docker Desktop is a package from Docker. Installing it installs the docker CLI and daemon. More info here: https://www.docker.com/products/docker-desktop – Cameron Hudson Feb 06 '20 at 23:35
  • Yes, I have Docker Desktop installed. It shows running containers, and allows to start/stop/delete/inspect them. Where in Docker Desktop can you "add a path" to a volume? – Slav Feb 07 '20 at 14:37
  • 1
    @Slav Docker Desktop -> Preferences -> Resources -> File Sharing – Cameron Hudson Feb 07 '20 at 18:05