I have an image saved to disk as a .tar
file. I would like to run this image as a container.
docker run
take an image name, but I don't know what the name is; I only have a .tar
file.
Is it possible to pass .tar
directly to docker run
? How?
I have an image saved to disk as a .tar
file. I would like to run this image as a container.
docker run
take an image name, but I don't know what the name is; I only have a .tar
file.
Is it possible to pass .tar
directly to docker run
? How?
1 Answer
Reset to default 0You can't do this directly; you must docker load
the tar file first. Docker needs to import the image layers into its internal copy-on-write filesystem storage so that it can create the temporary container filesystem.
The other trick is finding the image name, if you don't already know it. This answer has a shell fragment using jq
to extract the image name from JSON metadata embedded in the tar file.
So the best you can do is to load the image and then run it
docker load -i test_v1.0.tar
IMAGE=$(tar -xf test_v1.0.tar --to-stdout repositories | jq -r ".[\"${repository}\"] | keys | .[0]")
docker run ... "$IMAGE"