Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of installing Nginx in Docker

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to solve the problem of installing Nginx in Docker". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to solve the problem of installing Nginx in Docker.

Question:

The following error was encountered when installing Nginx in Docker:

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.

I went directly after installing the mirror image.

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

And then there was a mistake.

Error analysis:

What I can understand in the error says: try to load the directory to a folder, / nginx/nginx.conf\ "caused\" not a directory\ ", da da … What, here I looked at the file path on the host and found that the locally created nginx.conf is a folder nginx.conf/, not the file nginx.conf I want.

The correct operation method:

Create a file

Mkdir-p / mydata/nginx/conftouch / mydata/nginx/conf/nginx.confvim / mydata/nginx/conf/nginx.conf

Write the official initial content in nginx.conf

# user nobody;worker_processes 1 the errorless 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;}}

Then run

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 Test:

Put an index.html under the local / mydata/nginx/html/

Restart: docker restart nginx

Visit http://localhost/

At this point, I believe you have a deeper understanding of "how to solve the problem of installing Nginx in Docker". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report