6

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

Nur Rony
  • 7,823
  • 7
  • 38
  • 45
  • What OS are you on? Images are stored in machines, not the host, so there is no host image location. – Xiongbing Jin May 09 '16 at 03:22
  • @warmoverflow Yes I know it. but I want machines to share and saves images from hosts default location so that I can share images among multiple machines without pulling it from registry for each machine. Updated Question as well – Nur Rony May 09 '16 at 14:53

1 Answers1

3

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:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks @VonC this definitely helps. But I am looking for simpler workaround. Can't I skip the registry setup and make machine able to check default image location on host before pulling images in machine while creating a container into it? – Nur Rony May 09 '16 at 14:49
  • @nmrony see http://stackoverflow.com/q/33054369/6309: I would setup a registry mirror: https://docs.docker.com/registry/mirror/ – VonC May 10 '16 at 05:54
  • @ScottStensland Thank you. I have included the link in the answer for more visibility. – VonC Sep 07 '16 at 15:25