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

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

提交回复
热议问题