使用docker挂载卷后如何避免使用uid / gid 1000拒绝权限?

时间:2016-12-26 10:14:55

标签: mongodb docker

我正在使用Fedora开发Docker版本1.12.5。

我尝试使用以下命令创建Mongodb容器:

sudo docker run -v $PWD/db:/data/db -p 27017:27017 --name db -it username/mongo /bin/bash

这是我启动mongodb后的响应:

# mongod
root@32c9349a75b8:/# mongod
2016-12-26T09:59:08.643+0000 I CONTROL  [initandlisten] MongoDB starting : pid=10 port=27017 dbpath=/data/db 64-bit host=32c9349a75b8
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten] db version v3.4.1
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten] modules: none
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten] build environment:
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten]     distarch: x86_64
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2016-12-26T09:59:08.644+0000 I CONTROL  [initandlisten] options: {}
2016-12-26T09:59:08.646+0000 I STORAGE  [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2016-12-26T09:59:08.646+0000 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2016-12-26T09:59:08.646+0000 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2016-12-26T09:59:08.646+0000 I CONTROL  [initandlisten] now exiting
2016-12-26T09:59:08.646+0000 I CONTROL  [initandlisten] shutting down with code:100

我检查了/ data / db:

的文件权限
root@32c9349a75b8:/data# ls -al 
total 4
drwxr-xr-x.  3 root root   16 Dec 26 03:15 .
drwxr-xr-x. 23 root root  266 Dec 26 09:59 ..
drwxrwxr-x.  2 1000 1000 4096 Dec 25 16:24 db

如果我只是使用mkdir创建目录而不用卷装入它,那么' / db'的所有者和组。将是root,我不知道为什么uid和gid只有在我尝试-v with docker run命令之后才是1000。我该如何解决?

1 个答案:

答案 0 :(得分:0)

卷装入的权限是您执行主机卷的目录Web(到主机上的目录)的权限。修复主机本身上此文件夹的权限可解决此问题。

最好使用命名卷而不是主机目录。 Docker将维护卷和初始内容,并且将从具有此类卷的映像中复制包含的权限。