docker 連接私有倉庫,并向私有倉庫推送鏡像
一、檢查是否已經(jīng)配置私有倉庫
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
- 出現(xiàn) Login Succeeded 則說明登錄成功
3.2 重命名鏡像(我們自己的工程推送构资,項目為basic抽诉,即,鏡像名應為:192.168.80.135/basic/openjdk:8)
docker tag openjdk:8 192.168.80.135/basic/openjdk:8
- 命名規(guī)則:私有倉庫ip/倉庫分類/鏡像名:版本
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 檢查鏡像