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

Using JS timer to move elements

Use JS timer to make an element to make a method ...

Sublime / vscode quick implementation of generating HTML code

Table of contents Basic HTML structure Generate s...

Detailed explanation of scp and sftp commands under Linux

Table of contents Preface 1. scp usage 2. Use sft...

LINUX Checks whether the port is occupied

I have never been able to figure out whether the ...

How to adjust the log level of nginx in Docker

Table of contents Intro Nginx Dockerfile New conf...

canvas.toDataURL image/png error handling method recommendation

Problem background: There is a requirement to tak...

Django online deployment method of Apache

environment: 1. Windows Server 2016 Datacenter 64...

MySQL 5.7 JSON type usage details

JSON is a lightweight data exchange format that u...

An example of implementing a simple finger click animation with CSS3 Animation

This article mainly introduces an example of impl...

How to view files in Docker image

How to view files in a docker image 1. If it is a...

How to elegantly implement the mobile login and registration module in vue3

Table of contents Preface Input box component lay...

Solution to no Chinese input method in Ubuntu

There is no solution for Chinese input method und...

Tutorial on disabling and enabling triggers in MySQL [Recommended]

When using MYSQL, triggers are often used, but so...