千家信息网

Docker安装Nginx问题怎么解决

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,本篇内容主要讲解"Docker安装Nginx问题怎么解决",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Docker安装Nginx问题怎么解决"吧!问题:在
千家信息网最后更新 2026年11月02日Docker安装Nginx问题怎么解决

本篇内容主要讲解"Docker安装Nginx问题怎么解决",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Docker安装Nginx问题怎么解决"吧!

问题:


在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/conftouch /mydata/nginx/conf/nginx.confvim /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 {    include       mime.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 {        listen       80;        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/

到此,相信大家对"Docker安装Nginx问题怎么解决"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

文件 问题 错误 内容 文件夹 方法 学习 哒哒 实用 更深 中装 主机 兴趣 地方 官方 实用性 实际 操作简单 更多 朋友 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 嘟嘟瓜互联网科技 齐家互联网科技 狮子座互联网科技有限公司 中国最先进互联网科技公司 团飞科技与伯堂互联网服务平台 武汉健翔互联网络科技有限公司 荆州市昕露互联网络科技有限公司 智腾互联网科技有限公司 哈尔滨屹滨互联网科技有限公司 米聚互联网科技南京有限公司排面 保险科技服务互联网营销体系 伊宁互联网科技做什么的 众安科技工业互联网合作 小米互联网科技园入驻 信承诺互联网科技有限公司 数字互联网科技有限公司 广西泛欧互联网科技有限公司 盐城市攀科互联网科技有限公司 10位科技互联网大佬 伍佰万互联网科技是干嘛的 手磨咖啡 互联网科技公司税收优惠 互联网科技媒体 极限挑战互联网科技 融贸通互联网科技 狮子座互联网科技培训 重庆科技学院互联网 互联网巨头投资的硬核科技 衡水科技产业互联网平台 宁波允成互联网科技有限公司
0