使用shell脚本在Docker容器内部挂载NFS共享

我有一个在Windows主机上运行的Ubuntu容器。 我已经安装了所有的nfs客户端软件包。 我可以连接到我的容器并安装一个nfs共享。

这个想法是开始容器运行我的脚本有它挂载两个共享,然后运行gunicorn。

docker-compose.yml version: '2.1' services: web: # restart: always build: . expose: - "5000" - "80" ports: - "5000:80" #command: gunicorn -w 4 wsgi_mount:app -b 0.0.0.0:80 --timeout 500 privileged: true command: /bin/bash /app/entrypoint.sh entrypoint.sh ------------ mount --verbose -t nfs -o nolock -o nfsvers=3 server:/nfs/share /app/path_to_mount1 mount --verbose -t nfs -o nolock -o nfsvers=3 server:/nfs/share /app/path_to_mount2 gunicorn -w 4 wsgi_mount:app -b 0.0.0.0:80 --timeout 500 

产量

 does not existt point /app/path_to_mount1 does not existt point /app/path_to_mount2 [2017-10-04 16:29:57 +0000] [41] [INFO] Starting gunicorn 19.7.1 [2017-10-04 16:29:57 +0000] [41] [INFO] Listening at: http://0.0.0.0:80 (41) [2017-10-04 16:29:57 +0000] [41] [INFO] Using worker: sync [2017-10-04 16:29:57 +0000] [46] [INFO] Booting worker with pid: 46 [2017-10-04 16:29:57 +0000] [49] [INFO] Booting worker with pid: 49 [2017-10-04 16:29:57 +0000] [50] [INFO] Booting worker with pid: 50 [2017-10-04 16:29:57 +0000] [53] [INFO] Booting worker with pid: 53 

我发现真正令人沮丧的是,如果我只是让它运行gunicorn然后附加到容器,并复制过去从容器中的脚本行的每个安装点它的工作。

如果我运行容器内的脚本我得到相同的确切的错误

我知道权限是正确的,我现在的NFS安装正确,我可以手动使它在我的容器中工作,但如果尝试从容器内的运行完全相同的命令我得到的bash脚本“不存在点。 ..“顺便说一句,不是一个错字,它显示在控制台的方式。

编辑:接受的答案完美工作,但我只是想在这里添加,如果path存在已经在容器中,那么它将无法安装。 如果你在docker-compose文件中定义了mount,那么还需要添加更改yml文件,如果它不好,你必须首先读取卷。

您可以使用docker deamon挂载nfs vumes。 这样你就不需要在你的容器中支持nfs了。 我不能看到为什么要装在容器内的原因

$ docker volume create –driver local \ –opt type = nfs \ –opt o = addr = 192.168.1.1,rw \ –opt device =:/ path / to / dir \ foo