「这是我参与11月更文挑战的第4天,活动详情查看:2021最后一次更文挑战」。
我相信你肯定知道 helloworld,其在所有编程语言中都是最经典的入门示例。当然 Docker 也不例外。
启动 helloworld 容器
启动容器使用 docker run 命令,具体用法 docker run --help 可以查看。
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...
启动 hello-world:
分析
首先,执行 docker run hello-world就可以启动 hell-world 容器,但是因为我们本地没有 hello-world 的镜像,所以 docker 自动从远端仓库进行搜索下载了 hello-world 镜像。
查看拉取下来的 hello-world 镜像
root@phyger-VirtualBox:/home/phyger# docker images | grep hello
hello-world latest bf756fb1ae65 5 months ago 13.3kB
root@phyger-VirtualBox:/home/phyger#
我们发现这个镜像只有 13.3kB,特别小,但是它是一个完整的 Docker 容器镜像。
然后,Docker 使用 hello-world 镜像启动了 hello-world 容器,并且打印出了 Hello from Docker!
Hello from Docker!
This message shows that your installation appears to be working correctly
最后容器运行结束,打印出了容器的整个启动过程。
查看运行结束的容器:
root@phyger-VirtualBox:/home/phyger# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3d23ead2fc6 hello-world "/hello" 6 seconds ago Exited (0) 4 seconds ago sharp_sinoussi
root@phyger-VirtualBox:/home/phyger#
为什么这个容器运行完之后的状态是 Exited 呢?下篇继续~
容器运行原理图
containerd 的安装使用
安装
下载包
wget https://github.com/containerd/containerd/releases/download/v1.5.7/cri-containerd-cni-1.5.7-linux-amd64.tar.gz
tar -zxvf cri-containerd-cni-1.5.7-linux-amd64.tar.gz
删除不必要的文件
rm -rf etc/cni
rm -rf opt
启动 containerd
ystemctl status containerd
systemctl enable containerd
systemctl restart containerd
生成默认配置文件
containerd config default > /etc/containerd/config.toml
修改配置文件:oom_score = -999
启动 HelloWorld 容器
由于 containerd 默认不会从 docker 的仓库拉取镜像,所以我们指定源来进行操作。
ctr i pull docker.io/library/hello-world:latest
ctr run -d -t docker.io/library/hello-world:latest
查看启动的 hello-world 容器:
ctr c ls
更多命令使用
ctr --help查看。