Docker service migration (from one server to another)

Take Nginx as an example:

1. First deploy the Nginx service on the 183 server:

① Pull the mirror

docker pull nginx:latest

Insert picture description here
②Run the container

docker run --name nginx-test -p 12308:80 -d nginx

Parameter description:
--name nginx-test: container name.
-p 12308:80: port mapping, mapping the local port 12308 to port 80 inside the container.
-d nginx: Set the container to always run in the background.

③View the container process

docker ps -a

Insert picture description here
Visit 192.168.1.183:12308, the visit is successful:
Insert picture description here

2. Save the container as an image

docker commit container name mirror name

docker commit nginx-test nginxtest

This can be seen as an additional Nginx image, which is the one we just generated.
Insert picture description here

3. Pack the image into a tar file

docker save -o xxx.tar image name

docker save -o nginxTest.tar nginxtest
docker save nginxtest > nginxTest.tar

Insert picture description here
Note: If you need to merge multiple images into a tar package:

docker save [images] [images] > [name.tar]

4. Download the tar file and upload it to other servers (185)

5. Mirror recovery

Execute the following command to restore:

docker load < xxx.tar
docker load -i xxx.tar

Insert picture description here
At this time, the nginxtest image appears in the docker of the 185 server.Execute the
Insert picture description here
following command to start the container:

 docker run --name nginx-test -p 12309:80 -d nginxtest

Insert picture description here
Visit 192.168.1.185:12309, the visit is successful:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44455388/article/details/107539559