Docker安裝Nginx問題及錯(cuò)誤分析
問題:
在
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
測試:
在本地
/mydata/nginx/html/下放入一個(gè)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,可以看這篇博客)
到此這篇關(guān)于Docker安裝Nginx(含錯(cuò)誤分析)的文章就介紹到這了,更多相關(guān)Docker安裝Nginx內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Docker容器遷移之導(dǎo)入和導(dǎo)出容器方式
這篇文章主要介紹了Docker容器遷移之導(dǎo)入和導(dǎo)出容器方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
使用Docker部署Tomcat的實(shí)現(xiàn)示例
在本地編寫好了Spring項(xiàng)目,為了實(shí)現(xiàn)能夠隨時(shí)地訪問,所以需要將項(xiàng)目部署到服務(wù)器,本文主要介紹了使用Docker部署Tomcat的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-11-11
docker-compose安裝db2數(shù)據(jù)庫操作
這篇文章主要介紹了docker-compose安裝db2數(shù)據(jù)庫操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12
Docker網(wǎng)絡(luò)IP地址沖突的解決方法
本文主要介紹了Docker網(wǎng)絡(luò)IP地址沖突的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06
CentOS8上用Docker部署開源項(xiàng)目Tcloud的教程
這篇文章主要介紹了CentOS8上用Docker部署開源項(xiàng)目Tcloud,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-01-01
詳解Docker 容器基礎(chǔ)系統(tǒng)鏡像打包
這篇文章主要介紹了詳解Docker 容器基礎(chǔ)系統(tǒng)鏡像打包,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12
docker cmd 執(zhí)行多個(gè)帶參數(shù)命令
Docker提供了CMD指令來指定容器啟動后要執(zhí)行的命令,本文主要介紹了docker cmd 執(zhí)行多個(gè)帶參數(shù)命令,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-02-02

