前言:由於最近在學Docker,經過菜鳥教程的文檔,在學到Docker安裝Nginx時,掛載目錄運行容器時碰到了錯誤,一直跑不起來,浪費了不少時間,這裏記錄中途的解決方法html
菜鳥教程
這是菜鳥教程的運行代碼:linux
$ docker run -d -p 8082:80 --name runoob-nginx-test-web -v ~/nginx/www:/usr/share/nginx/html -v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/nginx/logs:/var/log/nginx nginxnginx
按照菜鳥教程的命令運行代碼,由於教程上的是Linux的目錄命令,而後我本身腦抽的把命令腦補成Windows的目錄:web
docker run -d -p 8082:80 --name runoob-nginx-test-web -v E:/nginx/www:/usr/share/nginx/html -v E:/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v E:/nginx/logs:/var/log/nginx nginxdocker
而後就報錯:翻譯
docker: Error response from daemon: open \.\pipe\docker_d4w_systray: The syThe system cannot find the file specifiedhtm
通過 有道翻譯,系統找不到文件,以爲有多是路徑問題,因而網上搜索Docker在Windows上掛載路徑的問題,發現確實有很多坑。教程
網上搜瞭解決辦法,發現要用下面這種方法來書寫:ip
docker run -d -p 8082:80 --name runoob-nginx-test-web -v //E/nginx/www:/usr/share/nginx/html -v //E/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v //E/nginx/logs:/var/log/nginx nginxci
這一次,卻是沒有上面的那個錯誤了,但是卻又出現了新的問題,容器卻是執行了,但是卻沒跑起來,而且有錯誤提示:
OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:424: container init caused \"rootfs_linux.go:58: mounting \\\"/E/PHPSpace/docker/nginx/conf/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/69414be2b2572a590e7ee33cc8765f431e8a354100090e802d78888a85834862/merged\\\" at \\\"/var/lib/docker/overlay2/69414be2b2572a590e7ee33cc8765f431e8a354100090e802d78888a85834862/merged/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
而後抱着僥倖心理,我打開了灰色圖標Docker,點擊Settings,進入設置頁面的Shared Drivers裏面,勾選了E盤,這裏保存須要登陸Windows系統的用戶名,而後發現尼瑪我竟然沒有設置密碼,而後又跑去設置密碼,過程:
一切OK後,我又運行了一次命令:
docker run -d -p 8082:80 --name runoob-nginx-test-web -v //E/nginx/www:/usr/share/nginx/html -v //E/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v //E/nginx/logs:/var/log/nginx nginx
結果仍是同樣的錯誤,文件不能掛載到目錄或是目錄不能掛載到文件。
心中絕望之際,忽然看見Shared Drivers下面有句代碼提示,能夠用Windows的C:/xxx這種命令,而後我就改爲這種命令試了一下,竟然跑起來了:
docker run -d -p 8082:80 --name runoob-nginx-test-web -v E:/PHPSpace/docker/nginx/www:/usr/share/nginx/html -v E:/PHPSpace/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v E:/PHPSpace/docker/nginx/logs:/var/log/nginx nginx
這就是這一次的踩坑教訓,作個筆記,但願不要忘記吧