我有一個在Windows主機上運行的Ubuntu容器。我安裝了所有的nfs客戶端軟件包。我可以連接到我的容器並掛載一個nfs共享。使用shell腳本在docker容器內部掛載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腳本執行它「不存在點...」。順便說一句,存在不是一個錯字,它顯示在控制檯中。
編輯: 接受的答案完美工作,但我只是想在這裏添加,如果路徑存在於容器中,那麼它將無法安裝。如果您在docker-compose文件中定義了mount,則還需要添加更改yml文件,如果它不好,您必須首先讀取該卷,否則不會重新創建該文件。
是o = addr = NFS服務器和設備的IP地址=容器內的掛載點?這些共享未安裝在主機上。 – Ominus
o = addr是服務器設備的IP地址=是要掛載的服務器nfs的路徑。顯示您的語法是用於創建一個命名卷,然後您可以使用docker run -v foo:container-path中的路徑裝載到一個容器中。它被安裝在/ var/lib/docker – herm
的某個地方,謝謝這是一個真正的生活保護程序! – Ominus