docker已经足够火了,试想每次部署都要飘洋过海去docker官方仓库拉镜像,肯定受不了,所以必须搭建内网私有docker仓库,充分利用高速内网带宽。
1、安装docker
yum install docker
2、开启docker服务
systemctl enable docker systemctl start docker
3、获取docker镜像
docker pull centos
上面是从docker官方仓库获取centos镜像,速度很慢。
也可以从别的地方获取,比如
docker pull index.tenxcloud.com/tenxcloud/centos
4、安装并启用 docker-distribution
yum install docker-distribution systemctl enable docker-distribution systemctl start docker-distribution
可以根据需要修改docker-distribution的配置文件 /etc/docker-distribution/registry/config.yml
比如端口(默认5000),镜像存储路径(默认/var/lib/registry)
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:latest
7、把镜像发布到仓库中
docker push localhost:5000/centos:latest
8、删除本地镜像
docker rmi index.tenxcloud.com/tenxcloud/centos docker rmi localhost:5000/centos docker images
9、从仓库中获取镜像
docker pull localhost:5000/centos:latest
10、查看刚刚本地拉取的镜像
docker images
11、修改docker配置文件,默认使用内网仓库
修改文件/etc/sysconfig/docker
#添加内网仓库 ADD_REGISTRY='--add-registry localhost:5000' #禁用官方仓库docker.io(可选) BLOCK_REGISTRY='--block-registry docker.io'