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

原文地址:https://www.cnblogs.com/yoyoketang/p/11923263.html