網(wǎng)站首頁 編程語言 正文
問題:
在
Docker
中裝Nginx
時(shí)遇到了如下錯(cuò)誤:
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
之后就出現(xiàn)了錯(cuò)誤。
錯(cuò)誤分析:
錯(cuò)誤中我看的懂的地方說:嘗試把目錄裝載到文件夾上,
/nginx/nginx.conf\" caused \“not a directory\”"
,噠噠噠…什么的,這里我看了主機(jī)上的文件路徑,發(fā)現(xiàn)本地創(chuàng)建的nginx.conf
是個(gè)文件夾nginx.conf/
,不是我想要的文件nginx.conf
。
正確的操作方法:
創(chuàng)建文件
mkdir -p /mydata/nginx/conf touch /mydata/nginx/conf/nginx.conf vim /mydata/nginx/conf/nginx.conf
在nginx.conf中寫入官方初始的內(nèi)容
#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; } } }
然后運(yùn)行
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
測(cè)試:
在本地
/mydata/nginx/html/
下放入一個(gè)index.html
,重啟:docker restart nginx
訪問http://localhost/
參考博客:
? https://www.cnblogs.com/ivictor/p/4834864.html(對(duì)目錄掛載的總結(jié))
? 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,可以看這篇博客)
原文鏈接:https://blog.csdn.net/liu_xin_xin/article/details/121973340
相關(guān)推薦
- 2023-07-25 適用SpringMVC實(shí)現(xiàn)圖片上傳功能
- 2022-03-20 ajax和fetch的區(qū)別點(diǎn)總結(jié)_AJAX相關(guān)
- 2022-06-02 C++的智能指針你真的了解嗎_C 語言
- 2022-09-27 Kotlin淺析延遲初始化與密封類的實(shí)現(xiàn)方法_Android
- 2023-03-16 python內(nèi)置函數(shù)anext的具體使用_python
- 2022-12-23 Kubernetes應(yīng)用服務(wù)質(zhì)量管理詳解_云其它
- 2022-05-08 Python與C語言分別完成排序流程_python
- 2022-10-29 C#?CLR學(xué)習(xí)?C++使用namespace實(shí)例詳解_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支