yum install -y golang
[root@hy runc]# go version
go version go1.15 linux/amd64
GOPATH
,当使用build和get命令时,GOPATH
环境变量决定了go工具的查找路径,因此如果需要更改环境为个人的工作目录,首先通过如下命令查看go的环境变量:go env
export GOPATH="/path/to/mygopath"
go get github.com/opencontainers/runc
$GOPATH/src/github.com/opencontainers/runc
目录下,另一种方法是直接通过git工具克隆代码,如下:cd $GOPATH/src/github.com/opencontainers
git clone https://github.com/opencontainers/runc
$GOPATH/src/github.com/opencontainers/runc
目录下,编译并安装runc,命令如下:cd $GOPATH/src/github.com/opencontainers/runc
make
make install
[root@hy ~]# whereis runc
runc: /usr/local/sbin/runc
[root@hy ~]# runc -v
runc version 1.0.0-rc92+dev
commit: 33faa5d0e2404aaf4ceb1abbfe36c5135179d32f
spec: 1.0.2-dev
go: go1.15
libseccomp: 2.3.1
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache -c /etc/yum.repos.d/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
docker version
Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:03:45 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:21 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc92+dev
GitCommit: 33faa5d0e2404aaf4ceb1abbfe36c5135179d32f
docker-init:
Version: 0.18.0
GitCommit: fec3683
docker create busybox
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 6858809bf669 2 weeks ago 1.23MB
[root@PC-Hyman containerd]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7e726e36d1a busybox "sh" 26 hours ago Created stoic_noyce
[root@PC-Hyman containerd]# docker export c7e726e36d1a -o busybox.tar
tar busybox.tar -C busyboxfs
[root@PC-Hyman ~]# runc state 1234
{
"ociVersion": "1.0.2-dev",
"id": "1234",
"pid": 267441,
"status": "created",
"bundle": "/home/ubuntuVM/containerd/demo/runc",
"rootfs": "/home/ubuntuVM/containerd/demo/runc/busyboxfs",
"created": "2020-09-24T07:58:46.28138205Z",
"owner": ""
}
"env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"TERM=xterm"
],
"mounts": [
{
"destination": "/dev/pts",
"type": "devpts",
"source": "devpts",
"options": [
"nosuid",
"noexec",
"newinstance",
"ptmxmode=0666",
"mode=0620",
"gid=5"
]
}
]
/ # env
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/ # mount |grep pts
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
create <container-id> <path-to-bundle>
[root@PC-Hyman runc]# ls /home/ubuntuVM/containerd/demo/runc
busyboxfs config.json
[root@PC-Hyman demo]# pwd
/home/ubuntuVM/containerd/demo
[root@PC-Hyman demo]# ls
containerd-1.4.1 main main.go runc tools v1.4.1.zip
[root@PC-Hyman demo]# runc create 12345
ERRO[0000] JSON specification file config.json not found
[root@PC-Hyman demo]# runc create 12345 -b /home/ubuntuVM/containerd/demo/runc
[root@PC-Hyman demo]# runc list
ID PID STATUS BUNDLE CREATED OWNER
12345 262814 created /home/ubuntuVM/containerd/demo/runc 2020-09-24T02:23:23.388415943Z root
start <container-id>
kill <container-id> <signal>
delete <container-id>
"root": {
"path": "busyboxfs", /* 相对bundle的路径 */
"readonly": true /* 根文件系统只读 */
},
"mounts": [
{
"destination": "/proc", /* 对应挂载点:proc on /proc type proc (rw,relatime) */
"type": "proc",
"source": "proc"
},
{
"destination": "/dev", /* 对应挂载点:tmpfs on /dev type tmpfs (rw,nosuid,size=65536k,mode=755) */
"type": "tmpfs",
"source": "tmpfs",
"options": [
"nosuid",
"strictatime",
"mode=755",
"size=65536k"
]
},
....
}