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

Detailed explanation of MySQL cursor concepts and usage

This article uses examples to explain the concept...

MySQL 5.6 compressed package installation method

There are two installation methods for MySQL: msi...

How to mount a data disk on Tencent Cloud Server Centos

First, check whether the hard disk device has a d...

Some ways to eliminate duplicate rows in MySQL

SQL statement /* Some methods of eliminating dupl...

Implement QR code scanning function through Vue

hint This plug-in can only be accessed under the ...

CocosCreator implements skill cooling effect

CocosCreator realizes skill CD effect There are s...

Summarize several common ranking problems in MySQL

Preface: In some application scenarios, we often ...

Solution to index failure caused by MySQL implicit type conversion

Table of contents question Reproduction Implicit ...

View the number of files in each subfolder of a specified folder in Linux

count script #!/bin/sh numOfArgs=$# if [ $numOfAr...

Implementation code for partial refresh of HTML page

Event response refresh: refresh only when request...

HTML Basics Must-Read - Comprehensive Understanding of CSS Style Sheets

CSS (Cascading Style Sheet) is used to beautify H...

How to use nginx to intercept specified URL requests through regular expressions

nginx server nginx is an excellent web server tha...

Solution to Mysql binlog log file being too large

Table of contents 1. Related binlog configuration...