How to copy Docker images from one host to another

2019-01-01 11:20发布

How do I transfer a Docker image from one machine to another one without using a repository, no matter private or public?

I am used to play and create my own image in VirtualBox, and when it is finished, I try to deploy to other machines to have real usage.

Since it is based on own based image (like Red Hat Linux), it cannot be recreated from a Dockerfile.

Are there simple commands I can use? Or another solution?

It seems save/export can achieve a similar purpose, see What is the difference between save and export in Docker?, and I prefer the save command for my case.

标签: docker
14条回答
不再属于我。
2楼-- · 2019-01-01 11:56

When using docker-machine, you can do docker $(docker-machine config <mach1>) save <image> | docker $(docker-machine config <mach2>) load to copy images between machines mach1 and mach2.

And of course you can also stick pv in the middle to get a progess indicator:

docker $(docker-machine config <mach1>) save <image> | pv | docker $(docker-machine config <mach2>) load.

You may also omit one of the docker-machine config sub-shells, to use your current default docker-host.

docker save <image> | docker $(docker-machine config <mach>) load to copy image from current docker-host to mach

or

docker $(docker-machine config <mach>) save <image> | docker load to copy from mach to current docker-host.

查看更多
人气声优
3楼-- · 2019-01-01 11:57

This is how you can move Docker images between two remote registers/repositories. It works with Docker version 1.10.2, build c3959b1.

docker pull source-registry.com/myProject/myImageName:1.0.0
docker tag source-registry.com/myProject/myImageName:1.0.0 target-remote-registry.com/myProject/myImageName:1.0.0
docker push target-remote-registry.com/myProject/myImageName:1.0.0

It's a handy method if you want to migrate your images to an AWS ECS/ECR service.

查看更多
冷夜・残月
4楼-- · 2019-01-01 11:58

First save the Docker image to a zip file:

docker save <docker image name> | gzip > <docker image name>.tar.gz

Then load the exported image to Docker using the below command:

zcat <docker image name>.tar.gz | docker load
查看更多
永恒的永恒
5楼-- · 2019-01-01 12:02

To transfer images from your local Docker installation to a minikube VM:

docker save <image> | (eval $(minikube docker-env) && docker load)
查看更多
路过你的时光
6楼-- · 2019-01-01 12:03

Transferring a Docker image via SSH, bzipping the content on the fly:

docker save <image> | bzip2 | \
     ssh user@host 'bunzip2 | docker load'

It's also a good idea to put pv in the middle of the pipe to see how the transfer is going:

docker save <image> | bzip2 | pv | \
     ssh user@host 'bunzip2 | docker load'

(More info about pv: home page, man page).

查看更多
十年一品温如言
7楼-- · 2019-01-01 12:04

To save an image to any file path or shared NFS place see the following example.

Get the image id by doing:

sudo docker images

Say you have an image with id "matrix-data".

Save the image with id:

sudo docker save -o /home/matrix/matrix-data.tar matrix-data

Copy the image from the path to any host. Now import to your local Docker installation using:

sudo docker load -i <path to copied image file>
查看更多
登录 后发表回答