runc是docker等运行时使用的基础库,以命令行方式使用,用于创建符合OCI规范的容器。
本篇文章介绍如何在Goland中步步调试runc, 以利于理解runc如何通过namespace和cgroup实现容器的过程。
编译 & 测试
编译
根据git: https://github.com/opencontainers/runc.git
README.md给出文档的编译runc.
测试
制作容器根目录
# create the top most bundle directory
mkdir /mycontainer
cd /mycontainer
# create the rootfs directory
mkdir rootfs
# export busybox via Docker into the rootfs directory
docker export $(docker create busybox) | tar -C rootfs -xvf -
生成spec文件 config.json
:
runc spec
以上操作完成后,其文件结构为:
$ pwd /root/container-playground $ ls rootfs config.json
启动程序
runc run -b /root/container-playground mycontainerid
Goland调试
- Choose the
Go Build
- Debug Configuration
- Run Kind: Package
- Go Tool arguments:
-i -trimpath "-buildmode=pie" -tags "seccomp urfave_cli_no_docs" -ldflags "-X main.gitCommit= -X main.version=1.1.0+dev "
- Program arguments:
run -b /root/container-playground mycontainerid
- Debug by step
做完上面的步骤就可以直接在goland里,一步步调试runc了,开始卷源码吧!骚年!