(六)Harbor登录、从库中pull,向库中push操作

一、harbor登录

在web页面中输入https://139.198.18.134:443(因为是用的是青云的主机,所以必须使用外网IP,刚开始会报“您的连接并不安全”,点击“高级”,然后“添加到例外”--“确认添加到例外”)

新建一个项目
[root@hadoop004 harbor]# docker login hadoop004
Username: admin
Password: 
Error response from daemon: Get https://hadoop004/v2/: x509: certificate signed by unknown authority
[root@hadoop004 harbor]# mkdir -p /etc/docker/certs.d/hadoop004/
[root@hadoop004 harbor]# cp /usr/local/harbor/data/cert/ca.crt /etc/docker/certs.d/hadoop004/
[root@hadoop004 harbor]# docker login hadoop004                                 Username: admin
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@hadoop004 harbor]# cat /root/.docker/config.json
{
        "auths": {
                "hadoop004": {
                        "auth": "YWRtaW46SGFyYm9yMTIzNDU="
                }
        },
        "HttpHeaders": {
                "User-Agent": "Docker-Client/18.06.1-ce (linux)"
        }
}
[root@hadoop004 harbor]#docker logout hadoop004
Removing login credentials for hadoop004
[root@hadoop004 harbor]# cat /root/.docker/config.json
{
        "auths": {},
        "HttpHeaders": {
                "User-Agent": "Docker-Client/18.06.1-ce (linux)"
        }
}
[root@hadoop004 harbor]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
nginx                         latest              62f816a209e6        7 days ago          109MB
mysql                         5.6                 a46c2a2722b9        2 weeks ago         256MB
hello-world                   latest              4ab4c602aa5e        2 months ago        1.84kB
vmware/redis-photon           v1.5.1              19245c7a4f51        5 months ago        207MB
vmware/clair-photon           v2.0.1-v1.5.1       e7f0ab982469        5 months ago        303MB
vmware/notary-server-photon   v0.5.1-v1.5.1       611385e920c3        5 months ago        211MB
vmware/notary-signer-photon   v0.5.1-v1.5.1       f9e01495db0e        5 months ago        209MB
vmware/registry-photon        v2.6.2-v1.5.1       2efae6b250b1        5 months ago        198MB
vmware/nginx-photon           v1.5.1              90d35cd72a68        5 months ago        135MB
vmware/harbor-log             v1.5.1              67000769dfac        5 months ago        200MB
vmware/harbor-jobservice      v1.5.1              3f7a7987ca5b        5 months ago        194MB
vmware/harbor-ui              v1.5.1              8dbe945233a8        5 months ago        212MB
vmware/harbor-adminserver     v1.5.1              a11b8eb3f9d8        5 months ago        183MB
vmware/harbor-db              v1.5.1              afa780d73279        5 months ago        526MB
vmware/mariadb-photon         v1.5.1              59ed57632415        5 months ago        526MB
vmware/postgresql-photon      v1.5.1              41b693c0ce50        5 months ago        221MB
vmware/harbor-migrator        v1.5.0              466c57ab0dc3        6 months ago        1.16GB
vmware/photon                 1.0                 4b481ecbef2a        6 months ago        130MB

二、创建自己的镜像然后push上去

//创建属于自己的版本的镜像
[root@hadoop004 harbor]# docker tag mysql:5.6 hadoop004/hlwdata/mysql:v1
[root@hadoop004 harbor]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
nginx                         latest              62f816a209e6        7 days ago          109MB
hadoop004/hlwdata/mysql       v1                  a46c2a2722b9        2 weeks ago         256MB
mysql                         5.6                 a46c2a2722b9        2 weeks ago         256MB
hello-world                   latest              4ab4c602aa5e        2 months ago        1.84kB
vmware/redis-photon           v1.5.1              19245c7a4f51        5 months ago        207MB
vmware/clair-photon           v2.0.1-v1.5.1       e7f0ab982469        5 months ago        303MB
vmware/notary-server-photon   v0.5.1-v1.5.1       611385e920c3        5 months ago        211MB
vmware/notary-signer-photon   v0.5.1-v1.5.1       f9e01495db0e        5 months ago        209MB
vmware/registry-photon        v2.6.2-v1.5.1       2efae6b250b1        5 months ago        198MB
vmware/nginx-photon           v1.5.1              90d35cd72a68        5 months ago        135MB
vmware/harbor-log             v1.5.1              67000769dfac        5 months ago        200MB
vmware/harbor-jobservice      v1.5.1              3f7a7987ca5b        5 months ago        194MB
vmware/harbor-ui              v1.5.1              8dbe945233a8        5 months ago        212MB
vmware/harbor-adminserver     v1.5.1              a11b8eb3f9d8        5 months ago        183MB
vmware/harbor-db              v1.5.1              afa780d73279        5 months ago        526MB
vmware/mariadb-photon         v1.5.1              59ed57632415        5 months ago        526MB
vmware/postgresql-photon      v1.5.1              41b693c0ce50        5 months ago        221MB
vmware/harbor-migrator        v1.5.0              466c57ab0dc3        6 months ago        1.16GB
vmware/photon                 1.0                 4b481ecbef2a        6 months ago        130MB
//可以看到hadoop004/hlwdata/mysql:v1和mysql:5.6的 IMAGE ID 是一样的,因为没做变化,只改了名字
//尝试将自己创建的镜像push上去
[root@hadoop004 harbor]# docker push hadoop004/hlwdata/mysql:v1
The push refers to repository [docker.io/hadoop004/hlwdata/mysql]
699df95a5aeb: Preparing 
2171f3a45c5b: Preparing 
5685cd307859: Preparing 
d9ebb7ec059f: Preparing 
596861b65c17: Preparing 
9a20b62888c2: Waiting 
cef03d1730e4: Waiting 
2039058a7b75: Waiting 
7332e314e51e: Waiting 
ebdd1217991d: Waiting 
237472299760: Waiting 
denied: requested access to the resource is denied
//因为没有DNS,报错权限问题,那尝试用ip登录,然后用ip   push
[root@hadoop004 harbor]# docker login 192.168.137.5
Username: admin
Password: 
Error response from daemon: Get https://192.168.137.5/v2/: x509: cannot validate certificate for 192.168.137.5 because it doesn't contain any IP SANs
//使用ip登录失败,此时需要编辑一个daemon.json文件
[root@hadoop004 harbor]# vi /etc/docker/daemon.json
{
"registry-mirrors":["https://hadoop004"],
"insecure-registries":["192.168.137.5"]
}
//重启使得上方的json生效
[root@hadoop004 harbor]# docker-compose stop
[root@hadoop004 harbor]# systemctl daemon-reload
[root@hadoop004 harbor]# systemctl restart docker
[root@hadoop004 harbor]# docker-compose up -d
harbor-log is up-to-date
redis is up-to-date
harbor-db is up-to-date
harbor-adminserver is up-to-date
registry is up-to-date
Starting harbor-ui ... done
Starting harbor-jobservice ... 
Starting harbor-jobservice ... done
[root@hadoop004 harbor]# docker-compose ps
       Name               Command               State                Ports      
--------------------------------------------------------------------------------
harbor-adminserver   /harbor/start.sh     Up (healthy)                          
harbor-db            /usr/local/bin/doc   Up (healthy)         3306/tcp         
                     ker-entr ...                                               
harbor-jobservice    /harbor/start.sh     Up                                    
harbor-log           /bin/sh -c           Up (healthy)         127.0.0.1:1514->1
                     /usr/local/bin/                           0514/tcp         
                     ...                                                        
harbor-ui            /harbor/start.sh     Up (healthy)                          
nginx                nginx -g daemon      Up (health:          0.0.0.0:443->443/
                     off;                 starting)            tcp, 0.0.0.0:4443
                                                               ->4443/tcp, 0.0.0
                                                               .0:80->80/tcp    
redis                docker-              Up                   6379/tcp         
                     entrypoint.sh                                              
                     redis ...                                                  
registry             /entrypoint.sh       Up (healthy)         5000/tcp         
                     serve /etc/ ...  
//再次尝试使用ip登录
[root@hadoop004 harbor]# docker login 192.168.137.5
Username: admin
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
//创建v2版本的镜像
[root@hadoop004 harbor]# docker tag mysql:5.6 192.168.137.5/hlwdata/mysql:v2
//尝试push
[root@hadoop004 harbor]# docker push 192.168.137.5/hlwdata/mysql:v2
The push refers to repository [192.168.137.5/hlwdata/mysql]
699df95a5aeb: Pushed 
2171f3a45c5b: Pushed 
5685cd307859: Pushed 
d9ebb7ec059f: Pushed 
596861b65c17: Pushed 
9a20b62888c2: Pushed 
cef03d1730e4: Pushed 
2039058a7b75: Pushed 
7332e314e51e: Pushed 
ebdd1217991d: Pushed 
237472299760: Pushed 
v2: digest: sha256:be1eecb61652ae323e68918aef26d1b0e7a6d973f3d3155a2ab233c7fb4b3447 size: 2621
//push成功!
[root@hadoop004 harbor]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
nginx                         latest              62f816a209e6        7 days ago          109MB
mysql                         5.6                 a46c2a2722b9        2 weeks ago         256MB
192.168.137.5/hlwdata/mysql   v2                  a46c2a2722b9        2 weeks ago         256MB
hadoop004/hlwdata/mysql       v1                  a46c2a2722b9        2 weeks ago         256MB
hello-world                   latest              4ab4c602aa5e        2 months ago        1.84kB
vmware/redis-photon           v1.5.1              19245c7a4f51        5 months ago        207MB
vmware/clair-photon           v2.0.1-v1.5.1       e7f0ab982469        5 months ago        303MB
vmware/notary-server-photon   v0.5.1-v1.5.1       611385e920c3        5 months ago        211MB
vmware/notary-signer-photon   v0.5.1-v1.5.1       f9e01495db0e        5 months ago        209MB
vmware/registry-photon        v2.6.2-v1.5.1       2efae6b250b1        5 months ago        198MB
vmware/nginx-photon           v1.5.1              90d35cd72a68        5 months ago        135MB
vmware/harbor-log             v1.5.1              67000769dfac        5 months ago        200MB
vmware/harbor-jobservice      v1.5.1              3f7a7987ca5b        5 months ago        194MB
vmware/harbor-ui              v1.5.1              8dbe945233a8        5 months ago        212MB
vmware/harbor-adminserver     v1.5.1              a11b8eb3f9d8        5 months ago        183MB
vmware/harbor-db              v1.5.1              afa780d73279        5 months ago        526MB
vmware/mariadb-photon         v1.5.1              59ed57632415        5 months ago        526MB
vmware/postgresql-photon      v1.5.1              41b693c0ce50        5 months ago        221MB
vmware/harbor-migrator        v1.5.0              466c57ab0dc3        6 months ago        1.16GB
vmware/photon                 1.0                 4b481ecbef2a        6 months ago        130MB
//下面尝试一下拉取镜像到本地,首先删除本地的192.168.137.5/hlwdata/mysql:v2镜像
[root@hadoop004 harbor]# docker rmi 192.168.137.5/hlwdata/mysql:v2
Untagged: 192.168.137.5/hlwdata/mysql:v2
Untagged: 192.168.137.5/hlwdata/mysql@sha256:be1eecb61652ae323e68918aef26d1b0e7a6d973f3d3155a2ab233c7fb4b3447
//可以看到192.168.137.5/hlwdata/mysql:v2镜像已经没有了
[root@hadoop004 harbor]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
nginx                         latest              62f816a209e6        7 days ago          109MB
hadoop004/hlwdata/mysql       v1                  a46c2a2722b9        2 weeks ago         256MB
mysql                         5.6                 a46c2a2722b9        2 weeks ago         256MB
hello-world                   latest              4ab4c602aa5e        2 months ago        1.84kB
vmware/redis-photon           v1.5.1              19245c7a4f51        5 months ago        207MB
vmware/clair-photon           v2.0.1-v1.5.1       e7f0ab982469        5 months ago        303MB
vmware/notary-server-photon   v0.5.1-v1.5.1       611385e920c3        5 months ago        211MB
vmware/notary-signer-photon   v0.5.1-v1.5.1       f9e01495db0e        5 months ago        209MB
vmware/registry-photon        v2.6.2-v1.5.1       2efae6b250b1        5 months ago        198MB
vmware/nginx-photon           v1.5.1              90d35cd72a68        5 months ago        135MB
vmware/harbor-log             v1.5.1              67000769dfac        5 months ago        200MB
vmware/harbor-jobservice      v1.5.1              3f7a7987ca5b        5 months ago        194MB
vmware/harbor-ui              v1.5.1              8dbe945233a8        5 months ago        212MB
vmware/harbor-adminserver     v1.5.1              a11b8eb3f9d8        5 months ago        183MB
vmware/harbor-db              v1.5.1              afa780d73279        5 months ago        526MB
vmware/mariadb-photon         v1.5.1              59ed57632415        5 months ago        526MB
vmware/postgresql-photon      v1.5.1              41b693c0ce50        5 months ago        221MB
vmware/harbor-migrator        v1.5.0              466c57ab0dc3        6 months ago        1.16GB
vmware/photon                 1.0                 4b481ecbef2a        6 months ago        130MB
//从库中拉取镜像
[root@hadoop004 harbor]# docker pull 192.168.137.5/hlwdata/mysql:v2
v2: Pulling from hlwdata/mysql
Digest: sha256:be1eecb61652ae323e68918aef26d1b0e7a6d973f3d3155a2ab233c7fb4b3447
Status: Downloaded newer image for 192.168.137.5/hlwdata/mysql:v2
//拉取成功,本地再次有了192.168.137.5/hlwdata/mysql:v2镜像
[root@hadoop004 harbor]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
nginx                         latest              62f816a209e6        7 days ago          109MB
192.168.137.5/hlwdata/mysql   v2                  a46c2a2722b9        2 weeks ago         256MB
hadoop004/hlwdata/mysql       v1                  a46c2a2722b9        2 weeks ago         256MB
mysql                         5.6                 a46c2a2722b9        2 weeks ago         256MB
hello-world                   latest              4ab4c602aa5e        2 months ago        1.84kB
vmware/redis-photon           v1.5.1              19245c7a4f51        5 months ago        207MB
vmware/clair-photon           v2.0.1-v1.5.1       e7f0ab982469        5 months ago        303MB
vmware/notary-server-photon   v0.5.1-v1.5.1       611385e920c3        5 months ago        211MB
vmware/notary-signer-photon   v0.5.1-v1.5.1       f9e01495db0e        5 months ago        209MB
vmware/registry-photon        v2.6.2-v1.5.1       2efae6b250b1        5 months ago        198MB
vmware/nginx-photon           v1.5.1              90d35cd72a68        5 months ago        135MB
vmware/harbor-log             v1.5.1              67000769dfac        5 months ago        200MB
vmware/harbor-jobservice      v1.5.1              3f7a7987ca5b        5 months ago        194MB
vmware/harbor-ui              v1.5.1              8dbe945233a8        5 months ago        212MB
vmware/harbor-adminserver     v1.5.1              a11b8eb3f9d8        5 months ago        183MB
vmware/harbor-db              v1.5.1              afa780d73279        5 months ago        526MB
vmware/mariadb-photon         v1.5.1              59ed57632415        5 months ago        526MB
vmware/postgresql-photon      v1.5.1              41b693c0ce50        5 months ago        221MB
vmware/harbor-migrator        v1.5.0              466c57ab0dc3        6 months ago        1.16GB
vmware/photon                 1.0                 4b481ecbef2a        6 months ago        130MB

三、其他机器登录

[root@hadoop003 ~]# mkdir -p /etc/docker/certs.d/hadoop004
[root@hadoop003 ~]# scp hadoop004:/usr/local/harbor/data/cert/ca.crt  /etc/docker/certs.d/hadoop003/
[root@hadoop003 ~]# vi  /etc/docker/daemon.json
{
        "registry-mirrors": ["https://hadoop003"],
        "insecure-registries":["192.168.137.4","192.168.137.5"]
}
[root@hadoop003 ~]# systemctl restart docker
[root@hadoop003 ~]# docker login -u admin -p Harbor12345 192.168.137.5
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
[root@hadoop003 ~]# docker pull 192.168.137.5/hlwdata/mysql:v2

你可能感兴趣的:((六)Harbor登录、从库中pull,向库中push操作)