8

【笔记】搭建私有Docker镜像仓库

 2 years ago
source link: https://feiju12138.github.io/2022/10/31/%E6%90%AD%E5%BB%BA%E7%A7%81%E6%9C%89Docker%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

搭建私有Docker镜像仓库学习笔记

搭建没有GUI界面的仓库

  • 通过Docker官方提供的镜像搭建镜像仓库
docker run --name registry --restart=always -p 5000:5000 -d -v registry-data:/var/lib/registry registry

搭建有GUI界面的仓库

  • 通过Docker官方提供的镜像以及第三方开发者开发的GUI界面组合,实现带GUI界面的仓库搭建

docker-compose.yml

version: "3.0"

services:
registry:
image: registry
volumes:
- ./registary-data:/var/lib/registry
ui:
image: joxit/docker-registry-ui:static
ports:
- 8080:80
environment:
- REGISTRY_TITLE=私有仓库标题
- REGISTRY_URL=http://registry:5000
depends_on:
- registry

配置Docker的信任地址

  • 配置从UI容器访问仓库容器的信任地址,访问仓库地址时,默认Docker只信任https,如果没有https,需要配置http

insecure-registries:配置仓库容器的IP地址和端口号(实际上就是宿主机的IP地址,端口号默认为5000)

/etc/docker/daemon.json

{
"registry-mirrors": ["https://n0dwemtq.mirror.aliyuncs.com"],
"insecure-registries": ["http://xx.xx.xx.xx:5000"]
}
  • 配置完成后重载配置并重启Docker
systemctl daemon-reload
systemctl restart docker

从本机推送镜像到仓库

重新标记tag

  • 发起推送之前要先通过docker tag命令,将镜像重新标记tag,必须将推送的仓库地址作为前缀

<name_local>:<version_local>:本机上镜像的名称和标签
<ip_ui>:<port_ui>:如果搭建的是有GUI的仓库,那么需要指定UI容器的IP地址和端口
<name_remote>:<version_remote>:发送到仓库时镜像的名称和标签,可以与本机上镜像的名称和标签相同

docker tag <name_local>:<version_local> <ip_ui>:<port_ui>/<name_remote>:<version_remote>
  • 重新标记tag完成后,才可以发起推送
docker push <ip_ui>:<port_ui>/<name_remote>:<version_remote>

从仓库拉取镜像到本机

docker pull <ip_ui>:<port_ui>/<name_remote>:<version_remote>

哔哩哔哩——黑马程序员


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK