How to copy Docker images from one host to another without using a repository

前端 未结 15 1463
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 13:37

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

I create my own image in VirtualBox, and wh

相关标签:
15条回答
  • 2020-11-22 13:54

    I assume you need to save couchdb-cartridge which has an image id of 7ebc8510bc2c:

    stratos@Dev-PC:~$ docker images
    REPOSITORY                             TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    couchdb-cartridge                      latest              7ebc8510bc2c        17 hours ago        1.102 GB
    192.168.57.30:5042/couchdb-cartridge   latest              7ebc8510bc2c        17 hours ago        1.102 GB
    ubuntu                                 14.04               53bf7a53e890        3 days ago          221.3 MB
    

    Save the archiveName image to a tar file. I will use the /media/sf_docker_vm/ to save the image.

    stratos@Dev-PC:~$ docker save imageID > /media/sf_docker_vm/archiveName.tar
    

    Copy the archiveName.tar file to your new Docker instance using whatever method works in your environment, for example FTP, SCP, etc.

    Run the docker load command on your new Docker instance and specify the location of the image tar file.

    stratos@Dev-PC:~$ docker load < /media/sf_docker_vm/archiveName.tar
    

    Finally, run the docker images command to check that the image is now available.

    stratos@Dev-PC:~$ docker images
    REPOSITORY                             TAG        IMAGE ID         CREATED             VIRTUAL SIZE
    couchdb-cartridge                      latest     7ebc8510bc2c     17 hours ago        1.102 GB
    192.168.57.30:5042/couchdb-cartridge   latest     bc8510bc2c       17 hours ago        1.102 GB
    ubuntu                                 14.04      4d2eab1c0b9a     3 days ago          221.3 MB
    

    Please find this detailed post.

    0 讨论(0)
  • 2020-11-22 13:54

    All other answers are very helpful. I just went through the same problem and figure out an easy way with docker machine scp.

    Since Docker Machine v0.3.0, scp was introduced to copy files from one Docker machine to another. This is very convenient if you want copying a file from your local computer to a remote Docker machine such as AWS EC2 or Digital Ocean because Docker Machine is taking care of SSH credentials for you.

    1. Save you images using docker save like:

      docker save -o docker-images.tar app-web
      
    2. Copy images using docker-machine scp

      docker-machine scp ./docker-images.tar remote-machine:/home/ubuntu
      

    Assume your remote Docker machine is remote-machine and the directory you want the tar file to be is /home/ubuntu.

    1. Load the Docker image

      docker-machine ssh remote-machine sudo docker load -i docker-images.tar
      
    0 讨论(0)
  • 2020-11-22 13:57

    You will need to save the Docker image as a tar file:

    docker save -o <path for generated tar file> <image name>
    

    Then copy your image to a new system with regular file transfer tools such as cp, scp or rsync(preferred for big files). After that you will have to load the image into Docker:

    docker load -i <path to image tar file>
    

    PS: You may need to sudo all commands.

    EDIT: You should add filename (not just directory) with -o, for example:

    docker save -o c:/myfile.tar centos:16
    
    0 讨论(0)
  • 2020-11-22 13:57

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

    docker save <image> | (eval $(minikube docker-env) && docker load)
    
    0 讨论(0)
  • 2020-11-22 13:58

    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>
    
    0 讨论(0)
  • 2020-11-22 13:58

    You can use a one-liner with DOCKER_HOST variable:

    docker save app:1.0 | gzip | DOCKER_HOST=ssh://user@remotehost docker load
    
    0 讨论(0)
提交回复
热议问题