'What is the difference between import and load in Docker?
I understand the difference between export (for containers) and save (for images). But at the end of the day the tarball produced by either save or export should be used as an image.
So why are there 2 commands to make an image from a tarball?
Solution 1:[1]
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 (using save):
docker save myImage -o myImage.tarOn second system (using import):
docker import myImage.tar--> Works nicely, no issues, just tag required:
docker tag _the_assigned_tag myImageOn that second system:
docker run -it myImage /bin/bashdocker: 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.
Solution 2:[2]
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.
Solution 3:[3]
I want to share another difference from real world situation using docker save and on prod servers using docker import vs docker load.
On the server with internet access docker import worked the same way as docker load. Container was up and running without error and missing layers have been downloaded over internet.
On the server without internet - on-prem setup docker import cause above error on container start e.g.
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.
In order to get saved container up and running without that we need to use docker load < saved-container.tgz In that way all the layers are imported.
Solution 4:[4]
While this is not visible in the Actions Console, it is something that can be done if you download the project to a local environment using gactions.
You can create a new Type in under custom/types. You will use create RegularExpression Entities.
regularExpression:
entities:
# `bankNumber` is your parameter name. It can be custom.
bankNumber:
regularExpressions:
- \d{8} # In the `re2` syntax
Then you'll need to re-upload your project to the Actions Console with gactions push and gactions deploy preview.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | |
| Solution 3 | gsone |
| Solution 4 | Nick Felker |
