1. 程式人生 > >Docker 安裝 出現 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 安裝 出現 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 映象時

docker run -p 80:80 --name mynginx -v $PWD/www:/www -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs -d nginx
1. -p 80:80  //把本機80埠 對映到 docker容器
2. --name mynginx //名稱為mynginx
3. -v $PWD/www:/www //把當前目錄下的www 資料夾 掛載到 docker的 www 目錄
4. -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf //把當前目錄下的conf/nginx.conf 掛載到 docker容器的/etc/nginx/nginx.conf檔案上
5. -d nginx 以守護程序方式載入映象 nginx

執行後報錯
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:364: container init caused \"rootfs_linux.go:54: mounting \\\"/usr/local/nginx/conf/nginx.conf\\\" to rootfs \\\"/var/lib/docker/overlay2/a17b89ade6183e400160108f8e2698007ef99e09843f6c34623e6402ba4ff3da/merged\\\
" at \\\"/var/lib/docker/overlay2/a17b89ade6183e400160108f8e2698007ef99e09843f6c34623e6402ba4ff3da/merged/etc/nginx/nginx.conf\\\" caused \\\"not a directory\\\"\"" : 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.

出現的原因是 $PWD/conf/nginx.conf 是一個目錄,而不是檔案

解決方法:刪除本機的conf/nginx.conf 目錄,然後新建一個nginx.conf 檔案就可以了。