首页 > 其他分享 >containerd 导入镜像

containerd 导入镜像

时间:2024-03-03 20:57:03浏览次数:16  
标签:ctr containerd image gcr 导入 io 镜像 docker k8s

containerd 导入镜像

 containerd而非docker,需要离线导入镜像

 

解决原理
https://segmentfault.com/a/1190000019534913
ctr --namespace=k8s.io images ls
复制代码
获取到你需要的镜像名称和版本之后 (参见后面的排查技巧)

docker pull mirrorgooglecontainers/$imageName:$imageVersion
docker tag  mirrorgooglecontainers/$imageName:$imageVersion k8s.gcr.io/$imageName:$imageVersion
docker save k8s.gcr.io/$imageName:$imageVersion > $imageName.tar
microk8s.ctr -n k8s.io image import $imageName.tar
复制代码

 

 

复制代码
使用ctr命令导入镜像。
ctr image import app.tar  #导入本地镜像
ctr images list|grep app  #查看导入的镜像
crictl images list|grep app #此命令也可查看

命令介绍:
ctr:是containerd本身的CLI
crictl :是Kubernetes社区定义的专门CLI工具
复制代码

 

复制代码
Steps to reproduce:

 ctr images tag 192.168.56.1:8080/docker/alpine:latest 192.168.56.1:8080/docker/alpine:1.1
192.168.56.1:8080/docker/alpine:1.1

ctr images push 192.168.56.1:8080/docker/alpine:latest 192.168.56.1:8080/docker/alpine:1.1
index-sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a: waiting        |--------------------------------------|
elapsed: 0.1 s                                                                 total:   0.0 B (0.0 B/s)
ctr: content digest sha256:29a82d50bdb8dd7814009852c1773fb9bb300d2f655bd1cd9e764e7bb1412be3: not found
复制代码

 

 

复制代码
As you see this is quite powerful and you can do a lot with it.

Let’s start by pulling an image

# ctr image pull docker.io/library/hello-world

This would give you an error saying you missed an object, because Containerd requires you to specify the object like the command below:

# ctr image pull docker.io/library/hello-world:latest

You can replace object with whatever is available like ‘alpine’

Let’s try listing the image to confirm

# ctr image ls

This can be a bit unfriendly, so try the following command:

#ctr image ls -q

The above command will give only the image name and nothing else.

Now that we’ve got our image, we need to run a container.

#ctr container create docker.io/library/hello-world:latest demo

This would create a container with container id, ‘demo’, based on the image that we pulled.

There are a few things to notice here: The output is not redirected to the CLI by default. Unlike Docker, we need to use the full path with the object every time we use a container image. Also, the image needs to be pulled before being able to run a container.

We can list the containers created with the command below:

#ctr container list

You can see the demo container listed. You can even use -q to get just the container names.

Now to delete the image.

#ctr image remove docker.io/library/hello-world:latest

This would delete the image. What would happen to your container?

#ctr container list

Your container would still be running. This is because containerd works on references, and in this case, the image is no longer being referenced as an image but it is still being referenced by the container (as a snapshot), so it wouldn’t be deleted as long as it’s being referenced.

You’ll get a better picture when learning about snapshots, which would be a topic for another article.

For now, we’ll delete the image.

#ctr container remove demo

Please leave a comment with any suggestions.
复制代码

 

复制代码
常用技巧
containerd相关的CLI确实没有Docker CLI方便,比如笔者在使用containerd时碰到一个场景,期望实现对镜像重新tag的操作,这在Docker下非常容易做到,但是在containerd下非常麻烦。crictl中并不支持这种操作,社区中也有相关issue解释:

https://github.com/kubernetes- ... s/438

所以我们只能使用其他方式,通常我会这样做:
在一台机去上使用docker tag转换image
导出镜像,并拷贝到k3s机器上
docker tag busybox busyboxaaa
docker save -o busybox.tar busyboxaaa
scp busybox.tar [email protected]:~/
用ctr导入
ctr image import busybox.tar
复制代码

 

复制代码
root@ubuntu:~# docker pull coredns/coredns:coredns-arm64
coredns-arm64: Pulling from coredns/coredns
Digest: sha256:e98e05b50afc6606d3e0a66e264175910651746262e4a4823299ec6c827ef72a
Status: Image is up to date for coredns/coredns:coredns-arm64
docker.io/coredns/coredns:coredns-arm64
root@ubuntu:~# docker tag coredns/coredns:coredns-arm64 k8s.gcr.io/coredns:1.6.7
root@ubuntu:~# docker save -o coredns:coredns-arm64.tar  k8s.gcr.io/coredns:1.6.7 
root@ubuntu:~# ctr image import coredns:coredns-arm64.tar
unpacking k8s.gcr.io/coredns:1.6.7 (sha256:19910cb28a673d9ad642c3762b71fb5da6668537d9417d14d4d0cbf82569d7a8)...done
root@ubuntu:~# 
复制代码

 

 

复制代码
两者命令对比表:

id    containerd 命令    docker 命令    备注
1    ctr image ls    docker images    获取image信息
2    ctr image pull nginx    docker pull nginx    pull 一个nginx的image
3    ctr image tag nginx nginx-test    docker tag nginx nginx-test    tag 一个nginx的image
4    ctr image push nginx-test    docker push nginx-test    push nginx-test的image
5    ctr image pull nginx    docker pull nginx    pull 一个nginx的image
6    ctr image import nginx.tar    docker load<nginx.tar.gz    导入本地镜像ctr不支持压缩
7    ctr run -d --env 111 nginx-test nginx    docker run -d --name=nginx nginx-test    运行的一个容器
8    ctr task ls    docker ps    查看运行的容器
复制代码

 

https://github.com/kubernetes/kubeadm/issues/1885

复制代码
root@ubuntu:~# kubeadm init --kubernetes-version=v1.18.1  --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.10.16.82 --ignore-preflight-errors=all unix:///run/containerd/containerd.sock  --image-repository registry.aliyuncs.com/google_containers
unknown command "unix:///run/containerd/containerd.sock" for "kubeadm init"
To see the stack trace of this error execute with --v=5 or higher
root@ubuntu:~# kubeadm init --kubernetes-version=v1.18.1  --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.10.16.82 --ignore-preflight-errors=all unix:///run/containerd/containerd.sock  --image-repository registry.aliyuncs.com/google_containers --v=5
unknown command "unix:///run/containerd/containerd.sock" for "kubeadm init"
root@ubuntu:~# 
复制代码

 

 

 

复制代码
root@ubuntu:~# ctr images  -help
NAME:
   ctr images - manage images

USAGE:
   ctr images command [command options] [arguments...]

COMMANDS:
   check       check that an image has all content available locally
   export      export images
   import      import images
   list, ls    list images known to containerd
   pull        pull an image from a remote
   push        push an image to a remote
   remove, rm  remove one or more images by reference
   tag         tag an image
   label       set and clear labels for an image

OPTIONS:
   --help, -h  show help
   
root@ubuntu:~# 
复制代码

 

复制代码
root@ubuntu:~# ctr images list -help
NAME:
   ctr images list - list images known to containerd

USAGE:
   ctr images list [command options] [flags] [<filter>, ...]

DESCRIPTION:
   list images registered with containerd

OPTIONS:
   --quiet, -q  print only the image refs
   
root@ubuntu:~# ctr images list -q 
docker.io/library/nginx:alpine
k8s.gcr.io/coredns:1.6.7
k8s.gcr.io/etcd-arm64:3.4.3-0
k8s.gcr.io/kube-apiserver:v1.18.1
k8s.gcr.io/kube-controller-manager:v1.18.1
k8s.gcr.io/kube-proxy:v1.18.1
k8s.gcr.io/kube-scheduler:v1.18.1
k8s.gcr.io/pause-arm64:3.2
root@ubuntu:~# 
复制代码

 

 

复制代码
root@ubuntu:~# ctr images list -q 
docker.io/library/nginx:alpine
k8s.gcr.io/coredns:1.6.7
k8s.gcr.io/etcd-arm64:3.4.3-0
k8s.gcr.io/kube-apiserver:v1.18.1
k8s.gcr.io/kube-controller-manager:v1.18.1
k8s.gcr.io/kube-proxy:v1.18.1
k8s.gcr.io/kube-scheduler:v1.18.1
k8s.gcr.io/pause-arm64:3.2
root@ubuntu:~# ctr images rm $(ctr images list -q)
docker.io/library/nginx:alpine
k8s.gcr.io/coredns:1.6.7
k8s.gcr.io/etcd-arm64:3.4.3-0
k8s.gcr.io/kube-apiserver:v1.18.1
k8s.gcr.io/kube-controller-manager:v1.18.1
k8s.gcr.io/kube-proxy:v1.18.1
k8s.gcr.io/kube-scheduler:v1.18.1
k8s.gcr.io/pause-arm64:3.2
root@ubuntu:~# ctr images list -q 
root@ubuntu:~# 
复制代码

 

复制代码
root@ubuntu:~# ctr -n  k8s.gcr.io images list -q 
k8s.gcr.io/coredns:1.6.7
k8s.gcr.io/etcd-arm64:3.4.3-0
k8s.gcr.io/kube-apiserver:v1.18.1
k8s.gcr.io/kube-controller-manager:v1.18.1
k8s.gcr.io/kube-proxy:v1.18.1
k8s.gcr.io/kube-scheduler:v1.18.1
k8s.gcr.io/pause-arm64:3.2
root@ubuntu:~# ctr -n  k8s.gcr.io images rm $(ctr -n  k8s.gcr.io images list -q)
k8s.gcr.io/coredns:1.6.7
k8s.gcr.io/etcd-arm64:3.4.3-0
k8s.gcr.io/kube-apiserver:v1.18.1
k8s.gcr.io/kube-controller-manager:v1.18.1
k8s.gcr.io/kube-proxy:v1.18.1
k8s.gcr.io/kube-scheduler:v1.18.1
k8s.gcr.io/pause-arm64:3.2
root@ubuntu:~# ctr -n  k8s.gcr.io images list -q 
root@ubuntu:~# 
复制代码

 

复制代码
root@ubuntu:~# kubeadm config images list --image-repository k8s.gcr.io
I1015 09:51:08.165119   47994 version.go:252] remote version is much newer: v1.19.3; falling back to: stable-1.18
W1015 09:51:08.786382   47994 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
k8s.gcr.io/kube-apiserver:v1.18.9
k8s.gcr.io/kube-controller-manager:v1.18.9
k8s.gcr.io/kube-scheduler:v1.18.9
k8s.gcr.io/kube-proxy:v1.18.9
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.3-0
k8s.gcr.io/coredns:1.6.7
root@ubuntu:~# 
复制代码

 

 

标签:ctr,containerd,image,gcr,导入,io,镜像,docker,k8s
From: https://www.cnblogs.com/exmyth/p/18050695

相关文章

  • Import 相对导入中遇到的问题总结
    这是我写的第一遍博客,晚上6点52,有点困,大概写一下。一、包(Package)、模块(Modules)、脚本(Script)搞清楚什么是包、什么是模块、什么是脚本很重要,简单来说:Script是用来运行的,也就是"__name__"=="__main__"成立的.py文件Modules是一大堆Classfuntion的合集,我们不希望它的"__n......
  • 使用官方镜像快速部署 Gitlab
    之前已经发布过一篇使用docker-compose部署Gitlab的博客,使用的是国外的某位大佬制作的镜像。博客地址为:https://www.cnblogs.com/studyjobs/p/18015154.html本篇博客使用docker-compose采用官网提供的镜像部署Gitlab,部署过程非常简单无论采用哪种方式部署Gitlab,需要的......
  • npm配置淘宝镜像
    设置淘宝镜像源打开终端,输入以下命令来设置淘宝镜像源npmconfigsetregistryhttps://registry.npm.taobao.org/查看镜像使用状态。输入以下命令来查看当前的镜像源是否已成功配置:npmconfiggetregistry如果返回的地址是https://registry.npm.taobao.org/,则表示淘宝镜......
  • Windows安装node.js以及环境配置、常见npm镜像源、npm安装包报错 解决https证书过期 r
    一、Windows安装node.js以及环境配置1、下载Node.js安装包Node.js官方网站,选择LTS版本或者最新版本,然后点击下载按钮。.msi是软件安装包、.zip是压缩包,解压之后即可,不需要安装2、运行安装程序下载完成后,双击安装包运行安装程序。安装完成后,在Node的安装目录下创建两个......
  • Docker的3要素:镜像容器仓库
        Docker的3大基本组成1.镜像image2.容器container3.仓库repository 容器解释: 仓库解释:  ......
  • C# MiniExcel 导入和导出表格数据
    C#MiniExcel导入和导出表格数据1.首先从NuGet包里下载MIniExcel文件引入然后下面是一段Api控制器导入的代码导入导出的表格用.xlsx或.xls工作表///<summary>///上传文件到服务器端///</summary>///<paramname="formFile"></param>///<returns></returns>[......
  • 容器镜像服务:云原生时代的核心基石
    本文分享自天翼云开发者社区《容器镜像服务:云原生时代的核心基石》,作者:每日知识小分享随着云计算技术的快速发展,容器化技术已成为应用部署的主流方式。容器镜像服务作为容器技术的重要组成部分,为应用提供了可靠、高效、一致的运行环境。本文将对容器镜像服务的概念、原理、应用场......
  • Hudi-FlinkSQL导入数据报错:[ERROR] Could not execute SQL statement. Reason: java.l
    问题描述通过FlinkSQL创建Hudi表后,向表中插入数据报错:[ERROR]CouldnotexecuteSQLstatement.Reason:java.lang.ClassNotFoundException:org.apache.hadoop.fs.FSDataInputStream 解决办法向Hudi表中写入数据时,会调用Hadoop的Jar包,但是Flink的lib目录中没有该Jar包。......
  • 导入gateway运行失败错误解决
    报错如上图所示。原因:由于gateway项目的pom文件中导入了common(自定义的模块)依赖,而common的pom文件中有mybatis-plus配置,因此,mybatis-plus这个包也被引入了gateway项目中,由于mybatis-plus会读取配置文件中关于数据源的配置信息,然而gateway暂时用不到数据源,因此配置文件中没有数......
  • Docker镜像拉取总结
    flanneldockerpullquay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64dockertagquay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64quay.io/coreos/flannel:v0.11.0-amd64dockerrmiquay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64tillerdockerpull......