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: mysql functions

1. Built-in functions 1. Mathematical functions r...

5 VueUse libraries that can speed up development (summary)

Table of contents What utilities does VueUse have...

How to create a view on multiple tables in MySQL

In MySQL, create a view on two or more base table...

MySQL Series 10 MySQL Transaction Isolation to Implement Concurrency Control

Table of contents 1. Concurrent access control 2....

Detailed explanation of custom swiper component in JavaScript

Table of contents Effect display Component Settin...

Implementation of services in docker accessing host services

Table of contents 1. Scenario 2. Solution 3. Conc...

CSS3 speeds up and delays transitions

1. Use the speed control function to control the ...

Vue+spring boot realizes the verification code function

This article example shares the specific code of ...

Two ways to make IE6 display PNG-24 format images normally

Method 1: Please add the following code after <...

How to support full Unicode in MySQL/MariaDB

Table of contents Introduction to utf8mb4 UTF8 by...

Solve the problem that vue project cannot carry cookies when started locally

Solve the problem that the vue project can be pac...