一、检查是否已经配置私有仓库
docker info
# 输出如下
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.10.4
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.17.2
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 4
Running: 4
Paused: 0
Stopped: 0
Images: 5
Server Version: 23.0.4
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
runc version: v1.1.5-0-gf19387a
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
Kernel Version: 4.15.0-210-generic
Operating System: Ubuntu 18.04.6 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.852GiB
Name: ub18
ID: 845c4949-5572-444a-977f-4d7b9ce143b4
Docker Root Dir: /data/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Experimental: false
# 检查此项
Insecure Registries:
178.119.31.7:5000
127.0.0.0/8
Registry Mirrors:
https://qls7cwi7.mirror.aliyuncs.com/
https://docker.mirrors.ustc.edu.cn/
https://registry.docker-cn.com/
Live Restore Enabled: false
Insecure Registries:表示私有仓库地址,本次案例配置的私有仓库地址为 reg.hdu.io
记得看下hosts
后面登录测试可能报错
Error response from daemon: Get "http://reg.hdu.io/v2/": dial tcp: lookup reg.hdu.io: no such host
二、配置私有仓库
2.1 编辑配置文件(不存在则新建)
vim /etc/docker/daemon.json
# 添加配置
"insecure-registries": [
"reg.hdu.io"
]
2.2 配置完成的内容
{
"dns": ["114.114.114.114", "8.8.8.8" ],
"log-driver": "json-file",
"log-opts": {"max-size":"20m", "max-file":"10"},
"registry-mirrors": ["https://qls7cwi7.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn","https://registry.docker-cn.com"],
"data-root": "/data/docker",
"insecure-registries": ["reg.hdu.io"]
}
2.3 重启docker
systemctl daemon-reload
systemctl restart docker.service
2.4 检查是否配置成功
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.10.4
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.17.2
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 4
Running: 4
Paused: 0
Stopped: 0
Images: 5
Server Version: 23.0.4
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 2806fc1057397dbaeefbea0e4e17bddfbd388f38
runc version: v1.1.5-0-gf19387a
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
Kernel Version: 4.15.0-210-generic
Operating System: Ubuntu 18.04.6 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.852GiB
Name: ub18
ID: 845c4949-5572-444a-977f-4d7b9ce143b4
Docker Root Dir: /data/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
reg.hdu.io
127.0.0.0/8
Registry Mirrors:
https://qls7cwi7.mirror.aliyuncs.com/
https://docker.mirrors.ustc.edu.cn/
https://registry.docker-cn.com/
Live Restore Enabled: false
三、将镜像推送至私有仓库
3.1 登录私有仓库
- Harbor
docker login https://reg.hdu.io -u tangsiqi -p 密码
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
3.2 重命名镜像
docker pull elasticsearch
docker tag elasticsearch reg.hdu.io/huayun/thingsultra/elasticsearch:latest
3.3 将镜像推送至私有仓库
docker push reg.hdu.io/huayun/thingsultra/elasticsearch:latest
3.4 检查镜像
- 访问 harbor镜像仓库进行访问