loading...

Download Docker Images without Docker Pull

tomsfernandez profile image Tomas Fernandez Updated on ・2 min read

Docker pull is the basic command for using Docker images. It works most of the time but sometimes it freezes in the middle of the download. Lots of people have raised issues about this with hacks that involve killing a process or restarting the docker-machine several times.

All these hacks aren't an issue with small image sizes like the alpine distribution or an nginx image but, what about the large images? Images that weight like 500 MB or 2 GB?

These hacks aren't useful because they involve downloading large layers over and over again.

A better workaround is to download the images manually and load them to the docker-machine. This is a much better solution as the manual download has much lower chances to fail than restarting the docker-machine hoping that docker pull starts working.

To download a docker image manually, there is a script called 'download-frozen-image-v2.sh' in the Moby project that lets us do that:

https://github.com/moby/moby/blob/master/contrib/download-frozen-image-v2.sh

GitHub logo moby / moby

Moby Project - a collaborative project for the container ecosystem to assemble container-based systems

The Moby Project

Moby Project logo

Moby is an open-source project created by Docker to enable and accelerate software containerization.

It provides a "Lego set" of toolkit components, the framework for assembling them into custom container-based systems, and a place for all container enthusiasts and professionals to experiment and exchange ideas Components include container build tools, a container registry, orchestration tools, a runtime and more, and these can be used as building blocks in conjunction with other tools and projects.

Principles

Moby is an open project guided by strong principles, aiming to be modular, flexible and without too strong an opinion on user experience It is open to the community to help set its direction.

  • Modular: the project includes lots of components that have well-defined functions and APIs that work together.
  • Batteries included but swappable: Moby includes enough components to build fully featured container system, but its modular architecture ensures that most of…

This script only needs three things installed:

  • Curl
  • Jq
  • Go

To use the script we only need to specify the image to download and the location relative to the current:

$ ./download-frozen-image-v2.sh "example" hello-world:latest

In this example we are downloading the image "hello-world:latest" in the "example" directory.

Note: be sure to specify the version tag. If not specified, the script will return Not Found (404)

This will download several files into the "example" directory:

  • manifest.json
  • repositories file
  • json with details of the image
  • folder for each layer in the image

The only thing next to do is load it into the docker-machine. The script outputs the command necessary to do it:

$ tar -cC 'example' . | docker load
af0b15c8625b: Loading layer [==================================================>]     977B/977B
Loaded image: hello-world:latest

Congratulations! You have pulled a docker image without the docker pull command!

Discussion

pic
Editor guide
Collapse
nilox94 profile image
Danilo Gómez

Hi, really thank you!
I made a Google Colab notebook for saving Docker images to Google Drive using the script.

Collapse
matya profile image
Janos Mattyasovszky

Hi.

I have had the same (similar) problems but unfortunately the script was not properly sufficient as it did not include support for non-docker registries.

I have forked it and added some features to it, if anyone is interested in.
github.com/matya/download-docker-i...

cheers
JM

Collapse
mohbob profile image
MOHAMED BOUBENIA

Unfortunatly, the docker load command doesn't create a docker image when I executed "tar -cC 'example' . | docker load"
Can you help me please ?

Thank you !

Collapse
tomsfernandez profile image
Tomas Fernandez Author

1) What image are you trying to load ?
2) Is there an error message of sorts ?

Collapse
mohbob profile image
MOHAMED BOUBENIA

Hi Tomas,
1) I'm trying to load this image: eesprit/example-voting-app
2) No, I get no message.

I'm on windows, and I'm using Docker Toolbox 19.03.5

Thanks a lot.

Thread Thread
tomsfernandez profile image
Tomas Fernandez Author

I updated the article to show the output of downloading the "hello-world" image and added some clarifications to the process. To clarify:

  • The "example" argument is the directory were the image will be downloaded. You should load it from the same place.
  • It is strange that you don't get an error message. I never got a message in any of the scenarios I tested