What is the difference between import and load in Docker?

南笙酒味 提交于 2019-11-27 18:41:43
VonC

docker save will indeed produce a tarball, but with all parent layers, and all tags + versions.

docker export does also produce a tarball, but without any layer/history.

It is often used when one wants to "flatten" an image, as illustrated in "Flatten a Docker container or image" from Thomas Uhrig:

docker export <CONTAINER ID> | docker import - some-image-name:latest

However, once those tarballs are produced, load/import are there to:

  • docker import creates one image from one tarball which is not even an image (just a filesystem you want to import as an image)

Create an empty filesystem image and import the contents of the tarball

  • docker load creates potentially multiple images from a tarred repository (since docker save can save multiple images in a tarball).

Loads a tarred repository from a file or the standard input stream

qootec

As a Docker-newbie, I learnt this difference the hard way.

  • On one system:

    docker run -it myImage /bin/bash
    

    --> Works fine

  • On that same system:

    docker **save** myImage -o myImage.tar
    
  • On second system:

    docker **import** myImage.tar
    

    --> Works nicely, no issues, just tag required:

    docker tag _the_assigned_tag myImage
    
  • On that second system:

    docker run -it myImage /bin/bash
    

    docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown.

Looking for that error brought my to all kinds of reasons such as MountFlags="slave", but the real reason turned out to be the one described in this post: I should have used load instead of import. Not knowing what was going on, Docker's error message didn't put me in any sense on track towards the "import" cause, till I stumbled over this post.

docker import is mostly used with a tarball that is created out of running container. For Eg. docker export containerID > /home/cntr.tar then import this tarball to an image Eg. docker import /home/cntr.tar mynewimage:tag

Whereas docker load is used to load the image from a tarball that is created from another image. For Eg. docker save > /home/fromimg.tar then load it back with docker load < /home/fromimg.tar

the main difference though docker save/load with image does preserve the image history. Whereas docker export/import with container flattens the image by removing all the history of the container.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!