HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerCritical

Downloading Docker Images from Docker Hub without using Docker

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
withoutdockerdownloadinghubusingimagesfrom

Problem

I want to manually download a Docker Image from Docker Hub. More specifically, I want to download a Docker Image from Docker Hub on a machine in a restricted environment which does not (and cannot) have the Docker client software installed. I would have thought that this would be possible using the official API, but this does not appear to be the case - see the following discussion:

  • Fetch docker images without docker command. e.g. with wget



Is it really the case that the API doesn't support downloading images? Is there a way to work around this?

UPDATE 1:

I came across the following ServerFault post:

  • Downloading docker image for transfer to non-internet-connected machine



The accepted solution uses the docker save command, which doesn't help in my situation. But another solution posted there cites the following StackOverflow post:

  • Pulling docker images



One of the solutions there refers to a command-line tool called docker-registry-debug which, among other things, can generate a curl command for downloading an image. Here is what I got:

`user@host:~$ docker-registry-debug curlme docker ubuntu

# Reading user/passwd from env var "USER_CREDS"
# No password provided, disabling auth
# Getting token from https://index.docker.io
# Got registry endpoint from the server: https://registry-1.docker.io
# Got token: signature=1234567890abcde1234567890abcde1234567890,repository="library/docker",access=read
curl -i --location-trusted -I -X GET -H "Authorization: Token signature=1234567890abcde1234567890abcde1234567890,repository="library/docker",access=read" https://registry-1.docker.io/v1/images/ubuntu/layer

user@host:~$ curl \
-i --location-trusted -I -X GET \
-H "Authorization: Token signature=1234567890abcde1234567890abcde1234567890,repository="library/docker",access=read"

https://registry-1.docker.io/v1/images/ubuntu/layer
HTTP/1.1 404 NOT FOUND
Server: gunicorn/18.0
Date: Wed, 29 Nov 2017 01:00:00 GMT
Expires: -1
Content-Type: application/json
Pragma: no

Solution

It turned out that the Moby Project has a shell script on the Moby Github which can download images from Docker Hub in a format that can be imported into Docker:

  • download-frozen-image-v2.sh



The usage syntax for the script is given by the following:
download-frozen-image-v2.sh target_dir image[:tag][@digest] ...


The image can then be imported with tar and docker load:
tar -cC 'target_dir' . | docker load


To verify that the script works as expected, I downloaded an Ubuntu image from Docker Hub and loaded it into Docker:
user@host:~$ bash download-frozen-image-v2.sh ubuntu ubuntu:latest
user@host:~$ tar -cC 'ubuntu' . | docker load
user@host:~$ docker run --rm -ti ubuntu bash
root@1dd5e62113b9:/#


In practice I would have to first copy the data from the internet client (which does not have Docker installed) to the target/destination machine (which does have Docker installed):
user@nodocker:~$ bash download-frozen-image-v2.sh ubuntu ubuntu:latest
user@nodocker:~$ tar -C 'ubuntu' -cf 'ubuntu.tar' .
user@nodocker:~$ scp ubuntu.tar user@hasdocker:~


and then load and use the image on the target host:
user@hasdocker:~ docker load ubuntu.tar
user@hasdocker:~ docker run --rm -ti ubuntu bash
root@1dd5e62113b9:/#

Context

StackExchange DevOps Q#2731, answer score: 54

Revisions (0)

No revisions yet.