github.com/feiyang21687/docker@v1.5.0/docs/sources/articles/registry_mirror.md (about)

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