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

Advanced Usage Examples of mv Command in Linux

Preface The mv command is the abbreviation of mov...

A brief discussion on several situations where MySQL returns Boolean types

mysql returns Boolean type In the first case, ret...

What you need to understand about MySQL locks

1. Introduction MySQL locks can be divided into g...

W3C Tutorial (1): Understanding W3C

W3C, an organization founded in 1994, aims to unl...

How to install pyenv under Linux

Prerequisites Need to install git Installation St...

Example of using mycat to implement MySQL database read-write separation

What is MyCAT A completely open source large data...

Super detailed tutorial to implement Vue bottom navigation bar TabBar

Table of contents Project Introduction: Project D...

A mobile adaptive web page effect solves the problem of small display page

For work needs, I need to make a mobile phone adap...

Discuss the value of Web standards from four aspects with a mind map

I have roughly listed some values ​​to stimulate ...

How to install phabricator using Docker

I am using the Ubuntu 16.04 system here. Installa...

Tomcat uses Log4j to output catalina.out log

Tomcat's default log uses java.util.logging, ...

TypeScript namespace merging explained

Table of contents Merge namespaces with the same ...