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

Display and hide HTML elements through display or visibility

Sometimes we need to control whether HTML elements...

Detailed explanation on how to get the IP address of a docker container

1. After entering the container cat /etc/hosts It...

SQL Practice Exercise: Online Mall Database Product Category Data Operation

Online shopping mall database-product category da...

Best Practices for Implementing Simple Jira Projects with React+TS

A set of projects for training react+ts Although ...

Troubleshooting the cause of 502 bad gateway error on nginx server

The server reports an error 502 when synchronizin...

Detailed explanation of MySQL's FreeList mechanism

1. Introduction After MySQL is started, BufferPoo...

WeChat applet custom tabbar component

This article shares the specific code of the WeCh...

Implementation of react automatic construction routing

Table of contents sequence 1. Centralized routing...

Detailed explanation of the use of umask under Linux

I recently started learning Linux. After reading ...

Deploy the Vue project on a Linux server

Case 1 vue-cli builds the vue3 project, uploads t...

Nginx configuration SSL and WSS steps introduction

Table of contents Preface 1. Nginx installation 1...

A brief introduction to MySQL dialect

Putting aside databases, what is dialect in life?...