Solution to incorrect access log time when deploying Nginx in Docker
In the process of operating the website, I never took the logs too seriously. Although logging was turned on, I never analyzed the logs carefully. Today, when I looked at the logs on a whim, I found that the recorded time was 8 hours less than the server time. 8 hours, this is a special number. We know that the UTC time zone is the standard world time zone, and UTC+8 is 8 hours faster than the world time, and we happen to be in this time zone. My website is deployed using Docker+Nginx, so it is inferred here that the time zone used by Docker may be UTC. The time zone where our server is located is 8 hours faster than it. To verify our conjecture, use the following command to enter the docker container for viewing
$ docker exec -it nginx bash
After entering the container, execute date
the command and the following results are displayed:
Obviously, the time zone of the docker container is UTC. Knowing the problem, the next step is to correct the time zone of the docker container. There are basically three ways to do this online:
- localtime of shared hosting
- Copy the localtime of the host
- Creating a custom Dockerfile
I use the first method here, sharing the localtime of the host . I use it docker-compse
. So just add a line of file mapping in the configuration file
version: '3'
services:
web:
...
volumes:
...
- /etc/localtime:/etc/localtime
...
...
Then rebuild the web image and start the container
$ docker-compose up web
After that, the time of the logs recorded by nginx will be synchronized with the server.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
How to Install Nginx on Ubuntu 20.04?
Publish Date:2025/04/07 Views:157 Category:OPERATING SYSTEM
-
Nginx is one of the most popular web servers in the world, responsible for hosting some of the largest and most trafficked sites on the Internet. It is a lightweight application software that can be used as a web server or a reverse proxy.
How to use Let's Encrypt with Nginx to configure https in Ubuntu 20.04
Publish Date:2025/04/07 Views:123 Category:OPERATING SYSTEM
-
Let's Encrypt is a Certificate Authority (CA) that provides an easy way to obtain and install free TLS/SSL certificates, enabling encrypted HTTPS on your web server. It simplifies the process by providing a software client, Certbot, which a
Install WordPress with Nginx on Ubuntu 18.04
Publish Date:2025/04/07 Views:86 Category:OPERATING SYSTEM
-
WordPress is one of the most popular open source content management systems (CMS) with a market share of up to 60% compared to other CMS like Drupal or Joomla. WordPress can be used to develop any type of website, be it a blog, a small busi
Get the IP address of the Docker container from the host using docker inspect
Publish Date:2025/03/26 Views:103 Category:Docker
-
Docker containers are not just for isolation—they are often used to manage processes that still need to communicate directly with each other. However, to communicate, you usually need to know the IP address of each container, which you ca
Docker deploys nginx php application
Publish Date:2025/03/26 Views:131 Category:Docker
-
I'm learning docker recently. I'm learning by building an nginx+php development environment example. Here I record the build process. First, give a docker-compose.yml deployment configuration file version: '3' services: nginx: container_nam
How to use Docker to image a Node.js web application
Publish Date:2025/03/26 Views:107 Category:Docker
-
Docker is a containerization platform that simplifies the packaging and execution of applications. Containers run as independent processes with their own file systems, but share the kernel of their host machine. Docker has attracted much at
Start a Bash terminal in a new Docker container
Publish Date:2025/03/26 Views:97 Category:Docker
-
Docker containers are a standard unit for packaging all the dependencies of an application, allowing us to easily run them in any environment. Containers have become very popular recently, and most developers now rely heavily on containers
Passing environment variables to containers in Docker
Publish Date:2025/03/26 Views:125 Category:Docker
-
This article will introduce how to pass environment variables to containers in Docker. Passing environment variables to containers in Docker using the -e and tags -env We will first see how to create environment variables and pass them to t
Install Docker using Homebrew
Publish Date:2025/03/26 Views:202 Category:Docker
-
There is no doubt that Docker containers have revolutionized the way we develop and deploy applications. They provide developers with the ability to package applications and dependencies in an isolated environment. Recently, we've seen wide