1. 程式人生 > >020、搭建本地Registry(2019-01-11 週五)

020、搭建本地Registry(2019-01-11 週五)

參考 https://www.cnblogs.com/CloudMan6/p/6902325.html   Docker Hub 雖然方便,但還是有些限制,比如     1、需要Internet連線,上傳下載速度慢     2、上傳到Docker Hub上的公共映象任何人都能訪問,私有Registry需要收費     3、出於安全原因很多公司不允許將映象放到外網   最簡單的解決方案就是搭建本地Registry(Registry也支援認證和https加密,這裡不做講解)  
[email protected]
:~/020# docker images REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[email protected]
:~/020# docker build -t test020 .    #    構建一個用於測試上傳下載的映象 Sending build context to Docker daemon  2.048kB Step 1/2 : FROM busybox latest: Pulling from library/busybox 57c14dd66db0: Pull complete Digest: sha256:b6e640a3768c460ad6066a003b6da52034c31aaf8500f9263057ddffcd830ef6 Status: Downloaded newer image for busybox:latest ---> 3a093384ac30 Step 2/2 : CMD echo "Hello www1707" ---> Running in d0817c08cb82 Removing intermediate container d0817c08cb82 ---> d93c942a1584 Successfully built d93c942a1584 Successfully tagged test020:latest
[email protected]
:~/020# docker images REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE test020             latest              d93c942a1584        About a minute ago   1.2MB busybox             latest              3a093384ac30        12 days ago          1.2MB [email protected]:~/020# docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2Unable to find image 'registry:2' locally    #    執行本地Registry容器 2: Pulling from library/registry cd784148e348: Pull complete 0ecb9b11388e: Pull complete 918b3ddb9613: Pull complete 5aa847785533: Pull complete adee6f546269: Pull complete Digest: sha256:1cd9409a311350c3072fe510b52046f104416376c126a479cef9a4dfe692cf57 Status: Downloaded newer image for registry:2 f9e7d22e21d6e0c03b146a3e2100c135c14203308c4323b0673c45eaea97030d [email protected]:~/020# docker images REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE test020             latest              d93c942a1584        About a minute ago   1.2MB registry            2                   33fbbf4a24e5        9 days ago           24.2MB busybox             latest              3a093384ac30        12 days ago          1.2MB [email protected]:~/020# docker tag test020:latest 127.0.0.1:5000/www1707/test020:v1    #    為上傳映象打tag [email protected]:~/020# docker images REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE 127.0.0.1:5000/www1707/test020   v1                  d93c942a1584        3 minutes ago       1.2MB test020                          latest              d93c942a1584        3 minutes ago       1.2MB registry                         2                   33fbbf4a24e5        9 days ago          24.2MB busybox                          latest              3a093384ac30        12 days ago         1.2MB [email protected]:~/020# docker push 127.0.0.1:5000/www1707/test020:v1    #    上傳映象 The push refers to repository [127.0.0.1:5000/www1707/test020] 683f499823be: Pushed v1: digest: sha256:b3d65da9455ca71f2bc2d2e1343a1ad1058829b027eee576976becc5ecdce8af size: 527 [email protected]:~/020# docker rmi 127.0.0.1:5000/www1707/test020:v1    #    刪掉本地映象 Untagged: 127.0.0.1:5000/www1707/test020:v1 Untagged: 127.0.0.1:5000/www1707/[email protected]:b3d65da9455ca71f2bc2d2e1343a1ad1058829b027eee576976becc5ecdce8af [email protected]:~/020# docker rmi test020:latest Untagged: test020:latest Deleted: sha256:d93c942a158487248506ac545d33f6fc27c7af29960a5b139e2ef4510b39f37b [email protected]:~/020# docker images REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE registry            2                   33fbbf4a24e5        9 days ago          24.2MB busybox             latest              3a093384ac30        12 days ago         1.2MB [email protected]:~/020# docker pull 127.0.0.1:5000/www1707/test020:v1    #    下載映象測試 v1: Pulling from www1707/test020 57c14dd66db0: Already exists Digest: sha256:b3d65da9455ca71f2bc2d2e1343a1ad1058829b027eee576976becc5ecdce8af Status: Downloaded newer image for 127.0.0.1:5000/www1707/test020:v1 [email protected]:~/020# docker images REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE 127.0.0.1:5000/www1707/test020   v1                  d93c942a1584        4 minutes ago       1.2MB registry                         2                   33fbbf4a24e5        9 days ago          24.2MB busybox                          latest              3a093384ac30        12 days ago         1.2MB