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

前端 未结 15 1428
爱一瞬间的悲伤
爱一瞬间的悲伤 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:59

    For a flattened export of a container's filesystem, use;

    docker export CONTAINER_ID > my_container.tar

    Use cat my_container.tar | docker import - to import said image.

    0 讨论(0)
  • 2020-11-22 14:04

    You may use sshfs:

    $ sshfs user@ip:/<remote-path> <local-mount-path>
    $ docker save <image-id> > <local-mount-path>/myImage.tar
    
    0 讨论(0)
  • 2020-11-22 14:07

    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).

    0 讨论(0)
  • 2020-11-22 14:07

    Script to perform Docker save and load function (tried and tested):

    Docker Save:

    #!/bin/bash
    
    #files will be saved in the dir 'Docker_images'
    mkdir Docker_images
    cd Docker_images
    directory=`pwd`
    c=0
    #save the image names in 'list.txt'
    doc= docker images | awk '{print $1}' > list.txt
    printf "START \n"
    input="$directory/list.txt"
    #Check and create the image tar for the docker images
    while IFS= read -r line
    do
         one=`echo $line | awk '{print $1}'`
         two=`echo $line | awk '{print $1}' | cut -c 1-3`
         if [ "$one" != "<none>" ]; then
                 c=$((c+1))
                 printf "\n $one \n $two \n"
                 docker save -o $two$c'.tar' $one
                 printf "Docker image number $c successfully converted:   $two$c \n \n"
         fi
    done < "$input"
    

    Docker Load:

    #!/bin/bash
    
    cd Docker_images/
    directory=`pwd`
    ls | grep tar > files.txt
    c=0
    printf "START \n"
    input="$directory/files.txt"
    while IFS= read -r line
    do
         c=$((c+1))
         printf "$c) $line \n"
         docker load -i $line
         printf "$c) Successfully created the Docker image $line  \n \n"
    done < "$input"
    
    0 讨论(0)
  • 2020-11-22 14:11

    Run

    docker images
    

    to see a list of the images on the host. Let's say you have an image called awesomesauce. In your terminal, cd to the directory where you want to export the image to. Now run:

    docker save awesomesauce:latest > awesomesauce.tar
    

    Copy the tar file to a thumb drive or whatever, and then copy it to the new host computer.

    Now from the new host do:

    docker load < awesomesauce.tar
    

    Now go have a coffee and read Hacker News...

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

    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
    
    0 讨论(0)
提交回复
热议问题