其他分享
首页 > 其他分享> > debug记 docker: Error response from daemon: Mounts denied:

debug记 docker: Error response from daemon: Mounts denied:

作者:互联网

今天开始尚医通Mongodb的部分。老师一上来就给我们几个命令,让学生安装mongodb

#拉取镜像 
docker pull mongo:latest

#创建和启动容器 
docker run -d --restart=always -p 27017:27017 --name mymongo -v /data/db:/data/db -d mongo

#进入容器 
docker exec -it mymongo/bin/bash 

我在运行完第二个命令后终端给我报错:

docker: Error response from daemon: Mounts denied:
The path /data/db is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/desktop/mac for more info.

运行docker ps命令查看了一下容器,反馈如下:
image

经过查阅终端提供的文档,发现

Use File sharing to allow local directories on the Mac to be shared with Linux containers. This is especially useful for editing source code in an IDE on the host while running and testing the code in a container. By default the /Users, /Volume, /private, /tmp and /var/folders directory are shared. If your project is outside this directory then it must be added to the list. Otherwise you may get Mounts denied or cannot start service errors at runtime.>>>

也就是说-v 宿主机目录|容器内目录 中的宿主机目录必须使用/Users, /Volue, /private, /tmp和/var之一,如果想使用其他路径,则应当修改配置文件。至于具体如何修改,仍可参阅https://docs.docker.com/desktop/mac ,本文不再详细介绍。

后面我运行了以下两个命令:

docker rm mymongo

删除了刚才创建的命名为mymongo的容器.

然后我修改了宿主机目录,将原来的/data/db改为/Users,重新挂载数据卷创建容器。

docker run -d --restart=always -p 27017:27017 --name mymongo -v /Users:/data/db -d mongo

运行成功!

标签:容器,daemon,--,db,mymongo,denied,Mounts,docker,data
来源: https://www.cnblogs.com/gabiandlizzy/p/16178478.html