环境准备
- 编译移植需要安装git、go、containerd、docker、libseccomp-dev等工具。
编译runc
- runc版本v1.0.0-rc93
- 如果在sw6a或者sw6b上编译,可使用我们内部runc源码的master分支,master分支代码是基于sw6a做了改动,目前只适用于sw上的编译。
- 如果想要在其他架构上编译,可去github获取runc源码,github源码位置:https://github.com/opencontainers/runc/tree/v1.0.0-rc95。
1、下载源码到本地目录/home/deepin/go/src/github.com/runc下。
git clone https://gitlabwh.uniontech.com/wuhan/container/runc.git
2、添加对sw64的支持,找到如下代码段,添加sw64字样。
vim runc/Makefile
ifeq ($(shell $(GO) env GOOS),linux) ifeq (,$(filter $(shell $(GO) env GOARCH),mips mipsle mips64 mips64le ppc64 sw64)) GO_BUILDMODE := "-buildmode=pie" endif endif
3、在runc/目录下使用make命令编译runc,正常会在源码目录下生成runc二进制文件。
cd runc/ make
4、安装runc:使用sudo make install安装,会将二进制安装到/usr/local/sbin/目录中,之后需要将runc拷贝到/usr/sbin/目录下。
sudo cp /usr/local/sbin/runc /usr/sbin/runc
测试runc功能
docker pull harbor.sh.deepin.com/nonfree/busybox:uos mkdir -p /tmp/mycontainer/rootfs cd /tmp/mycontainer docker export $(docker create harbor.sh.deepin.com/nonfree/busybox:uos) | tar -C rootfs -xvf - runc spec runc list runc run mybusybox
常见问题及处理办法
1、在使用runc create busybox命令创建容器时,如果出现下面错误信息,修改config.json中的terminal参数值为false即可。
ERROR[0000] cannot allocate tty if runc will detach without setting console socket cannot allocate tty if runc will detach without setting console socket
2、下图错误是因为部分go文件未添加对申威架构支持。
libcontainer/init_linux.go:319:12: undefined: system.Setgid libcontainer/init_linux.go:322:12: undefined: system.Setuid make: *** [Makefile:34:runc] 错误 2
解决办法可使用下列命令检索哪些go文件需要添加对申威的支持,可参考mips架构的字样添加申威支持。
# grep mips64 * -R | grep -v unix # grep mips64 * -iR | grep -v unix | grep -v test | grep -v ptr_
3、编译前需要安装libseccomp-dev,否则编译会报错Package 'libseccomp',required by 'virtual:world',not found.
sudo apt-get install libseccomp-dev
https://xpanx.com/
评论