docker学习(四)之私有仓库

1、Docker私有仓库

Docker官方的Docker hub是一个用于管理公共镜像的仓库,我们可以从上面拉取镜像到本地,也可以把我们自己的镜像推送上去。但是,有时候我们的服务器无法访问互联网,或者你不希望将自己镜像放到公网当中,那么我们就需要搭建自己的私有仓库来存储和管理自己的镜像。

2、搭建私有仓库

  1. 拉取私有仓库镜像
[root@docker ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
486039affc0a: Pull complete
ba51a3b098e6: Pull complete
8bb4c43d6c8e: Pull complete
6f5f453e5f2d: Pull complete
42bc10b72f42: Pull complete
Digest: sha256:7d081088e4bfd632a88e3f3bcd9e007ef44a796fddfe3261407a3f9f04abe1e7
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest

  1. 启动私有仓库容器
[root@docker ~]# docker run -id --name=registry -p 5000:5000 registry
429ab425356c6838331425206f25db512cdc65d97d0179be45455112dc4a47f0
[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
429ab425356c        registry            "/entrypoint.sh /etc…"   3 seconds ago       Up 2 seconds        0.0.0.0:5000->5000/tcp   registry

  1. 打开浏览器,输入地址http://ip:5000/v2/_catalog,看到{“repositories”:[]}表示私有仓库搭建成功
    在这里插入图片描述
  2. 修改deamon.json,添加一个key,用于让docker信任私有仓库地址;注意私有仓库服务器ip修改为自己私有仓库服务器真实ip
[root@docker ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://bdxzq1r4.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.8.20:5000"]
}

  1. 重启docker服务
[root@docker ~]# systemctl restart docker
[root@docker ~]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-04-17 21:55:27 CST; 3s ago
     Docs: https://docs.docker.com
 Main PID: 2985 (dockerd)
    Tasks: 10
   Memory: 39.7M
   CGroup: /system.slice/docker.service
           └─2985 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont...

Apr 17 21:55:26 docker dockerd[2985]: time="2020-04-17T21:55:26.059187414+0...2"
Apr 17 21:55:26 docker dockerd[2985]: time="2020-04-17T21:55:26.081255183+0...d"
Apr 17 21:55:26 docker dockerd[2985]: time="2020-04-17T21:55:26.081366583+0...e"
Apr 17 21:55:26 docker dockerd[2985]: time="2020-04-17T21:55:26.081877593+0...."
Apr 17 21:55:27 docker dockerd[2985]: time="2020-04-17T21:55:27.229286819+0...s"
Apr 17 21:55:27 docker dockerd[2985]: time="2020-04-17T21:55:27.611014604+0...."
Apr 17 21:55:27 docker dockerd[2985]: time="2020-04-17T21:55:27.637420519+0....8
Apr 17 21:55:27 docker dockerd[2985]: time="2020-04-17T21:55:27.637495129+0...n"
Apr 17 21:55:27 docker dockerd[2985]: time="2020-04-17T21:55:27.676661062+0...k"
Apr 17 21:55:27 docker systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

3、上传镜像到私有仓库

  1. 标记镜像为私有仓库的镜像
    把centos标记到私有仓库
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello               v1.0                1eee8113dc65        22 hours ago        933MB
new_tomcat          v1.0                5b82f557292f        24 hours ago        529MB
tomcat              latest              6ab907c973d2        7 days ago          528MB
python              3.8                 d47898c6f4b0        2 weeks ago         933MB
redis               latest              4cdbec704e47        2 weeks ago         98.2MB
nginx               latest              ed21b7a8aee9        2 weeks ago         127MB
mysql               latest              9228ee8bac7a        2 weeks ago         547MB
registry            latest              708bc6af7e5e        2 months ago        25.8MB
centos              latest              470671670cac        3 months ago        237MB
[root@docker ~]# docker tag centos:latest 192.168.8.20:5000/centos:latest
[root@docker ~]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
hello                      v1.0                1eee8113dc65        22 hours ago        933MB
new_tomcat                 v1.0                5b82f557292f        24 hours ago        529MB
tomcat                     latest              6ab907c973d2        7 days ago          528MB
python                     3.8                 d47898c6f4b0        2 weeks ago         933MB
redis                      latest              4cdbec704e47        2 weeks ago         98.2MB
nginx                      latest              ed21b7a8aee9        2 weeks ago         127MB
mysql                      latest              9228ee8bac7a        2 weeks ago         547MB
registry                   latest              708bc6af7e5e        2 months ago        25.8MB
192.168.8.20:5000/centos   latest              470671670cac        3 months ago        237MB
centos                     latest              470671670cac        3 months ago        237MB

  1. 上传标记的镜像
    如果registry容器处于关闭状态,需先启动以下
[root@docker ~]# docker start registry
registry

上传centos:latest

[root@docker ~]# docker push 192.168.8.20:5000/centos
The push refers to repository [192.168.8.20:5000/centos]
0683de282177: Pushed
latest: digest: sha256:9e0c275e0bcb495773b10a18e499985d782810e47b4fce076422acb4bc3da3dd size: 529
  1. 验证上传结果
    在这里插入图片描述
    centos已上传成功

4、拉取私有仓库镜像到本地

初始的docker images

[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello               v1.0                1eee8113dc65        22 hours ago        933MB
new_tomcat          v1.0                5b82f557292f        24 hours ago        529MB
tomcat              latest              6ab907c973d2        7 days ago          528MB
python              3.8                 d47898c6f4b0        2 weeks ago         933MB
redis               latest              4cdbec704e47        2 weeks ago         98.2MB
nginx               latest              ed21b7a8aee9        2 weeks ago         127MB
mysql               latest              9228ee8bac7a        2 weeks ago         547MB
registry            latest              708bc6af7e5e        2 months ago        25.8MB
centos              latest              470671670cac        3 months ago        237MB

拉取私有仓库镜像

[root@docker ~]# docker pull 192.168.8.20:5000/centos
Using default tag: latest
latest: Pulling from centos
Digest: sha256:9e0c275e0bcb495773b10a18e499985d782810e47b4fce076422acb4bc3da3dd
Status: Downloaded newer image for 192.168.8.20:5000/centos:latest
192.168.8.20:5000/centos:latest

查看docker images

[root@docker ~]# docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
hello                      v1.0                1eee8113dc65        22 hours ago        933MB
new_tomcat                 v1.0                5b82f557292f        24 hours ago        529MB
tomcat                     latest              6ab907c973d2        7 days ago          528MB
python                     3.8                 d47898c6f4b0        2 weeks ago         933MB
redis                      latest              4cdbec704e47        2 weeks ago         98.2MB
nginx                      latest              ed21b7a8aee9        2 weeks ago         127MB
mysql                      latest              9228ee8bac7a        2 weeks ago         547MB
registry                   latest              708bc6af7e5e        2 months ago        25.8MB
192.168.8.20:5000/centos   latest              470671670cac        3 months ago        237MB
centos                     latest              470671670cac        3 months ago        237MB

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值