網(wǎng)站首頁 編程語言 正文
問題:
在
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
之后就出現(xiàn)了錯誤。
錯誤分析:
錯誤中我看的懂的地方說:嘗試把目錄裝載到文件夾上,
/nginx/nginx.conf\" caused \“not a directory\”"
,噠噠噠…什么的,這里我看了主機上的文件路徑,發(fā)現(xiàn)本地創(chuàng)建的nginx.conf
是個文件夾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; } } }
然后運行
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/
參考博客:
? https://www.cnblogs.com/ivictor/p/4834864.html(對目錄掛載的總結(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)推薦
- 2022-11-07 深入了解Python中運算符函數(shù)的使用_python
- 2022-02-16 瀏覽器斷點如何使用(測試工具)
- 2022-03-17 C語言判斷數(shù)是否為素數(shù)與素數(shù)輸出_C 語言
- 2022-09-05 Hbase之查看RowKey所在Region
- 2022-05-26 Flutter實現(xiàn)抽屜動畫_Android
- 2022-03-03 解決composer提示版本太舊Warning from https://mirrors.aliyu
- 2022-11-11 C++泛型模板約束深入講解_C 語言
- 2022-04-21 Python數(shù)據(jù)類型中的元組Tuple_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支