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

React's reconciliation algorithm Diffing algorithm strategy detailed explanation

Table of contents Algorithmic Strategy Single-nod...

Web project development VUE mixing and inheritance principle

Table of contents Mixin Mixin Note (duplicate nam...

The normal method of MySQL deadlock check processing

Normally, when a deadlock occurs, the connection ...

Simple example of HTML text formatting (detailed explanation)

1. Text formatting: This example demonstrates how...

Vue implements setting multiple countdowns at the same time

This article example shares the specific code of ...

Vue implements picture verification code when logging in

This article example shares the specific code of ...

Let's talk in depth about the principle and implementation of new in JS

Table of contents definition Constructor bodies a...

Detailed explanation of MySQL master-slave inconsistency and solutions

1. MySQL master-slave asynchrony 1.1 Network Dela...

Best Practices for Sharing React Code

When any project develops to a certain complexity...

Vue+Openlayer uses modify to modify the complete code of the element

Vue+Openlayer uses modify to modify elements. The...

Analysis and solution of data loss during Vue component value transfer

Preface In the previous article Two data types in...

js dynamically adds example code for a list of circled numbers

1. Add the ul tag in the body first <!-- Unord...