docker持久化部署nginx时,挂载配置文件提示文件不存在

650次阅读
没有评论

运行命令:

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

微信扫描下方的二维码阅读本文

正文完
 0
柹子丶
版权声明:本站原创文章,由 柹子丶 于2023-11-01发表,共计978字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码