本文共 1888 字,大约阅读时间需要 6 分钟。
一、环境准备
ipdocker仓库机 10.5.0.50docker客户机 10.5.0.51关闭防火墙
systemctl stop firewalld.servicesystemctl disable firewalld.service关闭本地selinux防火墙
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux getenforce 0二、搭建
1.搭建仓库 registry
docker pull regsity2.基于私有仓库镜像运行容器
docker run -d -p 5000:5000 --privileged=true --restart=always -v /opt/registry:/tmp/registry registry
3.访问私有仓库
网上都用这个curl 127.0.0.1:5000/v1/search,但是报404 page not found,后查证是v1版本的api查看方式,我们现在的版本是v2,所以用如下方法查看:
curl -X GET
{"repositories":[]} #私有仓库为空,没有提交新镜像到仓库中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 dockerdocker push 10.5.0.50:5000/centos
7.查看私有仓库是否存在对应的镜像
root@localhost ~
curl -X GET {"repositories":["centos","nginx"]}curl -X GET {"name":"centos","tags":["latest"]}三、在docker客户机验证
1.修改Docker配置文件vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --insecure-registry 10.5.0.50:5000'systemctl restart docker2.从私有仓库中下载已有的镜像
docker pull 10.5.0.50:5000/centos
Using default tag: latestTrying to pull repository 10.5.0.50:5000/centos ... latest: Pulling from 10.5.0.50:5000/centosDigest: sha256:fd9058a6149809b2f4725bb4461294ceebb59e587435f3509c2c8dcc9ee1d5b4Status: Downloaded newer image for 10.5.0.50:5000/centos:latest查看
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE10.5.0.50:5000/centos latest a374fd62f97f 11 weeks ago 194.5 MBdocker.io/centos 6.8 a374fd62f97f 11 weeks ago 194.5 MB运行
docker run -itd 10.5.0.50:5000/centos
2da2c1e9e70146b71a68f829e89756664f1e2a67abf369baac524c65deb25docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES2da2c1e9e 10.5.0.50:5000/centos "/bin/bash" About a minute ago Up About a minute thirsty_elion自此,docker本地仓库搭建完成。。。
转载于:https://blog.51cto.com/chentianwang/2089952