Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make docker machine to get images from host before pulling any image for itself?

I found that every time I create a container in a new machine it is pulling image from docker hub. I have searched the web but found no well formed result. I have pulled the images from hub on host machine. now my question is how to make docker machine to check the host image location before pulling any image into virtualbox? I want machines to share and save images from host's default location so that I can share images among multiple machines without pulling it from registry for each machine

like image 454
Nur Rony Avatar asked May 09 '16 01:05

Nur Rony


1 Answers

In a new machine, meaning a new VM, docker will indeed pull images from docker hub to the local VM docker image storage path:

/var/lib/docker/images

Each new machine has its own image cache.

If you want to share images amongst machine, you need one acting as your private registry, with its own certificate to enable https access.
See an example here, using gen_ssl_key_and_crt.sh for the key/certificate generation:

./gen_ssl_key_and_crt.sh
if [[ "$(docker inspect -f {{.State.Running}} registry 2> /dev/null)" == "" ]]; then
    docker run -d -p 5000:5000 --restart=always --name registry \
        -v $(pwd)/certs:/certs \
        -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/crt \
        -e REGISTRY_HTTP_TLS_KEY=/certs/key \
        registry:2
fi

Then your other machine can pull from that registry, which is much faster, and which will pull from docker hub only once, the first time it sees it does not have in its own registry the image.

For instance:

if [[ "$(docker images -q kv:5000/b2d/git:2.8.1 2> /dev/null)" == "" ]]; then
    docker pull kv:5000/b2d/git:2.8.1
fi

For a simpler workaround, see:

  • "How to change the default docker registry from docker.io to my private registry"
  • "Run a local registry mirror"
like image 73
VonC Avatar answered Nov 15 '22 04:11

VonC