[英]How to run docker images in containerd using ctr in CLI?
Am exploring on how to use containerd
in place of dockerd.我正在探索如何使用containerd
代替 dockerd。 This is for learning only and as a cli tool rather than with any pipelines or automation.这仅用于学习和作为 cli 工具,而不是任何管道或自动化。
So far, documentation in regards to using containerd in cli (via ctr
) is very limited.到目前为止,关于在 cli(通过ctr
)中使用 containerd 的文档非常有限。 Even the official docs are using Go lang to utilize containerd
directly.甚至官方文档也在使用 Go lang 来直接使用containerd
。
What I have learnt is ctr
command plays the role of docker
command to control containerd
.我的心得是ctr
命令扮演的角色docker
命令来控制containerd
。 I have thus far created a docker image and exported it to .tar format.到目前为止,我已经创建了一个 docker 映像并将其导出为 .tar 格式。 Now using ctr i import hello.tar
I have imported it as an image.现在使用ctr i import hello.tar
我已将其作为图像导入。
Now ctr i ls
gives me the following output:现在ctr i ls
给了我以下输出:
REF TYPE DIGEST SIZE PLATFORMS LABELS
docker.io/library/hello-java-app:latest application/vnd.oci.image.manifest.v1+json sha256:ef4acfd85c856ea020328959ff3cac23f37fa639b7edfb1691619d9bfe1e06c7 628.7 MiB linux/amd64 -
Trying to run a container asks me for the image id:尝试运行容器要求我提供图像 ID:
root@slave-node:~/images/sample# ctr run
ctr: image ref must be provided
root@slave-node:~/images/sample# ctr run docker.io/library/hello-java-app:latest
ctr: container id must be provided
I am not sure on where to get the image id from.我不确定从哪里获取图像 ID。 Are there any docs related to ctr
or containerd
that could be helpful for a beginner?是否有任何与ctr
或containerd
相关的文档对初学者有帮助?
Just running the image as a container would be sufficient for me.仅将图像作为容器运行对我来说就足够了。
The ctr run
command creates a container and executes it ctr run
命令创建一个容器并执行它
ctr run <imageName> <uniqueValue>
eg, ctr run docker.io/library/hello-java-app:latest v1 --rm例如,ctr 运行 docker.io/library/hello-java-app:latest v1 --rm
This executes my basic docker java image with a print statement:这将使用打印语句执行我的基本 docker java 图像:
~~~~
HelloWorld from Java Application running in Docker.
~~~~
Steps followed:步骤如下:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("~~~~\nHelloWorld from Java Application running in Docker.\n~~~~");
}
}
FROM java:8
COPY HelloWorld.java .
RUN javac HelloWorld.java
CMD ["java", "HelloWorld"]
docker build -t hello-java-app .
docker save -o ~/images/sample/hello-java-app.tar hello-java-app
ctr i import hello-java-app.tar
unpacking docker.io/library/hello-java-app:latest (sha256:ef4acfd85c856ea020328959ff3cac23f37fa639b7edfb1691619d9bfe1e06c7)...done
ctr i ls
REF TYPE DIGEST SIZE PLATFORMS LABELS
docker.io/library/hello-java-app:latest application/vnd.oci.image.manifest.v1+json sha256:ef4acfd85c856ea020328959ff3cac23f37fa639b7edfb1691619d9bfe1e06c7 628.7 MiB linux/amd64 -
ctr run docker.io/library/hello-java-app:latest v1 --rm
~~~~
HelloWorld from Java Application running in Docker.
~~~~
I am still unsure of the use of creating a container.我仍然不确定创建容器的用途。 The run command creates a container and executes it once. run 命令创建一个容器并执行一次。
ctr c create
just creates a container which can then be listed withctr c ls
but I am not able to utilize them in any meaningful way.ctr c create
只是创建一个容器,然后可以用ctr c ls
列出它,但我无法以任何有意义的方式利用它们。 Can anyone clarify its purpose?任何人都可以澄清其目的吗?
PS: Without the --rm flag, a new unique value is needed to be entered for every run
as the old container is retained and we get an error: ctr: snapshot "v1": already exists
PS:如果没有 --rm 标志,每次run
都需要输入一个新的唯一值,因为旧容器被保留,我们得到一个错误: ctr: snapshot "v1": already exists
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.