您的位置:首页 > 运维架构 > Docker

CentOS 7 搭建docker仓库

2017-02-13 18:32 246 查看

docker已经足够火了,试想每次部署都要飘洋过海去docker官方仓库拉镜像,肯定受不了,

即使有了国内镜像,然而,频繁的docker部署,依然会让网速捉襟见肘。

所以必须搭建内网私有docker仓库,充分利用高速内网带宽。


与vmware habor相比,docker distrbution 胜在小巧简单。


1、安装dockeryum install docker2、开启docker服务systemctl enable docker systemctl start docker3、获取docker镜像docker pull centos上面是从docker官方仓库获取centos镜像,速度很慢。

也可以从别的地方获取,比如docker pull index.tenxcloud.com/tenxcloud/centos4、安装并启用 docker-distributionyum install docker-distribution systemctl enable docker-distribution systemctl start docker-distribution可以根据需要修改docker-distribution的配置文件 /etc/docker-distribution/registry/config.yml

比如端口(默认5000),镜像存储路径(默认/var/lib/registry)


如果需要监听在80端口,可以用iptables转发实现。iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 5000

5、查看本地镜像docker images示例输出如下:

# docker images
REPOSITORY                   TAG   IMAGE ID     CREATED     SIZE
index.tenxcloud.com/tenxcloud/centos  latest 6e7516266d96  9 months ago  309.9 MB

6、给本地docker镜像打标签docker tag 6e7516266d96 localhost:5000/centos:latest7、把镜像发布到仓库中docker push localhost:5000/centos:latest8、删除本地镜像docker rmi index.tenxcloud.com/tenxcloud/centos docker rmi localhost:5000/centos docker images9、从仓库中获取镜像docker pull localhost:5000/centos:latest10、查看刚刚本地拉取的镜像docker images

11、修改docker配置文件,默认使用内网仓库

修改文件/etc/sysconfig/docker

#添加内网仓库
ADD_REGISTRY='--add-registry localhost:5000'
#禁用官方仓库docker.io(可选)
BLOCK_REGISTRY='--block-registry docker.io'

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: