您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Docker安裝Nginx問題怎么解決”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Docker安裝Nginx問題怎么解決”吧!
在
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ò)誤中我看的懂的地方說:嘗試把目錄裝載到文件夾上,
/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/
到此,相信大家對(duì)“Docker安裝Nginx問題怎么解決”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。