I would like to migrate a Docker image created on one server to another server. The Docker image to be migrated uses the one created in Article before last. The OS of both the migration source and migration destination servers is Amazon Linux 2.
Check the Docker image. Migrate the image named "ansible-demo".
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ansible-demo latest 590a85caf1ec 5 days ago 553MB
Then output the image to a tar file.
$ docker save ansible-demo > ansible-demo.tar
$ ls
ansible-demo.tar
If you have specified the version etc. in Tag, you can execute as follows You can save the image with the specified Tag name, and the Tag name will be inherited.
$ docker save ansible-demo:3.9.0-slim-buster > ansible-demo.tar
Use the scp command to copy the tar file to the destination server.
$ sudo scp -i .ssh/Private key file ansible-demo.tar [email protected]:/home/ec2-user
ansible-demo.tar 100% 568MB 64.2MB/s 00:08
Load the Docker image on the destination server.
$ sudo docker load < ansible-demo.tar
d0fe87fa8b8c: Loading layer [==================================================>] 72.49MB/72.49MB
225ef83ca30a: Loading layer [==================================================>] 7.316MB/7.316MB
83dcc4a0d3e6: Loading layer [==================================================>] 31.29MB/31.29MB
d93c07014f51: Loading layer [==================================================>] 4.608kB/4.608kB
b36284d246c4: Loading layer [==================================================>] 8.972MB/8.972MB
21aeb0eb9f43: Loading layer [==================================================>] 3.072kB/3.072kB
7f1f16e48b7f: Loading layer [==================================================>] 390.2MB/390.2MB
0ba8cec4031f: Loading layer [==================================================>] 85.38MB/85.38MB
Loaded image: ansible-demo:latest
You can confirm that the image file is loaded as shown below.
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ansible-demo latest 590a85caf1ec 6 days ago 553MB
Now, let's start the Docker container. Since WORKDIR is specified in the Dockerfile, execute it from the directory creation. The same container as the migration source has been started!
$ sudo mkdir /usr/src/app
$ cd /usr/src/app
$ sudo docker run -it --rm -v $(pwd):/usr/src/app ansible-demo /bin/bash
root@ff8c4ae0d144:/usr/src/app#
Recommended Posts