Docker time zone issue and data migration issue

Docker time zone issue and data migration issue

Latest solution:

-v /usr/share/zoneinfo/Asia/Shanghai:/etc/timezone -v /etc/localtime:/etc/localtime:ro

docker run --name tomcat-service-0 -d -p 8080:8080 -v /usr/share/zoneinfo/Asia/Shanghai:/etc/timezone -v /etc/localtime:/etc/localtime:ro -v /home/zjy/logs/tomcat-service-0:/usr/local/tomcat/logs -v /home/zjy/code/ligu/target:/usr/local/tomcat/webapps tomcat

Question 1

When the project was deployed using Docker, it was found that the time zone in the Docker container was 8 hours different from the server time.
Although the server time and container time are synchronized using -v /etc/localtime:/etc/localtime, the time zone of Tomcat in the container is still 8 hours different.

illustrate

-v /etc/localtime:/etc/localtime

When starting up, using this command only mounts the system time of the server and the container. You may enter the container and execute the "date" command to see that the time in the container is indeed changed, but the date of the environment where tomcat runs in the container is actually still unchanged.
Because the time zone of the Tomcat container is fixed when we pull the Tomcat image, our only solution is to bind the local server time to the image when compiling the Tomcat image.

Solution (super simple)

Use dockerFile to compile the image. The Dockerfile is as follows

# Pull base image 
FROM tomcat:latest 
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

Execute the following command

Command format:
$docker build -t image_name Dockerfile_path
$:docker build -t timetomcat/timetomcat .

Then when you start the container later, use the compiled tomcat

As shown

insert image description here

Docker container migration

illustrate

When a server deployed by Docker changes, such as a database, and you want to deploy it to a new address, there are many ways to migrate this data:

For databases:

1 Use MySQL's master-slave replication backup. During the project operation, back up the MySQL server to multiple addresses. For details, please see the address: https://zhangjy520.github.io/

2 When starting MySQL, use -v to mount the local path and container path, and then copy the local path to the new server when migrating.
-v /home/mysql/master/data/db-conf:/etc/mysql/ -v /home/mysql/master/data/db-data:/var/lib/mysql

3 Export the MySQL database and import it to a new address, which is relatively low

4 Use Docker container migration. This blog is mainly about docker. Here we mainly talk about how to use docker migration

Solution (super simple) Container migration

export / import

Execute on the source server

docker export 83271b648212 >time.tar //Export the container. The number here is the container ID. A tarball will be obtained.

Explanation: When you open this compressed package, you can see that it is actually a directory structure of a Linux server. This command packages the container and the environment in which the container runs.

Execute on the destination server

cat time.tar | sudo docker import - time:v2 //Import the container and import it to get an image. Use docker run with command /bin/bash
You can get the previous container including files

Start the image

sudo docker run -itd --name import_test -p 8087:8080 time:v2 /bin/bash 

insert image description here

insert image description here

insert image description here

insert image description here

save / load

sudo docker save web > web.tar
sudo docker load < web.tar

This is the end of this article about docker time zone issues and data migration issues. For more information about docker time zone issues and data migration issues, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Docker container time zone adjustment operation
  • 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

<<:  A brief discussion on the matching rules of host and user when Mysql connects to the database

>>:  JavaScript anti-shake and throttling detailed explanation

Recommend

The pitfalls of deploying Angular projects in Nginx

Searching online for methods to deploy Angular pr...

MySQL multi-instance configuration application scenario

Table of contents MySQL multiple instances Multi-...

Native js to realize bouncing ball

On a whim, I wrote a case study of a small ball b...

In-depth analysis of MySQL explain usage and results

Preface In daily work, we sometimes run slow quer...

The difference between method=post/get in Form

Form provides two ways of data transmission - get ...

Implementation of socket options in Linux network programming

Socket option function Function: Methods used to ...

JavaScript to implement slider verification code

This article shares the specific code of JavaScri...

Linux system command notes

This article describes the linux system commands....

Example code of javascript select all/unselect all operation in html

Copy code The code is as follows: <html> &l...

CSS pseudo-class: empty makes me shine (example code)

Anyone who has read my articles recently knows th...

Several ways to shut down Hyper-V service under Windows 10

When using VMware Workstation to open a virtual m...

Ubuntu 20.04 how to modify the IP address example

illustrate: Today, when continuing the last offic...