docker學習11-上傳本地鏡像到鏡像倉庫


前言

在本地自己制作用過鏡像后,上傳到鏡像倉庫,這樣方便在不同的機器上快速搭建同一套環境。
如果公開的話,別人也可以用你的鏡像快速搭建環境,類似於 GitHub 本地代碼上傳到代碼倉庫,再從倉庫拉取代碼到本地。

新建鏡像倉庫

輸入倉庫名稱和描述,可以選擇公共 public 的倉庫和私有 private 的倉庫

創建成功后,右側會提示使用docker push推送

docker push yoyo********/yoyo-pytest:tagname

本地鏡像

本地鏡像制作參考前面這篇https://www.cnblogs.com/yoyoketang/p/11397597.html

docker build -t yoyo_pytest:v1 .

[root@VM_0_2_centos docker-run]# docker build -t yoyo_pytest:v1 .
Sending build context to Docker daemon  3.072kB
Step 1/8 : FROM python:3.6.8
 ---> 48c06762acf0
Step 2/8 : MAINTAINER yoyo  <283340479@qq.com>
 ---> Using cache
 ---> e0835a3f4d47
Step 3/8 : RUN pip install --upgrade pip  --index-url https://pypi.douban.com/simple
 ---> Using cache
 ---> 0909be7567da
Step 4/8 : WORKDIR /code
 ---> Using cache
 ---> d006572cbc66
Step 5/8 : ADD . /code
 ---> Using cache
 ---> 7296a3b5c7fe
Step 6/8 : RUN pip install -r requirements.txt --index-url https://pypi.douban.com/simple
 ---> Using cache
 ---> ffa6afb30d19
Step 7/8 : ENTRYPOINT ["pytest"]
 ---> Using cache
 ---> d4da9935ba20
Step 8/8 : CMD ["--help"]
 ---> Using cache
 ---> 250e663c1097
Successfully built 250e663c1097
Successfully tagged yoyo_pytest:v1

docker build 鏡像制作完成之后,查看本地鏡像

[root@VM_0_2_centos docker-run]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
yoyo_pytest         v1                  250e663c1097        6 minutes ago       939MB

打本地標簽tag

在上傳之前,先給本地鏡像打個tag標簽,相當於重新復制鏡像並重命名為docker賬戶名/倉庫名稱

docker tag 本地鏡像:tag docker賬號/docker倉庫:tag

[root@VM_0_2_centos docker-run]# docker tag yoyo_pytest:v1  yoyo*****/yoyo-pytest
[root@VM_0_2_centos docker-run]# docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
yoyo/pytest                 latest              250e663c1097        30 minutes ago      939MB
yoyo*****/yoyo-pytest   latest              250e663c1097        30 minutes ago      939MB

push 上傳本地鏡像

先登陸docker hub賬號,關於賬號的注冊和登陸查看上一篇https://www.cnblogs.com/yoyoketang/p/11923050.html

[root@VM_0_2_centos docker-run]# docker login
Authenticating with existing credentials...
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@VM_0_2_centos docker-run]# 

上傳本地鏡像標簽到鏡像倉庫,使用docker指令

docker push docker 賬號/倉庫名稱:tagname

[root@VM_0_2_centos docker-run]# docker push yoyo******/yoyo-pytest
The push refers to repository [docker.io/yoyo*********/yoyo-pytest]
6ec67a80257a: Pushed 
d8f6dad5fd38: Pushed 
08f4f1010d69: Pushed 
3b08987fd99a: Pushed 
d03a0ab13129: Pushed 
02d7555642f3: Pushed 
b04c763f3532: Pushed 
24747797d2fa: Pushed 
a637c551a0da: Pushed 
2c8d31157b81: Pushed 
7b76d801397d: Pushed 
f32868cde90b: Pushed 
0db06dff9d9a: Pushed 
latest: digest: sha256:35f815bd6169c75f998a894a664d850abfae5c5c99cbcc80881cb123f777754e size: 3054

上傳完成后打開自己的docker hub賬號,查看鏡像倉庫

pull 拉取鏡像

拉取鏡像使用docker pull 你自己的鏡像名稱

docker pull yoyo******/yoyo-pytest


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM