镜像私有仓库:registry搭建和使用

1. 实验环境

两台docker主机:

docker主机:192.168.183.189
镜像仓库:192.168.183.188

2. 仓库搭建

docker主机ip:192.168.183.188

2.1 拉取registry镜像

[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
0a6724ff3fcd: Pull complete 
d550a247d74f: Pull complete 
1a938458ca36: Pull complete 
acd758c36fc9: Pull complete 
9af6d68b484a: Pull complete 
Digest: sha256:d5459fcb27aecc752520df4b492b08358a1912fcdfa454f7d2101d4b09991daa
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@localhost ~]# 

2.2 基于registry镜像运行registry容器

[root@localhost ~]# docker run --name registry -d -p 5000:5000 --restart always registry
5a5bd6f0b415c53d0668dff2013dbc4ab347f7ae06c92e5d2f0a3e1805cc6e43

2.3 查看运行的registry容器

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
5a5bd6f0b415        registry            "/entrypoint.sh /etc…"   33 seconds ago      Up 33 seconds       0.0.0.0:5000->5000/tcp   registry
[root@localhost ~]# 


3. 配置docker主机:192.168.183.189

3.1 修改docker的配置文件

配置私库地址insecure-registries和端口号

[root@localhost ~]# vim /etc/docker/daemon.json 
[root@localhost ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://q3u0qv3z.mirror.aliyuncs.com"],
   "insecure-registries":["192.168.153.188:5000"]
}
[root@localhost ~]# 

3.2 重启docker

[root@localhost ~]# systemctl restart docker

3.3 给本地镜像打标签成标准格式

[root@localhost ~]# docker tag mysql:5.7 192.168.153.188:5000/mysql:5.7

3.4 推送本地镜像到registry仓库中

推送成功

 [root@localhost ~]# docker push 192.168.153.188:5000/mysql:5.7
The push refers to repository [192.168.153.188:5000/mysql]
6c316520569e: Pushed 
f6bef35c0067: Pushed 
a6ea401b7864: Pushed 
94bd7d7999de: Pushed 
8df989cb6670: Pushed 
f358b00d8ce7: Pushed 
ae39983d39c4: Pushed 
b55e8d7c5659: Pushed 
e8fd11b2289c: Pushed 
e9affce9cbe8: Pushed 
316393412e04: Pushed 
d0f104dc0a1f: Pushed 
5.7: digest: sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514 size: 2829
[root@localhost ~]# 

3.5 删除本地mysql镜像

[root@localhost ~]# docker rmi mysql:5.7
Untagged: mysql:5.7
[root@localhost ~]# docker rmi -f 192.168.153.188:5000/mysql:5.7
Untagged: 192.168.153.188:5000/mysql:5.7
Untagged: 192.168.153.188:5000/mysql@sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514
Deleted: sha256:a4cc8ac4386762cd0e8e3d9c7ca4ba6e84898aff2995762baaf47aef8cbaf063
[root@localhost ~]# 

3.6 从registry中拉取镜像测试

 [root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@localhost ~]# docker pull 192.168.153.188:5000/mysql:5.7
5.7: Pulling from mysql
bf5952930446: Already exists 
8254623a9871: Already exists 
938e3e06dac4: Already exists 
ea28ebf28884: Already exists 
f3cef38785c2: Already exists 
894f9792565a: Already exists 
1d8a57523420: Already exists 
5f09bf1d31c1: Already exists 
1b6ff254abe7: Already exists 
74310a0bf42d: Already exists 
d398726627fd: Already exists 
784aa83a1bf2: Already exists 
Digest: sha256:b9c1994c82f94c13370b0d79efa703616a538bf55fcb7e0923892d5a5e753514
Status: Downloaded newer image for 192.168.153.188:5000/mysql:5.7
192.168.153.188:5000/mysql:5.7
[root@localhost ~]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
192.168.153.188:5000/mysql   5.7                 a4cc8ac43867        3 months ago        448MB
[root@localhost ~]# 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
当然可以!下面是一个简单的私有Docker镜像仓库搭建教程: 1. 安装DockerDocker Compose:首先,确保你的主机上已经安装了DockerDocker Compose。你可以根据你的操作系统文档中的步骤进行安装。 2. 创建一个目录:在你的主机上创建一个目录来存储你的私有镜像仓库的数据。例如,你可以创建一个名为`docker-registry`的目录。 3. 编写docker-compose.yml文件:在你的`docker-registry`目录下创建一个名为`docker-compose.yml`的文件,并添加以下内容: ```yaml version: '3.8' services: registry: restart: always image: registry:2 ports: - 5000:5000 volumes: - ./data:/var/lib/registry ``` 这将启动一个名为`registry`的容器,使用Docker官方提供的`registry:2`镜像。容器将通过`5000`端口对外提供服务,并将数据存储在`./data`目录中。 4. 启动私有镜像仓库:在你的`docker-registry`目录下运行以下命令启动私有镜像仓库: ```bash docker-compose up -d ``` 这将在后台启动私有镜像仓库容器,并将其绑定到`5000`端口。 5. 配置客户端:现在你的私有镜像仓库已经启动,你可以配置Docker客户端来使用它。在你的客户端主机上执行以下命令: ```bash echo "{ \"insecure-registries\": { \"localhost:5000\": {} } }" > /etc/docker/daemon.json sudo systemctl restart docker ``` 这将在`/etc/docker/daemon.json`文件中添加一个配置,以允许Docker客户端信任私有镜像仓库的地址。 现在,你就可以使用私有镜像仓库了。你可以使用`docker push`命令将本地构建的镜像推送到私有仓库使用`docker pull`命令从私有仓库拉取镜像。 希望这个教程对你有所帮助!如果你有任何其他问题,请随时提问。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值