环境:CentOS7.6,DockerCE 18.09.3,
说明:192.168.3.11搭建为Docker私有仓库,192.168.3.12位客户端
Docker安装:(两台server同样操作)
- sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- sudo yum makecache fast
- sudo yum -y install docker-ce
- sudo service docker start
查看docker版本:
[root@localhost ~]# docker version
Client:
Version: 18.09.8
API version: 1.39
Go version: go1.10.8
Git commit: 0dd43dd87f
Built: Wed Jul 17 17:40:31 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.8
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 0dd43dd
Built: Wed Jul 17 17:10:42 2019
OS/Arch: linux/amd64
Experimental: false
配置Docker仓库:(192.168.3.11)
[root@localhost ~]# docker pull registry
[root@localhost ~]# docker pull busybox
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry=192.168.3.11:5000(在Docker system启动脚本里编辑启动Command以支持http访问,默认为https访问)
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
~~[root@localhost ~]# docker run -d -p 5000:5000 registry(运行registry image,以确认registry镜像存储位置,可忽略不做)
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
474e7eef5335 registry "/entrypoint.sh /etc…" 6 seconds ago Up 4 seconds 0.0.0.0:5000->5000/tcp infallible_nobel
[root@localhost ~]# docker exec -it 474e sh
/ # find / -name registry
/bin/registry
/etc/docker/registry
/var/lib/registry~~
[root@localhost ~]# docker run -d -p 5000:5000 -v /opt/registry:/var/lib/registry registry(后台运行registry image 并挂载到本地/opt/registry位置)
[root@localhost ~]# ls /opt/registry/(查看本地挂载镜像位置目录为空,为后续验证仓库搭建是否成功做铺垫)
上传镜像到本地docker仓库:
[root@localhost ~]# docker tag busybox:latest 192.168.3.11:5000/busybox:latest(更改busybox镜像tag标签,默认为docker.io/busyboxlatest,docker.io可省略)
[root@localhost ~]# docker push 192.168.3.11:5000/busybox(上传镜像到本地仓库)
The push refers to repository [192.168.3.11:5000/busybox]
0d315111b484: Pushed
latest: digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649 size: 527
[root@localhost ~]# tree /opt/registry/
测试本地docker仓库:(以下操作步骤在192.168.3.12操作)
如果直接操作会报如下错误:
[root@localhost ~]# docker pull 192.168.3.11:5000/busybox:latest
Error response from daemon: Get https://192.168.3.11:5000/v2/: http: server gave HTTP response to HTTPS client(未添加http仓库源)
修改配置:
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd --insecure-registry=192.168.3.11:5000
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
拉取镜像:
[root@localhost ~]# docker pull 192.168.3.11:5000/busybox
Using default tag: latest
latest: Pulling from busybox
ee153a04d683: Pull complete
Digest: sha256:895ab622e92e18d6b461d671081757af7dbaa3b00e3e28e12505af7817f73649
Status: Downloaded newer image for 192.168.3.11:5000/busybox:latest
至此,Docker私有仓库搭建OK!(第一次写博客,看着别扭的话,忘见谅啊,haha~)