Cannot call chown inside Docker container (Docker for Windows)

和自甴很熟 提交于 2019-12-07 05:26:28

问题


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.

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

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

回答1:


You have similar issues illustrating the same error message in mongo issues 68 or issue 74

The host machine volume directory cannot be under /Users (or ~). Try:

docker run --name mongo -p 27017:27017 -v /var/lib/boot2docker/my-mongodb-data/:/data/db -d mongo --storageEngine wiredTiger

The PR 470 adds:

WARNING: because MongoDB uses memory mapped files it is not possible to use it through vboxsf to your host (vbox bug).

VirtualBox shared folders are not supported by MongoDB (see docs.mongodb.org and related jira.mongodb.org bug).

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.



来源:https://stackoverflow.com/questions/40834349/cannot-call-chown-inside-docker-container-docker-for-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!