运行命令:
docker run \
-p 9002:80 \
--name nginx \
-v /home/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/docker/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/docker/nginx/log:/var/log/nginx \
-v /home/docker/nginx/html:/usr/share/nginx/html \
--privileged=true -d nginx:latest
报错如下:
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/docker/nginx/conf/nginx.conf" to rootfs at "/etc/nginx/nginx.conf": mount /home/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf (via /proc/self/fd/6), flags: 0x5000: 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 不能挂载不存在的文件, 因为本地还没有 nginx.conf 文件. 所以只能先建立这些问题.
1 , 自己手写一份配置文件.
2 , 先运行一份 nginx 作为测试, 将里面的配置文件复制出来.
建议使用第二种方式
docker run --name nginx -d nginx
docker cp nginx:/etc/nginx/nginx.conf /data/
复制完成之后, 记得删除 nginx
docker stop nginx
docker rm nginx
微信扫描下方的二维码阅读本文