【Docker】第四篇 Docker倉庫管理

旅行者-Travel發表於2018-09-27

一、倉庫概述

  • 倉庫(Repository)Docker倉庫主要用於映象的儲存,它是映象分發、部署的關鍵。倉庫分為公共倉庫和私有倉庫。
  • 註冊伺服器(Registry)和倉庫區別註冊伺服器上往往存放著多個倉庫,每個倉庫中又包含了多個映象,每個映象有不同的標籤(tag)
  • 官方的公用倉庫Docker Hub:如果僅僅是搜尋和使用Docker Hub的公共映象,不需要Docker Hub賬戶就可以直接操作。如果要上傳和分享我們自己建立的映象,就需要Docker Hub賬戶。注:註冊賬戶需要藉助FQ工具

二、倉庫管理

1、註冊賬號
https://hub.docker.com/ #在此頁面註冊賬號,需要使用者名稱,郵箱,密碼(注:需要FQ才能註冊,註冊通過郵箱啟用後可以通過網頁登陸)
2、登陸docker hub
root@localhost ~]# docker login
#Login with your Docker ID to push and pull images from Docker Hub. If you don`t have a Docker ID, head over to https://hub.docker.com to create one.
Username: *******      
Password: 
Login Succeeded
3、查詢映象   #可參考https://www.cnblogs.com/yangleitao/p/9683104.html
[root@localhost ~]# docker search centos #可以加上版本號
4、下載映象
[root@localhost ~]# docker pull centos
5、上傳映象
#我們可以把自己的映象傳到docker hub官網上,前提是已經註冊了賬號
[root@localhost ~]# docker push image_name   

三、搭建私有倉庫

1、使用registry映象建立私有倉庫
[root@localhost ~]# docker search registry
NAME                                    DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
registry                                The Docker Registry 2.0 implementation for s…   2216                [OK]                
[root@localhost ~]# docker pull registry   #直接下載映象
[root@localhost ~]# docker images    #檢視新下載的映象

2、
[root@localhost ~]# mkdir -p /data/registry/   #建立一個本地目錄,等一下掛載
[root@localhost ~]# 
[root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry/:/tmp/registry registry
599c0e1a298f5e7a19b9ba01ff314c3e3a26a22b3cba1e6800e21ffb54c8e9d5
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
599c0e1a298f        registry            "/entrypoint.sh /etc…"   9 seconds ago       Up 7 seconds        0.0.0.0:5000->5000/tcp   vibrant_engelbart
17c54a92a4e8        ubuntu:latest       "/bin/bash"              6 days ago          Up 6 days                                    quizzical_bhabha
[root@localhost ~]#

-d : 後臺執行

-p : 宿主機跟容器對映埠 SERVER_PORT:CONTAINER_PORT

-v : 掛載宿主機目錄到容器中作為資料卷, docker registry上傳映象預設存放到容器/var/lib/registry,將本地/data/registry目錄掛載到容器中,避免刪除容器是資料丟失

3、管理私有倉庫
[root@localhost ~]# docker run -d -p 5000:5000 registry 
19003703c71307603cdb48fab242c96dc34c0e37f0dcfe2e568658abbea40557
[root@localhost ~]# ps -aux|grep docker

[root@localhost ~]# docker push 192.168.19.130:5000/test
報如下錯: 
The push refers to a repository [192.168.19.130:5000/test] 
Get https://192.168.19.130:5000/v1/_ping: dial tcp 192.168.19.130:5000: getsockopt: connection refused 
解決辦法: 
a,執行 
    echo `{ "insecure-registries":["192.168.19.130:5000"] }` >> /etc/docker/daemon.json   #或者直接修改配置檔案
b, 重啟docker client的docker 服務 

[root@localhost ~]# systemctl restart docker  #如果容器沒有開啟也會報錯
[root@localhost ~]# docker push 192.168.19.130:5000/test1   #再次上傳成功
The push refers to repository [192.168.19.130:5000/test1]
8d7ea83e3c62: Pushed 
6a061ee02432: Pushed 
f73b2816c52a: Pushed 
6267b420796f: Pushed 
a30b835850bf: Pushed 
latest: digest: sha256:a819482773d99bbbb570626b6101fa37cd93a678581ee564e89feae903c95f20 size: 1357

[root@localhost ~]# curl -XGET http://192.168.19.130:5000/v2/_catalog 
{"repositories":["test","test1"]}

[root@localhost ~]# curl -XGET http://192.168.19.130:5000/v2/test1/tags/list
{"name":"test1","tags":["latest"]}
[root@localhost ~]# 

 

相關文章