JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Docker >

Solution to incorrect access log time when deploying Nginx in Docker

Author:JIYIK Last Updated:2025/03/26 Views:

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 datethe command and the following results are displayed:

Docker container time zone

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:

  1. localtime of shared hosting
  2. Copy the localtime of the host
  3. 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.

Article URL:

Related Articles

Running a Docker instance from a Dockerfile

Publish Date:2025/03/26 Views:139 Category:Docker

Docker containers have undoubtedly become the standard unit for managing software and dependencies in different environments. When using real applications, you must create a docker file before building the container image of the application

Copy files from host to Docker container

Publish Date:2025/03/25 Views:127 Category:Docker

This article will discuss and demonstrate methods we can use to transfer files from the host to a running container in Docker. docker cp Copy the file from the host to the Docker container using docker cp The command is one of the simplest

Get the IP address of the Docker container

Publish Date:2025/03/25 Views:102 Category:Docker

This article demonstrates how to get the IP address of a Docker container. Connect to the Bridge network and get the IP address of the Docker container One of the big reasons why docker containers are so convenient is that we can easily con

Uninstalling Docker on macOS

Publish Date:2025/03/25 Views:95 Category:Docker

Recently, we have seen widespread adoption of Docker as the ultimate containerization platform. Because of this, setting up Docker on all platforms has been greatly simplified, including macOS and Windows. However, some users usually face p

Enter the Docker container's shell

Publish Date:2025/03/25 Views:99 Category:Docker

This article will demonstrate how to enter the Docker container shell using multiple methods. Use docker exec to enter the Docker container's shell We need to have a container up and running to use this command. We can check the status of t

Listing containers in Docker

Publish Date:2025/03/25 Views:123 Category:Docker

This article will discuss various commands for listing containers created in our system. This means we should create some containers beforehand for these commands to return values. List all running containers in Docker We will start by list

Mount the host directory into the Docker container

Publish Date:2025/03/25 Views:189 Category:Docker

Docker provides, among other features, tools to work with the host operating system and the container file system. One of these features is the ability to persist data in containers and share data between containers by mounting directories

Docker build command with multiple parameters

Publish Date:2025/03/25 Views:138 Category:Docker

docker build The command allows us to create a Docker image from a Dockerfile. It also allows us to build an image from a context that references a set of files located in a location specified by a PATH or URL. A Dockerfile, on the other ha

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial