栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > 服务器

Docker安装Nginx问题及错误分析

服务器 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力
问题:

在Docker中装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” 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 run -p 80:80 --name nginx -d --restart=always -v /mydata/nginx/html:/usr/share/nginx/html -v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /mydata/nginx/logs:/var/log/nginx nginx

之后就出现了错误。

错误分析:

错误中我看的懂的地方说:尝试把目录装载到文件夹上,/nginx/nginx.conf" caused “not a directory”",哒哒哒…什么的,这里我看了主机上的文件路径,发现本地创建的nginx.conf是个文件夹nginx.conf/,不是我想要的文件nginx.conf。

正确的操作方法:

创建文件

mkdir -p /mydata/nginx/conf
touch /mydata/nginx/conf/nginx.conf

vim /mydata/nginx/conf/nginx.conf

在nginx.conf中写入官方初始的内容

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    includemime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #    '$status $body_bytes_sent "$http_referer" '
    #    '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
 listen80;
 server_name  localhost;

 #charset koi8-r;

 #access_log  logs/host.access.log  main;

 location / {
     root   /usr/share/nginx/html;
     index  index.html index.htm;
 }

 #error_page  404/404.html;

 # redirect server error pages to the static page /50x.html
 #
 error_page   500 502 503 504  /50x.html;
 location = /50x.html {
     root   html;
 }
    }
}

然后运行

docker run 
	-p 80:80  
	--name nginx 
 	-d --restart=always 
 	-v /mydata/nginx/html:/usr/share/nginx/html 
 	-v /mydata/nginx/conf.d:/etc/nginx/conf.d 
 	-v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf 
 	-v /mydata/nginx/logs:/var/log/nginx 
 	nginx 
测试:

在本地/mydata/nginx/html/下放入一个index.html,

重启:docker restart nginx

访问http://localhost/


image-20211216132625114

参考博客:

​ https://www.cnblogs.com/ivictor/p/4834864.html(对目录挂载的总结)

​ https://blog.csdn.net/qierkang/article/details/92657302

​ https://my.oschina.net/u/3375733/blog/1591091(如果需要加/conf.d/*.conf,可以看这篇博客)

​ https://blog.csdn.net/weixin_44757670/article/details/104993869(如果需要加/conf.d/*.conf,可以看这篇博客)

到此这篇关于Docker安装Nginx(含错误分析)的文章就介绍到这了,更多相关Docker安装Nginx内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/697827.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号