github.com/slene/docker@v1.8.0-rc1/docs/articles/registry_mirror.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Run a local registry mirror" 4 description = "How to set up and run a local registry mirror" 5 keywords = ["docker, registry, mirror, examples"] 6 [menu.main] 7 parent = "mn_docker_hub" 8 weight = 8 9 +++ 10 <![end-metadata]--> 11 12 # Run a local registry mirror 13 14 ## Why? 15 16 If you have multiple instances of Docker running in your environment 17 (e.g., multiple physical or virtual machines, all running the Docker 18 daemon), each time one of them requires an image that it doesn't have 19 it will go out to the internet and fetch it from the public Docker 20 registry. By running a local registry mirror, you can keep most of the 21 image fetch traffic on your local network. 22 23 ## How does it work? 24 25 The first time you request an image from your local registry mirror, 26 it pulls the image from the public Docker registry and stores it locally 27 before handing it back to you. On subsequent requests, the local registry 28 mirror is able to serve the image from its own storage. 29 30 ## How do I set up a local registry mirror? 31 32 There are two steps to set up and use a local registry mirror. 33 34 ### Step 1: Configure your Docker daemons to use the local registry mirror 35 36 You will need to pass the `--registry-mirror` option to your Docker daemon on 37 startup: 38 39 docker daemon --registry-mirror=http://<my-docker-mirror-host> 40 41 For example, if your mirror is serving on `http://10.0.0.2:5000`, you would run: 42 43 docker daemon --registry-mirror=http://10.0.0.2:5000 44 45 **NOTE:** 46 Depending on your local host setup, you may be able to add the 47 `--registry-mirror` options to the `DOCKER_OPTS` variable in 48 `/etc/default/docker`. 49 50 ### Step 2: Run the local registry mirror 51 52 You will need to start a local registry mirror service. The 53 [`registry` image](https://registry.hub.docker.com/_/registry/) provides this 54 functionality. For example, to run a local registry mirror that serves on 55 port `5000` and mirrors the content at `registry-1.docker.io`: 56 57 docker run -p 5000:5000 \ 58 -e STANDALONE=false \ 59 -e MIRROR_SOURCE=https://registry-1.docker.io \ 60 -e MIRROR_SOURCE_INDEX=https://index.docker.io \ 61 registry 62 63 ## Test it out 64 65 With your mirror running, pull an image that you haven't pulled before (using 66 `time` to time it): 67 68 $ time docker pull node:latest 69 Pulling repository node 70 [...] 71 72 real 1m14.078s 73 user 0m0.176s 74 sys 0m0.120s 75 76 Now, remove the image from your local machine: 77 78 $ docker rmi node:latest 79 80 Finally, re-pull the image: 81 82 $ time docker pull node:latest 83 Pulling repository node 84 [...] 85 86 real 0m51.376s 87 user 0m0.120s 88 sys 0m0.116s 89 90 The second time around, the local registry mirror served the image from storage, 91 avoiding a trip out to the internet to refetch it.