Detailed explanation of the processing of the three Docker Nginx Logs

Detailed explanation of the processing of the three Docker Nginx Logs

Because colleagues in the company need Nginx log standard output, that is, processing through the console, we need to write the log to the file first:

error_log /var/log/nginx/error.log

access_log /var/log/nginx/access.log

There are two ways to deal with it:

1. Create a host path and then mount it to the nginx log path in the container:

docker run --name docker_nginx -d -p 80:80\ 
 -v /var/log/nginx/log:/var/log/nginx\
--!-v: Mount the log directory

2. The second is to land in the log file and then direct to standard output:

RUN \

  ln -sf /dev/stdout /var/log/nginx/access.log && \    
  ln -sf /dev/stderr /var/log/nginx/error.log 

I heard the second one is better! ! !

This solves the log problem!

Supplementary knowledge: Custom docker nginx image without container log output

It just so happens that I need to customize an nginx image for my work environment. After generating it, I found that the container has no relevant nginx log output

FROM env_centos:latest
 
COPY nginx.repo /etc/yum.repos.d/ 
# Note that the log output must be redirected to stdout, otherwise the container log output cannot be seen RUN \
  yum -y install nginx httpd-tools && \
  mkdir -p /data/nginx_conf/upstream && \
  mkdir -p /data/nginx_conf/vhosts && \
  rm -f /etc/nginx/conf.d/default.conf && \
  ln -sf /dev/stdout /var/log/nginx/access.log && \ > These two lines are the key. Of course, this should match your nginx configuration file. Don't copy it. ln -sf /dev/stderr /var/log/nginx/error.log > These two lines are the key. COPY nginx.conf /etc/nginx/nginx.conf
 
EXPOSE 80
#EXPOSE 443
 
CMD ["nginx", "-g", "daemon off;"]

The final effect is as follows

#docker exec test123 ls -l /var/log/nginx/
lrwxrwxrwx 1 root root 11 Dec 29 10:51 access.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Dec 29 10:51 error.log -> /dev/stderr

The above detailed explanation of the processing of the three Docker Nginx Logs is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker Nginx container and Tomcat container to achieve load balancing and dynamic and static separation operations
  • Docker deploys nginx and mounts folders and file operations
  • Docker nginx implements one host to deploy multiple sites
  • Docker deployment nginx implementation process graphic and text detailed explanation
  • How to deploy Vue project using Docker image + nginx
  • Methods and steps to build nginx file server based on docker
  • How to build Nginx image server with Docker
  • Docker Nginx container production and deployment implementation method

<<:  Implementation of vue+drf+third-party sliding verification code access

>>:  Markup Language - Print Style Sheets

Recommend

Vue implements local storage add, delete and modify functions

This article example shares the specific code of ...

js to call the network camera and handle common errors

Recently, due to business reasons, I need to acce...

Instructions for using JSON operation functions in Mysql5.7

Preface JSON is a lightweight data exchange forma...

MySQL implements an example method of logging in without a password

Specific method: Step 1: Stop the mysql service /...

JavaScript ES new feature block scope

Table of contents 1. What is block scope? 2. Why ...

Vue project implements file download progress bar function

There are two common ways to download files in da...

Detailed explanation of the principle of js Proxy

Table of contents What is Proxy Mode? Introducing...

Implementation of Nginx configuration of multi-port and multi-domain name access

To deploy multiple sites on a server, you need to...

Several ways to center a box in Web development

1. Record several methods of centering the box: 1...

Webpack builds scaffolding to package TypeScript code

Create a folder Directory structure: dabaots Init...

Analysis of the problem of deploying vue project and configuring proxy in Nginx

1. Install and start nginx # Install nginx sudo a...