docker搭建私有仓库

docker搭建私有仓库

部署环境:

两台centos7虚拟机,其中一台作为registry
docker:18.06-ce
已经配置好阿里云镜像加速,阿里云镜像加速配置可以参考:[https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors](https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors)

registry节点

首先在registry节点,拉取registry镜像

[root@host1 se-eureka]#  docker pull registry

启动registry镜像服务

[root@host1 se-eureka]#  docker run -itd -v /data/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:latest 

修改daemon.json文件

[root@host1 se-eureka]# vim /etc/docker/daemon.json 
[root@host1 se-eureka]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://jrhfzcbf.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.1.36:5000"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}

重启docker服务

systemctl daemon-reload docker
systemclt restart docker

测试:

[root@host1 se-eureka]# curl http://192.168.1.36:5000/v2/_catalog
{"repositories":[""]}

其他节点

[root@host3 ~]# vim /etc/docker/daemon.json
[root@host3 ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://jrhfzcbf.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.1.36:5000"],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}

重启docker服务

[root@host3 ~]# systemctl daemon-reload docker
[root@host3 ~]# systemctl restart docker

测试:

[root@host1 se-eureka]# docker pull nginx
[root@host1 se-eureka]# docker tag nginx 192.168.1.36:5000/mynginx:v1
[root@host1 se-eureka]# docker push 192.168.1.36:5000/mynginx

然后在另外一台主机上

[root@host2 ~]# docker pull 192.168.1.36:5000/mynginx:v1
v1: Pulling from mynginx
8d691f585fa8: Pull complete 
5b07f4e08ad0: Pull complete 
abc291867bca: Pull complete 
Digest: sha256:f56b43e9913cef097f246d65119df4eda1d61670f7f2ab720831a01f66f6ff9c
Status: Downloaded newer image for 192.168.1.36:5000/mynginx:v1

你可能感兴趣的:(docker搭建私有仓库)