What is the process for moving a Docker image from one Droplet to another? thank you

November 9, 2019 217 views
DigitalOcean Accounts

We currently have a ‘Docker Image’ running on a Droplet (MUCH to big).. we need to migrate this to some other Droplet. What is the process for moving a Docker image from one Droplet to another? thank you

1 Answer

Hello,

There are a few ways to do that:

  • 1. Export and import containers

This would essentially mean that you would compress the data to a file from the container’s file system. The data would be saved as a ‘gzip’ file. To do that run:

docker export CONTAINER_NAME | gzip > CONTAINER_NAME.gz

Then copy this file to the droplet and start the container with:

zcat CONTAINER_NAME.gz | docker import - CONTAINER_NAME

After that start the container on the new host with the docker run command.

  • 2. Image migration

This is the most commonly used method. You would need to first create a docker image of the running container with the docker commit command:

docker commit CONTAINER_ID IMAGE_NAME

Then you can push your image to docker hub:

docker image tag IMAGE_NAME YOUR_TAG

After that push your new image to docker hub. For that you would need a docker hub account first:

Login:

docker login

Push the image:

docker push YOUR_DOCKER_HUB_uSER/IMAGE_NAME

Then on your new droplet, login to docker hub again:

docker login

And pull your image:

docker pull IMAGE_NAME
  • 3. Save and load images

The images can be compressed using docker save and moved to a new host.

docker save IMAGE_NAME > IMAGE_NAME.tar

This would create a tarball of your local docker image which you could copy to your new server and re-deploy with the docker load command:

docker load -i IMAGE_NAME.tar

If all went through successfully you should be able to see your new image with:

docker images

Hope that this helps!
Regards,
Bobby

Have another answer? Share your knowledge.