Migrate Docker image to another server

What you want to achieve

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.

Save Docker image

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

Copy the tar file to the destination server

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

Loading Docker image

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

Operation check

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

Migrate Docker image to another server
Migrate existing Rails 6 apps to Docker environment
Proxy server with squid using docker image
[AWS CLI] Switch roles to get a Docker image in another account
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
How to make Spring Boot Docker Image smaller
Migrate from Java to Server Side Kotlin + Spring-boot
How to give your image to someone with docker
Push the image to docker hub using Jib
Connect with VS Code from a Windows client to Docker on another server
Steps to push Docker image to GitHub Container Registry (ghcr.io)
Migrate from JUnit 4 to JUnit 5
How to deploy to Heroku from a local docker image
How to install Docker
Delete unused docker image
Introduce RMagick to convert existing existing image files to another format
[Docker + Rails] How to deal with Rails server startup failure
I can't find the docker image after updating to docker desktop 2.4.0.0
The key to running Docker on Raspberry Pi 4 (Ubuntu server 20.04)
[Personal notes] How to push a Docker image to GitHub Packages
Install Docker on Ubuntu Server 20.04
Install yarn in docker image
docker review image creation-container start
Migrating from vargrant to docker
Migrate GitBucket database to postgreSQL
Extract files from Docker Image
How to set Docker nginx
How to terminate rails server
How to migrate from JUnit4 to JUnit5
I tried to build the environment of PlantUML Server with Docker
[Docker] Magic command when you want to wipe out none image
Minimal Workflow to push Docker image to Github Container Registry with Github Actions
Use Jenkins to build inside Docker and then create a Docker image.
[GCP] Until you push the local Docker image to the Container Registry