docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused “process_linux.go:424: container init caused “rootfs_linux.go:58: mounting ”/docker/nginx/conf” to rootfs "/var/lib/docker/overlay2/126c244dc6ee7095b1501a503eb361bade4fc255601ec0b0fe96238b58178958/merged" at "/var/lib/docker/overlay2/126c244dc6ee7095b1501a503eb361bade4fc255601ec0b0fe96238b58178958/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:
docker run -d -p 80:80 --name nginx --net host -v /home/web/dist:/usr/share/nginx/html -v /home/nginx/logs:/var/log/nginx nginx
命令说明:
-p 8081:80: 将容器的 80 端口映射到主机的 8081 端口。
–name nginx :将容器命名为 nginx 。
–net host :启动模式 建议使用 否则做负载均衡会有问题!
-v /home/web/dist:/usr/share/nginx/html:将我们自己创建的 www 目录挂载到容器的 /usr/share/nginx/html。
-v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:将我们自己创建的 nginx.conf 挂载到容器的 /etc/nginx/nginx.conf。
-v /home/nginx/logs:/var/log/nginx:将我们自己创建的 logs 挂载到容器的 /var/log/nginx
报错了头大:docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused “process_linux.go:424: container init caused “rootfs_linux.go:58: mounting ”/docker/nginx/conf/nginx.conf” to rootfs "/var/lib/docker/overlay2/73ad6cfead8c2d9c1d25469cccff7d86029ce6308a83416b2ef08464c8c5f76f/merged" at "/var/lib/docker/overlay2/73ad6cfead8c2d9c1d25469cccff7d86029ce6308a83416b2ef08464c8c5f76f/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.
解决办法:
换一种方法不启动 -v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf 这个
启动之前先把刚刚已经启动的容器删除 docker rm -f nginx 然后记得删除掉/docker/nginx/conf/nginx.conf(注意这里帮你创建了个目录需要也删除 然后在执行下面命令其他不管)
docker run -d -p 80:80 --name nginx --net host -v /home/web/dist:/usr/share/nginx/html -v /home/nginx/logs:/var/log/nginx nginx
然后发现没错 正常启动
访问80端口:
访问可能会403 因为/home/web/dist 里面没有index.html放进去就好了



