安裝部署一個(gè)私有的Docker Registry是引入、學(xué)習(xí)和使用Docker這門技術(shù)的必經(jīng)之路之一。尤其是當(dāng)Docker被所在組織接受,更多人、項(xiàng)目和產(chǎn)品開始接觸和使用Docker時(shí),存儲(chǔ)和分發(fā)自制的Docker image便成了剛需。Docker Registry一如既往的繼承了“Docker坑多”的特點(diǎn),為此這里將自己搭建”各類”Registry過程中執(zhí)行的步驟、遇到的問題記錄下來,為己備忘,為他參考。
Registry2在鏡像存儲(chǔ)方面不僅支持本地盤,還支持諸多主流第三方存儲(chǔ)方案。通過分布式存儲(chǔ)系統(tǒng)你還可以實(shí)現(xiàn)一個(gè)分布式Docker Registry服務(wù)。
準(zhǔn)備
server1,server2 (其中server1作為私有庫服務(wù)器,server2作為普通客戶端)
在server1上
1 下載 registry
docker pull registry:latest
2 配置 /etc/default/docker 因?yàn)閔ttps需要證書密碼等比較復(fù)雜,直接加 insecure-registry即可
# 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"
DOCKER_OPTS="--insecure-registry 127.0.0.1:5000"
# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy="http://127.0.0.1:3128/"
# This is also a handy place to tweak where Docker's temporary files go.
#export TMPDIR="/mnt/bigdrive/docker-tmp"
3 啟動(dòng)registry
sudo docker run --name registry -d -p 5000:5000 -v /home/docker_registry:/var/lib/registry --restart=always registry:latest
4 tag鏡像
docker tag redis server1:5000/redis
5 推送保存私有鏡像
docker push server1:5000/redis
5.1 查看推送到私有倉庫的鏡像
$ docker search 10.10.105.71:5000/tonybai/busybox/
Error response from daemon: Unexpected status code 404
但通過v2版本的API,我們可以實(shí)現(xiàn)相同目的:
$curl http://10.10.105.71:5000/v2/_catalog
{"repositories":["tonybai/busybox"]}
在server2(client)上
因?yàn)閐ocker Registry中講到, 如果采用insecure registry的模式,那么所有與Registry交互的主機(jī)上的Docker Daemon都要配置:–insecure-registry選項(xiàng)。除了這個(gè)模式還可以配置證書,在此不作說明
1 配置 -insecure-registry(centos:/etc/sysconfig/docker ubuntu:/etc/default/docker)
# 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"
DOCKER_OPTS="--insecure-registry server1:5000"
# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy="http://127.0.0.1:3128/"
# This is also a handy place to tweak where Docker's temporary files go.
#export TMPDIR="/mnt/bigdrive/docker-tmp"
2 下載
docker pull server1:5000/redis
3 提交推送
docker tag redis server1:5000/redis
docker push server1:5000/redis
參考:
http://www.cnblogs.com/xcloudbiz/articles/5526262.html
到此這篇關(guān)于docker私有庫的搭建實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)docker私有庫搭建內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!