docker和Helm Chart的基本命令和操作

一、docker基本命令和操作

1. docker login【登录】

登录 docker client,登录成功之后会显示 Login Succeeded。
docker login登陆到指定的镜像仓库,docker pull 和 docker push 操作都需要预先执行 docker login 操作;
指令:(这里的用户名、密码和镜像仓库都换成自己的)

docker login -u <username> -p <password> iregistry.baidu-int.com

举例说明:

➜  ~ docker login -u yangxiaonan01 -p Xxxxxxx123 iregistry.baidu-int.com 
    WARNING! Using --password via the CLI is insecure. Use --password-stdin.
    Login Succeeded
2.docker pull【拉取】

指令:

docker pull iregistry.baidu-int.com/<namespace>/IMAGE[:TAG]

举例说明:

➜  ~ docker pull iregistry.baidu-int.com/xk-repo-test/centos-test:1.0.1
    1.0.1: Pulling from xk-repo-test/centos-test
    8a29a15cefae: Pull complete 
    Digest: sha256:9e0c275e0bcb495773b10a18e499985d782810e47b4fce076422acb4bc3da3dd
    Status: Downloaded newer image for iregistry.baidu-int.com/xk-repo-test/centos-test:1.0.1
    iregistry.baidu-int.com/xk-repo-test/centos-test:1.0.1
3.docker save【保存】

指令:

docker save -o 景象名.tar 镜像地址

该指令会将镜像保存在本地,执行命令的目录上

4.docker build【构建】

指令:

docker build -f <dockerFile> -t iregistry.baidu-int.com/<namespace>/IMAGE[:TAG] <contextPath>

注意:

dockerFile:一个用来构建镜像的文本文件

  • namespace:命名空间。一个组织维度,包含多个镜像仓库,和chart
  • IMAGE:镜像名称
  • TAG:镜像标签
  • contextPath:指定构建镜像的上下文的路径,构建镜像的过程中,可以且只可以引用上下文中的任何文件

举例说明:

➜  ~ vi ~/Desktop/work/DockerFile/dockerfile-nginx 

➜  ~ cat ~/Desktop/work/DockerFile/dockerfile-nginx 
FROM iregistry.baidu-int.com/yxn-test/nginx:latest
MAINTAINER yxn<yangxiaonan01@baidu.com>

➜  ~ docker build -f ~/Desktop/work/DockerFile/dockerfile-nginx -t iregistry.baidu-int.com/yxn-test/nginx:v1.0 .

➜  ~ docker images
REPOSITORY                                    TAG       IMAGE ID       CREATED         SIZE
iregistry.baidu-int.com/yxn-test/nginx        v1.0      1a6c19b45d6e   2 days ago      133MB
5.docker push【推送】

指令:

docker push iregistry.baidu-int.com//IMAGE[:TAG]

注意:

  • namespace:命名空间。一个组织维度,包含多个镜像仓库,和chart
  • IMAGE:镜像名称
  • TAG:镜像标签

举例说明:

   ➜  ~ docker push iregistry.baidu-int.com/yxn-test/centos-test:1.0.1     
        The push refers to repository [iregistry.baidu-int.com/yxn-test/mysql]
        03a007e88ba3: Pushed 
        d605c112cfab: Pushed 
        74634a9cf30b: Pushed 
        ea5fd90d1e58: Pushed 
        cffd1f984514: Pushed 
        3182d4b853f0: Pushed 
        ae477702a513: Pushed 
        570df12e998c: Pushed 
        b2abc2ad4a41: Pushed 
        e82f328cb5e6: Pushed 
        14be0d40572c: Pushed 
        02c055ef67f5: Pushed 
        latest: digest: sha256:68b207d01891915410db3b5bc1f69963e3dc8f23813fd01e61e6d7e7e3a46680 size: 2828
6.docker tag【打标签】

指令:

docker tag SOURCE_IMAGE[:TAG] iregistry.baidu-int.com/<namespace>/IMAGE[:TAG]

注意:

  • namespace:命名空间。一个组织维度,包含多个镜像仓库,和chart
  • IMAGE:镜像名称
  • TAG:镜像标签

举例说明:

  docker tag iregistry.baidu-int.com/xk-repo-test/centos-test:1.0.1  iregistry.baidu-int.com/yxn-test/centos-test:1.0.2

二、Chart的基本命令和操作

1. helm安装与配置
参考文档:https://helm.sh/docs/intro/install/

2. 添加仓库
简介:根据iRegistry仓库的用户名、密码,在本地添加chart repo【注意:添加一次即可】

指令:
helm repo add --username --password https://iregistry.baidu-int.com/chartrepo/

注意:
namespace:命名空间。一个组织维度,包含多个镜像仓库,和chart

指令执行结果,举例说明:

➜  ~ helm repo add --username yangxiaonan01 --password Yangxiaonan01 yxn-test https://iregistry.baidu-int.com/chartrepo/yxn-test
"yxn-test" has been added to your repositories
➜  ~ helm repo list                                                                                     
NAME    	URL                                               
yxn-test	https://iregistry.baidu-int.com/chartrepo/yxn-test

3.下载 Chart
简介:从chart仓库中下载指定版本的chart到本地;

第一步:配置 helm fetch 时使用的密码,详见【Helm Chart基本操作 --> 前提】,若已经配置过,则跳过;

第二步:本地添加仓库,详见【Helm Chart基本操作 --> 添加仓库】,若已经添加过,则跳过;
指令:
helm fetch --version <Chart 版本> <本地仓库名称>/<Chart 名称>

指令执行结果,举例说明:

➜  ~ helm fetch --version 0.1.0-145583081-1609409229920 yxn-test/helm2-demo

4.上传 Chart

简介:将本地中存在的chart文件上传到iRegistry镜像仓库中;

第一步:配置helm push的密码,详见【Helm Chart基本操作 --> 前提】,若已经配置过,则跳过;

第二步:安装 helm push 插件,参考链接:helm push插件安装;

第三步:本地添加仓库,详见【Helm Chart基本操作 --> 添加仓库】,若已经添加过,则跳过;

第四步:上传chart,helm push

  • chart package:charts文件包
  • charts repo:charts仓库名称
    指令:
➜  ~ helm plugin install https://github.com/chartmuseum/helm-push.git # 第二步:安装helm push插件
Downloading and installing helm-push v0.9.0 ...
https://github.com/chartmuseum/helm-push/releases/download/v0.9.0/helm-push_0.9.0_darwin_amd64.tar.gz
Installed plugin: push    

➜  ~ helm repo add --username yangxiaonan01 --password Xxxx1234  yxn-test https://iregistry.baidu-int.com/chartrepo/yxn-test # 第三步:添加仓库
"yxn-test" has been added to your repositories

➜  ~ helm repo list  # 查看仓库列表
NAME        	URL                                                   
yxn-test    	https://iregistry.baidu-int.com/chartrepo/yxn-test    

➜  ~ helm push ~/Downloads/sec-brain-web-0.0.1-162952076.tgz yxn-test  # 第四步:上传chart                                 
Pushing sec-brain-web-0.0.1-162952076.tgz to yxn-test...
Done.

5.安装 Chart
简介:将某个chart版本部署到k8s集群中;
第一步:配置 helm install 时使用的密码,详见【Helm Chart基本操作 --> 前提】,若已经配置过,则跳过;
第二步:本地添加仓库,详见【Helm Chart基本操作 --> 添加仓库】,若已经添加过,则跳过;
第三步:执行helm install 指令:
helm install --username= --password= --version <Chart 版本> <本地仓库名称>/<Chart 名称>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值