docker建立私有倉庫

因爲網速和大中華局域網效果,使得咱們在DockerHub下載鏡像的速度很慢,甚至一些國內的鏡像倉庫,也感受速度不是很好。因此,頗有必要在本地或者一個咱們訪問很快速的地方(本身的雲服務器)搭建一套鏡像倉庫。有了這樣一個倉庫,不只能夠提升下載速度,並且能夠增長咱們個性化定製的鏡像,以備後續使用。這篇將介紹怎樣搭建本地鏡像。docker

話外篇,配置docker代理ubuntu

若是有一個很快的代理,固然也能夠直接經過配置docker代理,以達到快速下載鏡像的目的。在搭建本地鏡像的過程也須要從DockerHub上下載完整鏡像文件,若是訪問緩慢的話,下載將會很是緩慢。設置代理的方法很是簡單,這裏以CentOS6.5爲例。緩存

找到/etc/default/docker,打開編輯,找到下面export http_proxy部分,去掉註釋並修改成本身的代理便可。bash

# Docker Upstart and SysVinit configuration file

# Customize location of Docker binary (especially for development testing).
#DOCKER="/usr/local/bin/docker"

# Use DOCKER_OPTS to modify the daemon startup options.
#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

# If you need Docker to use an HTTP proxy, it can also be specified here.
export http_proxy="http://xxxx:port"

# This is also a handy place to tweak where Docker's temporary files go.
#export TMPDIR="/mnt/bigdrive/docker-tmp"
DOCKER_OPTS="--insecure-registry dl.dockerpool.com:5000"

建立私有倉庫服務器

本文記錄以Docker官方提供的鏡像Registry 建立本地私有倉庫,建立方式和啓動一個普通鏡像的方式是同樣。curl

1.在私有倉庫服務器快速建立鏡像倉庫,運行以下代碼:ide

docker run -p 5000:5000 registry:2.0

運行上述命令後,會從DockerHub上拉取registry鏡像並在本地啓動Registry服務,並監聽5000端口。 url

2.列出本地鏡像代理

docker images

  

能夠看到registry的鏡像和一個本地ubuntu:12.04的鏡像blog

3.從新標記一個本地鏡像爲私有倉庫的版本,這裏將本地的ubuntu 12.04標記爲localhost:5000/ubuntu:1204。

docker tag ubuntu:12.04 localhost:5000/ubuntu:1204

再次查看鏡像能夠看到多了一個標記爲localhost:5000/ubuntu:1204的鏡像

4.將本地鏡像推送到本地倉庫中

docker push localhost:5000/ubuntu:1204

5.查看本地倉庫中的鏡像列表

curl http://localhost:5000/v2/ubuntu/tags/list

結果以下:

{"name":"ubuntu","tags":["1204"]}

 6.從本地倉庫拉取一個鏡像,在這以前先執行以下命令移除本地未使用的鏡像,保證從本地倉庫拉取的鏡像不是從緩存中獲取。

 docker rmi -f $(docker images -q -a )

以後再查看鏡像,只剩下registry這個鏡像

拉取本地倉庫中的鏡像

docker pull localhost:5000/ubuntu:1204

Unable to find image 'localhost:5000/ubuntu:1204' locally
1204: Pulling from localhost:5000/ubuntu
b796a17a2688: Pull complete 
273721eafe54: Pull complete 
7dd38dbb5eda: Pull complete 
32190de3770a: Already exists

以後查看鏡像以下:

  

最後正常啓動

docker run --name mytestubuntu localhost:5000/ubuntu:1204 

歡迎關注公衆號「gushidefengzheng」古時的風箏

相關文章
相關標籤/搜索