docker镜像仓库registry
在生产中很多用harbor,有时候环境规模 很小 可以用轻量级的registry私有镜像仓库,本文示范搭建并推送镜像
本次用ubuntu20.4进行搭建
首先确保环境干净,移除之前安装的docker环境
apt-get remove docker docker-engine docker.io containerd runc
安装所必须要的依赖包
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
安装docker 前需要添加密钥,这里使用阿里云
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
添加安装docker仓库
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
安装docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
验证安装
root@ubuntu:/etc/docker# sudo docker pull hello-world
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": read tcp 10.0.0.5:52478->98.85.153.80:443: read: connection reset by peer
这里发现报错 拉取不到容器,配置加速镜像后同时发现docker掉线
root@ubuntu:/etc/docker# systemctl restart docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
检查后发现需要docker镜像加速,需要配置
root@ubuntu:/etc/docker# tee /etc/docker/daemon.json <<-'EOF'
> {
> "registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
> }
> EOF
{
"registry-mirrors": ["https://si7y70hh.mirror.aliyuncs.com"]
}
root@ubuntu:/etc/docker#
配置文档后发现没有作用,通过搜索尝试发现使用下图中的可以
root@ubuntu:/etc/docker# vim daemon.json
root@ubuntu:/etc/docker# systemctl start docker
root@ubuntu:/etc/docker# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:bfbb0cc14f13f9ed1ae86abc2b9f11181dc50d779807ed3a3c5e55a6936dbdd5
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
root@ubuntu:/etc/docker# cat daemon.json
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://docker-0.unsee.tech",
"https://hub.rat.dev"
]
}
拉去registry文件,启动仓库,推送镜像,查看镜像
root@ubuntu:/etc/docker# docker run -itd -p 5000:5000 --name registry --restart=always registry:2.7.1
Unable to find image 'registry:2.7.1' locally
2.7.1: Pulling from library/registry
79e9f2f55bf5: Pull complete
0d96da54f60b: Pull complete
5b27040df4a2: Pull complete
e2ead8259a04: Pull complete
3790aef225b9: Pull complete
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:2.7.1
6d24f00899e80ac4bb37204c2c8ee1b960ef467a906a288f092d621f2420f8f3
root@ubuntu:/etc/docker#
root@ubuntu:/etc/docker# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest b52e0b094bc0 4 weeks ago 192MB
registry 2.7.1 b8604a3fe854 3 years ago 26.2MB
root@ubuntu:/etc/docker# docker run -itd -p 5000:5000 --name registry --restart=always registry:2.7.1^C
root@ubuntu:/etc/docker# docker tag nginx:latest 10.0.0.5:5000/nginx:latest
root@ubuntu:/etc/docker# docker push 10.0.0.5:5000/nginx:latest
The push refers to repository [10.0.0.5:5000/nginx]
55e9644f21c3: Pushed
7d22e2347c12: Pushed
f6d5815f290e: Pushed
791f0a07985c: Pushed
cabea05c000e: Pushed
c68632c455ae: Pushed
5f1ee22ffb5e: Pushed
latest: digest: sha256:b7f8d15543a82805cfa01884032133e78bd839f5bb21ad41e235552ed04a5657 size: 1778
root@ubuntu:/etc/docker# curl -X GET http://10.0.0.5:5000/v2/_catalog
{"repositories":["nginx"]}
root@ubuntu:/etc/docker#
root@ubuntu:/etc/docker# cat daemon.json
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://docker-0.unsee.tech",
"https://hub.rat.dev"
],
"insecure-registries": [
"10.0.0.5:5000"
],
"data-root": "/app/registry"
}