1. 程式人生 > >【Docker】第四篇 Docker倉庫管理

【Docker】第四篇 Docker倉庫管理

使用 註冊服務 一個 ear 2.0 lis ont www. serve

一、倉庫概述

  • 倉庫(Repository):倉庫是集中存放鏡像文件的場所,倉庫分為公共倉庫和私有倉庫。
  • 註冊服務器(Registry)和倉庫區別:註冊服務器上往往存放著多個倉庫,每個倉庫中又包含了多個鏡像,每個鏡像有不同的標簽(tag)

二、倉庫管理

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 ~]# 

【Docker】第四篇 Docker倉庫管理