Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot call chown inside Docker container (Docker for Windows)

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
like image 970
James Avatar asked Nov 09 '22 05:11

James


1 Answers

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.

like image 75
VonC Avatar answered Nov 15 '22 06:11

VonC