美文网首页【原创】Docker实战系列
Docker管理-构建私有Registry

Docker管理-构建私有Registry

作者: 复苏的兵马俑 | 来源:发表于2020-04-24 15:12 被阅读0次

1、拉取Registry镜像

[root@Server ~]# docker image ls -a
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ubuntu                  20.04               1d622ef86b13        5 hours ago         73.9MB
nginx                   1.17.10             e791337790a6        6 days ago          127MB
httpd                   2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3   2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
centos                  8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server   latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker image pull registry:2.7.1
2.7.1: 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:2.7.1
docker.io/library/registry:2.7.1
[root@Server ~]# docker image ls -a
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ubuntu                  20.04               1d622ef86b13        5 hours ago         73.9MB
nginx                   1.17.10             e791337790a6        6 days ago          127MB
httpd                   2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3   2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                2.7.1               708bc6af7e5e        3 months ago        25.8MB
centos                  8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server   latest              8cc13133f6ed        3 months ago        49.7MB

2、启动Registry容器

[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                                   NAMES
2cbebbcb3a64        centos:8.1.1911                 "/bin/bash"              29 hours ago        Up 5 hours          0.0.0.0:8004->80/tcp                                    vscodeweb
266b03596bdf        continuumio/anaconda3:2020.02   "/bin/bash"              40 hours ago        Up 31 hours         0.0.0.0:8003->8888/tcp                                  condasrv
b573bedbb67c        elleflorio/svn-server:latest    "/init"                  2 days ago          Up 31 hours         443/tcp, 0.0.0.0:3690->3690/tcp, 0.0.0.0:8001->80/tcp   svnsrv
bf9d05430205        httpd:2.4.43                    "httpd-foreground"       2 days ago          Up 31 hours         0.0.0.0:8002->80/tcp                                    apachesrv
7a5b653ef143        nginx:1.17.10                   "nginx -g 'daemon of…"   2 days ago          Up 31 hours         0.0.0.0:8000->80/tcp                                    nginxsrv
[root@Server ~]# docker container run -d -p 8005:5000 --restart=always --name registry -v /data/registry:/var/lib/registry registry:2.7.1
69a577124676d556ddbe371deba7af86f13f91cd0bfc7b315dffacb4b7d3b9fb
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                                   NAMES
69a577124676        registry:2.7.1                  "/entrypoint.sh /etc…"   6 seconds ago       Up 5 seconds        0.0.0.0:8005->5000/tcp                                  registry
2cbebbcb3a64        centos:8.1.1911                 "/bin/bash"              30 hours ago        Up 5 hours          0.0.0.0:8004->80/tcp                                    vscodeweb
266b03596bdf        continuumio/anaconda3:2020.02   "/bin/bash"              40 hours ago        Up 31 hours         0.0.0.0:8003->8888/tcp                                  condasrv
b573bedbb67c        elleflorio/svn-server:latest    "/init"                  2 days ago          Up 31 hours         443/tcp, 0.0.0.0:3690->3690/tcp, 0.0.0.0:8001->80/tcp   svnsrv
bf9d05430205        httpd:2.4.43                    "httpd-foreground"       2 days ago          Up 31 hours         0.0.0.0:8002->80/tcp                                    apachesrv
7a5b653ef143        nginx:1.17.10                   "nginx -g 'daemon of…"   2 days ago          Up 31 hours         0.0.0.0:8000->80/tcp                                    nginxsrv

3、修改配置文件

[root@Server ~]# vi /etc/docker/daemon.json
{
    "registry-mirrors": [
        "https://uoggbpok.mirror.aliyuncs.com",
        "https://68rmyzg7.mirror.aliyuncs.com",
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.mirrors.ustc.edu.cn",
        "https://registry.docker-cn.com"
    ],
    "insecure-registries": ["172.17.0.1:8005"]
}
[root@Server ~]# systemctl restart docker

4、上传镜像到registry

[root@Server ~]# docker image ls -a
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ubuntu                  20.04               1d622ef86b13        6 hours ago         73.9MB
nginx                   1.17.10             e791337790a6        6 days ago          127MB
httpd                   2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3   2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                2.7.1               708bc6af7e5e        3 months ago        25.8MB
centos                  8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server   latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker tag centos:8.1.1911 172.17.0.1:8005/kevin1228/centos:8.1.1911
[root@Server ~]# docker image ls -a
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
ubuntu                             20.04               1d622ef86b13        6 hours ago         73.9MB
nginx                              1.17.10             e791337790a6        6 days ago          127MB
httpd                              2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3              2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                           2.7.1               708bc6af7e5e        3 months ago        25.8MB
172.17.0.1:8005/kevin1228/centos   8.1.1911            470671670cac        3 months ago        237MB
centos                             8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server              latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker image push 172.17.0.1:8005/kevin1228/centos:8.1.1911
The push refers to repository [172.17.0.1:8005/kevin1228/centos]
0683de282177: Pushed
8.1.1911: digest: sha256:9e0c275e0bcb495773b10a18e499985d782810e47b4fce076422acb4bc3da3dd size: 529

5、从registry拉取镜像

[root@Server ~]# docker image ls -a
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ubuntu                  20.04               1d622ef86b13        6 hours ago         73.9MB
nginx                   1.17.10             e791337790a6        6 days ago          127MB
httpd                   2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3   2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                2.7.1               708bc6af7e5e        3 months ago        25.8MB
centos                  8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server   latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker image pull 172.17.0.1:8005/kevin1228/centos:8.1.1911
8.1.1911: Pulling from kevin1228/centos
Digest: sha256:9e0c275e0bcb495773b10a18e499985d782810e47b4fce076422acb4bc3da3dd
Status: Downloaded newer image for 172.17.0.1:8005/kevin1228/centos:8.1.1911
172.17.0.1:8005/kevin1228/centos:8.1.1911
[root@Server ~]# docker image ls -a
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
ubuntu                             20.04               1d622ef86b13        6 hours ago         73.9MB
nginx                              1.17.10             e791337790a6        6 days ago          127MB
httpd                              2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3              2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                           2.7.1               708bc6af7e5e        3 months ago        25.8MB
centos                             8.1.1911            470671670cac        3 months ago        237MB
172.17.0.1:8005/kevin1228/centos   8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server              latest              8cc13133f6ed        3 months ago        49.7MB

6、私有registry安全认证

[root@Server ~]# yum install -y httpd-tools
Last metadata expiration check: 0:24:58 ago on Fri 24 Apr 2020 02:55:28 PM CST.
Dependencies resolved.
=============================================================================================================
 Package             Architecture   Version                                          Repository         Size
=============================================================================================================
Installing:
 httpd-tools         x86_64         2.4.37-16.module_el8.1.0+256+ae790463            AppStream         103 k
Enabling module streams:
 httpd                              2.4

Transaction Summary
=============================================================================================================
Install  1 Package

Total download size: 103 k
Installed size: 211 k
Downloading Packages:
httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64.rpm                 453 kB/s | 103 kB     00:00
-------------------------------------------------------------------------------------------------------------
Total                                                                         99 kB/s | 103 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                     1/1
  Installing       : httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64                            1/1
  Running scriptlet: httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64                            1/1
  Verifying        : httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64                            1/1

Installed:
  httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64

Complete!
[root@Server ~]# mkdir /data/registry/auth
[root@Server ~]# htpasswd -Bbn kevin 1qaz@WSX > /data/registry/auth/htpasswd
[root@Server ~]# cat /data/registry/auth/htpasswd
kevin:$2y$05$0QK67tktOiMTEh2KVTX2sO3odFiRyNWJJ4uLznz61UXCUyw9cr4yO

7、启动带有安全认证的registry容器

[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                                   NAMES
69a577124676        registry:2.7.1                  "/entrypoint.sh /etc…"   47 minutes ago      Up 27 minutes       0.0.0.0:8005->5000/tcp                                  registry
2cbebbcb3a64        centos:8.1.1911                 "/bin/bash"              30 hours ago        Up 26 minutes       0.0.0.0:8004->80/tcp                                    vscodeweb
266b03596bdf        continuumio/anaconda3:2020.02   "/bin/bash"              41 hours ago        Up 27 minutes       0.0.0.0:8003->8888/tcp                                  condasrv
b573bedbb67c        elleflorio/svn-server:latest    "/init"                  2 days ago          Up 27 minutes       443/tcp, 0.0.0.0:3690->3690/tcp, 0.0.0.0:8001->80/tcp   svnsrv
bf9d05430205        httpd:2.4.43                    "httpd-foreground"       2 days ago          Up 27 minutes       0.0.0.0:8002->80/tcp                                    apachesrv
7a5b653ef143        nginx:1.17.10                   "nginx -g 'daemon of…"   2 days ago          Up 27 minutes       0.0.0.0:8000->80/tcp                                    nginxsrv
[root@Server ~]# docker container stop registry
registry
[root@Server ~]# docker container rm registry
registry
[root@Server ~]# docker container run -d -p 8005:5000 \
> --name registry \
> -v /data/registry:/var/lib/registry \
> -v /data/registry/auth:/opt/auth \
> -e "REGISTRY_AUTH=htpasswd" \
> -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
> -e "REGISTRY_AUTH_HTPASSWD_PATH=/opt/auth/htpasswd" \
> --restart=always registry:2.7.1
8d9c6f28311e4a00ef8f386def80a2d8bac7b57943292874063cb49e47bb40b2
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                                                   NAMES
8d9c6f28311e        registry:2.7.1                  "/entrypoint.sh /etc…"   7 seconds ago       Up 7 seconds        0.0.0.0:8005->5000/tcp                                  registry
2cbebbcb3a64        centos:8.1.1911                 "/bin/bash"              30 hours ago        Up 33 minutes       0.0.0.0:8004->80/tcp                                    vscodeweb
266b03596bdf        continuumio/anaconda3:2020.02   "/bin/bash"              41 hours ago        Up 34 minutes       0.0.0.0:8003->8888/tcp                                  condasrv
b573bedbb67c        elleflorio/svn-server:latest    "/init"                  2 days ago          Up 34 minutes       443/tcp, 0.0.0.0:3690->3690/tcp, 0.0.0.0:8001->80/tcp   svnsrv
bf9d05430205        httpd:2.4.43                    "httpd-foreground"       2 days ago          Up 34 minutes       0.0.0.0:8002->80/tcp                                    apachesrv
7a5b653ef143        nginx:1.17.10                   "nginx -g 'daemon of…"   2 days ago          Up 34 minutes       0.0.0.0:8000->80/tcp                                    nginxsrv

8、上传镜像到registry

[root@Server ~]# docker image ls -a
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
ubuntu                             20.04               1d622ef86b13        6 hours ago         73.9MB
nginx                              1.17.10             e791337790a6        6 days ago          127MB
httpd                              2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3              2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                           2.7.1               708bc6af7e5e        3 months ago        25.8MB
172.17.0.1:8005/kevin1228/centos   8.1.1911            470671670cac        3 months ago        237MB
centos                             8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server              latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker image tag nginx:1.17.10 172.17.0.1:8005/kevin1228/nginx:1.17.10
[root@Server ~]# docker image ls -a
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
ubuntu                             20.04               1d622ef86b13        6 hours ago         73.9MB
172.17.0.1:8005/kevin1228/nginx    1.17.10             e791337790a6        6 days ago          127MB
nginx                              1.17.10             e791337790a6        6 days ago          127MB
httpd                              2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3              2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                           2.7.1               708bc6af7e5e        3 months ago        25.8MB
172.17.0.1:8005/kevin1228/centos   8.1.1911            470671670cac        3 months ago        237MB
centos                             8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server              latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker login 172.17.0.1:8005
Username: kevin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@Server ~]# docker push 172.17.0.1:8005/kevin1228/nginx:1.17.10
The push refers to repository [172.17.0.1:8005/kevin1228/nginx]
be91fceb796e: Pushed
919b6770519b: Pushed
b60e5c3bcef2: Pushed
1.17.10: digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee size: 948

9、从registry拉取镜像

[root@Server ~]# docker image ls -a
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
ubuntu                             20.04               1d622ef86b13        7 hours ago         73.9MB
172.17.0.1:8005/kevin1228/nginx    1.17.10             e791337790a6        6 days ago          127MB
nginx                              1.17.10             e791337790a6        6 days ago          127MB
httpd                              2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3              2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                           2.7.1               708bc6af7e5e        3 months ago        25.8MB
172.17.0.1:8005/kevin1228/centos   8.1.1911            470671670cac        3 months ago        237MB
centos                             8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server              latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker image rm 172.17.0.1:8005/kevin1228/nginx:1.17.10
Untagged: 172.17.0.1:8005/kevin1228/nginx:1.17.10
Untagged: 172.17.0.1:8005/kevin1228/nginx@sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
[root@Server ~]# docker image ls -a
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
ubuntu                             20.04               1d622ef86b13        7 hours ago         73.9MB
nginx                              1.17.10             e791337790a6        6 days ago          127MB
httpd                              2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3              2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                           2.7.1               708bc6af7e5e        3 months ago        25.8MB
172.17.0.1:8005/kevin1228/centos   8.1.1911            470671670cac        3 months ago        237MB
centos                             8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server              latest              8cc13133f6ed        3 months ago        49.7MB
[root@Server ~]# docker image pull 172.17.0.1:8005/kevin1228/nginx:1.17.10
1.17.10: Pulling from kevin1228/nginx
Digest: sha256:6b3b6c113f98e901a8b1473dee4c268cf37e93d72bc0a01e57c65b4ab99e58ee
Status: Downloaded newer image for 172.17.0.1:8005/kevin1228/nginx:1.17.10
172.17.0.1:8005/kevin1228/nginx:1.17.10
[root@Server ~]# docker image ls -a
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
ubuntu                             20.04               1d622ef86b13        7 hours ago         73.9MB
172.17.0.1:8005/kevin1228/nginx    1.17.10             e791337790a6        6 days ago          127MB
nginx                              1.17.10             e791337790a6        6 days ago          127MB
httpd                              2.4.43              bdc169d27d36        7 days ago          166MB
continuumio/anaconda3              2020.02             bdb4a7e92a49        6 weeks ago         2.7GB
registry                           2.7.1               708bc6af7e5e        3 months ago        25.8MB
172.17.0.1:8005/kevin1228/centos   8.1.1911            470671670cac        3 months ago        237MB
centos                             8.1.1911            470671670cac        3 months ago        237MB
elleflorio/svn-server              latest              8cc13133f6ed        3 months ago        49.7MB

相关文章

网友评论

    本文标题:Docker管理-构建私有Registry

    本文链接:https://www.haomeiwen.com/subject/rvlfwhtx.html