1、環境準備
ip
docker倉庫機 10.5.0.50
docker客戶機 10.5.0.51linux
關閉防火牆
systemctl stop firewalld.service
systemctl disable firewalld.servicenginx
關閉本地selinux防火牆
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux
getenforce 0docker
2、搭建vim
1.搭建倉庫 registry
docker pull regsitycentos
2.基於私有倉庫鏡像運行容器api
docker run -d -p 5000:5000 --privileged=true --restart=always -v /opt/registry:/tmp/registry registry bash
3.訪問私有倉庫curl
網上都用這個curl 127.0.0.1:5000/v1/search,可是報404 page not found,後查證是v1版本的api查看方式,咱們如今的版本是v2,因此用以下方法查看:ide
curl -X GET http://10.5.0.50:5000/v2/_catalog
{"repositories":[]} #私有倉庫爲空,沒有提交新鏡像到倉庫中url
4.爲基礎鏡像打個標籤
根據 images id 創建 tag
docker tag a374fd62f97f 10.5.0.50:5000/centos
5.改Docker配置文件指定私有倉庫url
vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 10.5.0.50:5000'
systemctl restart docker
docker push 10.5.0.50:5000/centos
7.查看私有倉庫是否存在對應的鏡像
root@localhost ~
curl -X GET http://10.5.0.50:5000/v2/_catalog
{"repositories":["centos","nginx"]}
curl -X GET http://10.5.0.50:5000/v2/centos/tags/list
{"name":"centos","tags":["latest"]}
3、在docker客戶機驗證
1.修改Docker配置文件
vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 10.5.0.50:5000'
systemctl restart docker
2.從私有倉庫中下載已有的鏡像
docker pull 10.5.0.50:5000/centos
Using default tag: latest
Trying to pull repository 10.5.0.50:5000/centos ...
latest: Pulling from 10.5.0.50:5000/centos
Digest: sha256:fd9058a6149809b2f4725bb4461294ceebb59e587435f3509c2c8dcc9ee1d5b4
Status: Downloaded newer image for 10.5.0.50:5000/centos:latest
查看
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.5.0.50:5000/centos latest a374fd62f97f 11 weeks ago 194.5 MB
docker.io/centos 6.8 a374fd62f97f 11 weeks ago 194.5 MB
運行
docker run -itd 10.5.0.50:5000/centos
2da2c1e9e70146b71a68f829e89756664f1e2a67abf369baac524c65deb25
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2da2c1e9e 10.5.0.50:5000/centos "/bin/bash" About a minute ago Up About a minute thirsty_elion
自此,docker本地倉庫搭建完成。。。