docker 连接私有仓库,并向私有仓库推送镜像
一、检查是否已经配置私有仓库
docker info
# 输出如下
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-862.14.4.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 31.24GiB
Name: gxjsyjzx001
ID: SVUW:JJ64:IOHE:2NM3:L7E7:ZO5Z:2E4O:OQUO:XW7O:IZII:HWCW:GCNW
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
# 检查此项
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://pak31uuv.mirror.aliyuncs.com/
https://registry.docker-cn.com/
Live Restore Enabled: false
Product License: Community Engine
- Insecure Registries:表示私有仓库地址,本次案例配置的私有仓库地址为 192.168.80.135
二、配置私有仓库
2.1 编辑配置文件(不存在则新建)
vim /etc/docker/daemon.json
# 添加配置
"insecure-registries": [
"192.168.80.135"
]
2.2 配置完成的内容
{
"registry-mirrors": [
"https://pak31uuv.mirror.aliyuncs.com",
"https://registry.docker-cn.com"
],
"insecure-registries": [
"10.1.119.12"
]
}
- registry-mirrors : 配置镜像加速服务(本次案例是使用的tanxingsong的阿里云镜像加速服务,读者在配置的时候,可以自行去阿里云申请免费镜像加速服务,如果嫌麻烦,也可以先用着笔者的镜像加速)
- insecure-registries : 配置远程仓库
2.3 重启docker
systemctl restart docker
2.4 检查是否配置成功
docker info
# 输出如下
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-862.14.4.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 31.24GiB
Name: gxjsyjzx001
ID: SVUW:JJ64:IOHE:2NM3:L7E7:ZO5Z:2E4O:OQUO:XW7O:IZII:HWCW:GCNW
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
# 如果存在 192.168.80.135 ,则说明配置成功
Insecure Registries:
192.168.80.135
127.0.0.0/8
Registry Mirrors:
https://pak31uuv.mirror.aliyuncs.com/
https://registry.docker-cn.com/
Live Restore Enabled: false
Product License: Community Engine
三、将镜像推送至私有仓库
3.1 登录私有仓库
docker login 192.168.80.135 -u admin -p Harbor12345
# 输出如下
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
- 出现 Login Succeeded 则说明登录成功
3.2 重命名镜像(我们自己的工程推送,项目为basic,即,镜像名应为:192.168.80.135/basic/openjdk:8)
docker tag openjdk:8 192.168.80.135/basic/openjdk:8
3.3 将镜像推送至私有仓库
docker push 192.168.80.135/basic/openjdk:8
# 输出如下
The push refers to repository [10.1.119.12/basic/openjdk]
2ee490fbc316: Layer already exists
b18043518924: Layer already exists
9a11244a7e74: Layer already exists
5f3a5adb8e97: Layer already exists
73bfa217d66f: Layer already exists
91ecdd7165d3: Layer already exists
e4b20fcc48f4: Layer already exists
8: digest: sha256:1aa55a21176b17bc276dc1b545872cb1590edf632c179fc3297e5e48447d1b24 size: 1795
3.4 检查镜像