我已经在this stackoverflow thread中尝试了该解决方案。如下所示,它对我不起作用。
这是我的docker-compose.yml
文件:
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
这是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.
我也尝试了type: none
和type: volume
而不是type: bind
,但是遇到了同样的错误。
该目录显然存在:
$ ls -al /usr/local/opt/mysql/
...
drwxr-xr-x 2 cameronhudson staff 64 Jun 10 10:32 mywebsite.com
...
答案 0 :(得分:0)
我的配置不起作用有两个原因。
首先, Docker不遵循符号链接,并且mysql
目录是符号链接:
$ ls -al /usr/local/opt | grep mysql
lrwxr-xr-x 1 cameronhudson admin 22 Jan 23 17:42 mysql -> ../Cellar/mysql/8.0.13
但是,即使在使用没有任何符号链接的路径/databases/mywebsite.com
之后,我仍然遇到同样的no such file or directory
错误。
我发现,如果我更改了docker-compose.yml
文件以将该目录作为无名卷安装,则会出现另一个更合理的错误:
version: "3.7"
services:
db:
image: mysql
volumes:
- /databases/mywebsite.com:/var/lib/mysql
新错误:
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.'
在我在Docker Desktop中添加此路径后,我能够使用原始配置up
来服务。它也可以与type: none
,type: volume
,type: bind
一起使用,或者将type
完全排除在外。