Docker installation of Nginx problems and error analysis

Docker installation of Nginx problems and error analysis

question:


The following error occurred 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 installed the image and went directly to

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

Then something went wrong.

Error analysis:


The part of the error that I can understand says: trying to mount a directory to a folder, /nginx/nginx.conf\" caused \“not a directory\”" , da da da... something like that. Here I looked at the file path on the host and found that the locally created nginx.conf was a folder nginx.conf/ , not the file nginx.conf I wanted.

Correct operation method:


Create a file

mkdir -p /mydata/nginx/conf
touch /mydata/nginx/conf/nginx.conf

vim /mydata/nginx/conf/nginx.conf

Write the official initial content in nginx.conf

#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;
        }
    }
}

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 in the local /mydata/nginx/html/ ,

Restart: docker restart nginx

Visit http://localhost/

image-20211216132625114

Reference blog:

​ https://www.cnblogs.com/ivictor/p/4834864.html (Summary of directory mounting)

https://blog.csdn.net/qierkang/article/details/92657302

​ https://my.oschina.net/u/3375733/blog/1591091 (If you need to add /conf.d/*.conf, you can read this blog)

​ https://blog.csdn.net/weixin_44757670/article/details/104993869 (If you need to add /conf.d/*.conf, you can read this blog)

This is the end of this article about installing Nginx with Docker (including error analysis). For more information about installing Nginx with Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker installation of PHP and deployment example with Nginx
  • Docker installation Nginx tutorial implementation illustration
  • How to install Nginx in Docker
  • How to install and configure Docker nginx

<<:  Example of using CSS3 to achieve shiny font effect when unlocking an Apple phone

>>:  Advantages of INSERT INTO SET in MySQL

Recommend

MySQL time type selection

Table of contents DATETIME TIMESTAMP How to choos...

A brief introduction to JavaScript arrays

Table of contents Introduction to Arrays Array li...

Implementation example of nginx access control

About Nginx, a high-performance, lightweight web ...

Solution to 1449 and 1045 exceptions when connecting to MySQL

Solution to 1449 and 1045 exceptions when connect...

How to install Oracle on Windows Server 2016

1. Install Oracle There are too many Oracle insta...

Understanding JSON (JavaScript Object Notation) in one article

Table of contents JSON appears Json structure Jso...

vue uses Ele.me UI to imitate the filtering function of teambition

Table of contents Problem Description The general...

How to use html css to control div or table to be fixed in a specified position

CSS CodeCopy content to clipboard .bottomTable{ b...

Solution to the problem that VC6.0 cannot be used when installed on WIN10

VC6.0 is indeed too old VC6.0 is a development to...

Vue Element front-end application development: Use of API Store View in Vuex

Table of contents Overview 1. Separation of front...

Several ways to store images in MySQL database

Usually the pictures uploaded by users need to be...

How to write the introduction content of the About page of the website

All websites, whether official, e-commerce, socia...

Several reasons for not compressing HTML

The reason is simple: In HTML documents, multiple ...