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

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

    docker-push-ssh is a command line utility I created just for this scenario.

    It sets up a temporary private Docker registry on the server, establishes an SSH tunnel from your localhost, pushes your image, then cleans up after itself.

    The benefit of this approach over docker save (at the time of writing most answers are using this method) is that only the new layers are pushed to the server, resulting in a MUCH quicker upload.

    Oftentimes using an intermediate registry like dockerhub is undesirable, and cumbersome.

    https://github.com/brthor/docker-push-ssh

    Install:

    pip install docker-push-ssh
    

    Example:

    docker-push-ssh -i ~/my_ssh_key username@myserver.com my-docker-image

    The biggest caveat is that you have to manually add your localhost to Docker's insecure_registries configuration. Run the tool once and it will give you an informative error:

    Error Pushing Image: Ensure localhost:5000 is added to your insecure registries.
    More Details (OS X): https://stackoverflow.com/questions/32808215/where-to-set-the-insecure-registry-flag-on-mac-os
    

    Where should I set the '--insecure-registry' flag on Mac OS?

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

    When using docker-machine, you can copy images between machines mach1 and mach2 with:

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

    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.

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

    I want to move all images with tags.

    ```
    OUT=$(docker images --format '{{.Repository}}:{{.Tag}}')
    OUTPUT=($OUT)
    docker save $(echo "${OUTPUT[*]}") -o /dir/images.tar
    ``` 
    

    Explanation:

    First OUT gets all tags but separated with new lines. Second OUTPUT gets all tags in an array. Third $(echo "${OUTPUT[*]}") puts all tags for a single docker save command so that all images are in a single tar.

    Additionally, this can be zipped using gzip. On target, run:

    tar xvf images.tar.gz -O | docker load
    

    -O option to tar puts contents on stdin which can be grabbed by docker load.

    0 讨论(0)
提交回复
热议问题