问题描述
我正在尝试使用官方Mongo dockerfile 要启动数据库,我正在使用-v
命令将本地目录映射到容器内的/data
.
I am attempting to use the official Mongo dockerfile to boot up a database, I am using the -v
command to map a local directory to /data
inside the container.
作为Dockerfile
的一部分,它尝试将该目录授予用户mongodb:
As part of the Dockerfile
, it attempts to chown this directory to the user mongodb:
RUN mkdir -p /data/db /data/configdb \
&& chown -R mongodb:mongodb /data/db /data/configdb
VOLUME /data/db /data/configdb
但是,此操作失败,并显示以下命令:
However, this fails with the following command:
chown: changing ownership of '/data/db': Permission denied
我在这里做错了什么?我在这附近找不到任何文档-肯定容器应该对映射目录具有完全权限,因为它是在docker run命令中明确传递的:
What I am doing wrong here? I cannot find any documentation around this - surely the container should have full permissions to the mapped directory, as it was explicitly passed in the docker run command:
docker run -d --name mongocontainer -v R:\mongodata:/data/db -p 3000:27017 mongo:latest
推荐答案
You have similar issues illustrating the same error message in mongo issues 68 or issue 74
docker run --name mongo -p 27017:27017 -v /var/lib/boot2docker/my-mongodb-data/:/data/db -d mongo --storageEngine wiredTiger
PR 470 添加:
MongoDB不支持VirtualBox共享文件夹(请参阅 docs.mongodb.org 和相关的 jira.mongodb. org 错误).
VirtualBox shared folders are not supported by MongoDB (see docs.mongodb.org and related jira.mongodb.org bug).
这意味着使用Docker Toolbox的默认设置无法运行将数据目录映射到主机的MongoDB容器.
This means that it is not possible with the default setup using Docker Toolbox to run a MongoDB container with the data directory mapped to the host.
这篇关于无法在Docker容器中调用chown(适用于Windows的Docker)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!