ubuntu

Ubuntu Docker镜像仓库怎么搭建

小樊
42
2025-10-12 02:25:21
栏目: 智能运维

Ubuntu系统搭建Docker镜像仓库(私有)详细步骤

1. 准备环境:安装Docker

在Ubuntu上搭建私有仓库前,需先安装Docker。推荐使用Docker CE(社区版),步骤如下:

2. 拉取官方Registry镜像

Docker官方提供了registry:2镜像(版本2为当前主流),用于快速搭建私有仓库:
docker pull registry:2

3. 运行私有仓库容器

使用docker run命令启动容器,关键参数说明:

完整命令:
docker run -d -p 5000:5000 --name registry -v /opt/docker-registry/data:/var/lib/registry registry:2

4. 配置Docker信任私有仓库

默认情况下,Docker不信任非HTTPS的私有仓库(如本地的localhost:5000)。需修改Docker守护进程配置,添加私有仓库地址到信任列表:

5. 测试私有仓库功能

5.1 标记本地镜像

将本地的hello-world镜像(或其他镜像)标记为私有仓库的地址格式:<私有仓库地址>/<镜像名称>:<标签>。例如:
docker tag hello-world:latest localhost:5000/hello-world:latest

5.2 推送镜像到私有仓库

使用docker push命令将标记后的镜像推送到私有仓库:
docker push localhost:5000/hello-world:latest
若推送成功,终端会显示类似latest: digest: sha256:... size: 1336的信息

5.3 从私有仓库拉取镜像

使用docker pull命令从私有仓库拉取镜像,验证是否可用:
docker pull localhost:5000/hello-world:latest
若拉取成功,说明私有仓库功能正常

5.4 查看仓库中的镜像列表

通过浏览器或curl命令访问私有仓库的API,查看已存储的镜像列表:

注意事项

0
看了该问题的人还看了