Docker container time zone adjustment operation

Docker container time zone adjustment operation

How to check if the Docker container time zone is consistent with the host machine?

1. Enter the host machine and execute the following command:

# Check the host time

[root@localhost ~]# date

Wednesday, June 27, 2018 22:42:44 CST

2. Enter the container and execute the following command

# View container time

root@lksjoid909090:/#date

Wed Jul 27 14:43:31 UTC 2018

CST should refer to (China Shanghai Time, Eastern Time Zone 8)

UTC should refer to (Coordinated Universal Time, standard time)

It can be found that they are 8 hours apart, and the time zone of the host machine and the Docker container are inconsistent.

Solution:

1. [Before the image is produced] The base image sets the time zone in the Dockerfile:

ENV TZ=Asia/Shanghai

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

2. [After the image is generated && the container is not created] When creating and starting the container:

# Shared hosting time

docker run --name <name> -v /etc/localtime:/etc/localtime:ro ...

3. [After the image is generated && the container is started] Outside the container, modify in the host machine:

docker cp /etc/localtime [container ID or NAME]:/etc/localtime

4. [After the image is generated && the container is started] In the container

apk add tzdata

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime echo "Asia/Shanghai" > /etc/timezone

Additional knowledge: Docker command error error during connect: Get http://2F2F.2Fpipe2Fdocker_engine/v1.36/containers/json: open//.

Executing docker ps reports an error

error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.36/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

The error message is as follows:

Workaround

1. Execute the command:

docker-machine env default

2. Method 1:

Copy the displayed command and execute it

After execution, execute commands such as docker ps and you can use it normally

3. Method 2:

Only the last sentence

REM @FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

Remove REM from the command and execute it.

@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

After execution, the docker command can be used normally. Each time you open a new cmd window, you need to set the environment variables first.

Note: When using method 2 in a bat script, directly putting the FOR statement into the bat script will result in an error. Change the %i in the command to %%i.

The above Docker container time zone adjustment operation 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 time zone issue and data migration issue
  • How to deal with time zone issues in Docker
  • The created Docker container time display error/date error/time zone error
  • Detailed explanation of modifying docker time zone and common docker commands
  • How to solve the problem of Docker container time zone and time synchronization
  • The difference between two ways to create a docker image and start the container (summary)
  • Docker container time zone error issue

<<:  How to make if judgment in js as smooth as silk

>>:  MySQL obtains the current date and time function example detailed explanation

Recommend

Detailed description of the function of new in JS

Table of contents 1. Example 2. Create 100 soldie...

A practical record of an accident caused by MySQL startup

Table of contents background How to determine whe...

How to install MySQL and MariaDB in Docker

Relationship between MySQL and MariaDB MariaDB da...

In-depth understanding of slot-scope in Vue (suitable for beginners)

There are already many articles about slot-scope ...

Detailed explanation of MySQL's MERGE storage engine

The MERGE storage engine treats a group of MyISAM...

Detailed explanation of Docker Swarm service orchestration commands

1. Introduction Docker has an orchestration tool ...

Use and optimization of MySQL COUNT function

Table of contents What does the COUNT function do...

MySQL v5.7.18 decompression version installation detailed tutorial

Download MySQL https://dev.mysql.com/downloads/my...

MySQL changes the default engine and character set details

Table of contents 1. Database Engine 1.1 View dat...

How to Install and Configure Postfix Mail Server on CentOS 8

Postfix is ​​a free and open source MTA (Mail Tra...

Examples of MySQL and Python interaction

Table of contents 1. Prepare data Create a data t...