1. # create the top most bundle directory
    2. mkdir /mycontainer
    3. cd /mycontainer
    4. # create the rootfs directory
    5. mkdir rootfs
    6. # export busybox via Docker into the rootfs directory
    7. docker export $(docker create busybox) | tar -C rootfs -xvf -
    1. [root@node02 mycontainer]# ll
    2. total 0
    3. drwxr-xr-x. 12 root root 137 May 28 09:05 rootfs
    4. [root@node02 mycontainer]# runc spec
    5. [root@node02 mycontainer]# ll
    6. total 4
    7. -rw-r--r--. 1 root root 2652 May 28 09:05 config.json
    8. drwxr-xr-x. 12 root root 137 May 28 09:05 rootfs
    9. [root@node02 mycontainer]# runc run mycontainerid
    10. / # ps -ef
    11. PID USER TIME COMMAND
    12. 1 root 0:00 sh
    13. 7 root 0:00 ps -ef
    14. / # exit
    15. [root@node02 mycontainer]# runc list
    16. ID PID STATUS BUNDLE CREATED OWNER

    如果你使用未修改的runc规范模板,这应该会在容器内给你一个sh会话。
    启动容器的第二种方法是使用spec生命周期操作。这为您提供了在容器运行时如何创建和管理容器的更多权力。这也将在后台启动容器,因此您必须编辑配置。Json来删除下面简单示例的终端设置(参见runc终端处理的更多细节)。配置中的流程字段。Json应该如下所示,带有”terminal”: false和”args”: [“sleep”, “5”]。

    1. [root@node02 mycontainer]# vim config.json
    2. [root@node02 mycontainer]# runc create mycontainerid
    3. [root@node02 mycontainer]#
    4. [root@node02 mycontainer]# runc list
    5. ID PID STATUS BUNDLE CREATED OWNER
    6. mycontainerid 595088 created /root/liang/runc/test/mycontainer 2021-05-28T01:07:45.725027405Z root
    1. [root@node02 mycontainer]# runc start mycontainerid
    2. [root@node02 mycontainer]# runc list
    3. ID PID STATUS BUNDLE CREATED OWNER
    4. mycontainerid 595088 running /root/liang/runc/test/mycontainer 2021-05-28T01:07:45.725027405Z root
    5. [root@node02 mycontainer]# runc exec mycontainerid ls
    6. bin
    7. dev
    8. etc
    9. home
    10. proc
    11. root
    12. sys
    13. tmp
    14. usr
    15. var
    16. [root@node02 mycontainer]# runc exec mycontainerid ps -ef
    17. PID USER TIME COMMAND
    18. 1 root 0:00 sleep 50000
    19. 13 root 0:00 ps -ef
    1. [root@node02 mycontainer]# runc pause mycontainerid
    2. [root@node02 mycontainer]# runc list
    3. ID PID STATUS BUNDLE CREATED OWNER
    4. mycontainerid 595088 paused /root/liang/runc/test/mycontainer 2021-05-28T01:07:45.725027405Z root
    5. [root@node02 mycontainer]# runc resume mycontainerid
    6. [root@node02 mycontainer]# runc list
    7. ID PID STATUS BUNDLE CREATED OWNER
    8. mycontainerid 595088 running /root/liang/runc/test/mycontainer 2021-05-28T01:07:45.725027405Z root
    9. [root@node02 mycontainer]#
    1. [root@node02 mycontainer]# runc state mycontainerid
    2. {
    3. "ociVersion": "1.0.1-dev",
    4. "id": "mycontainerid",
    5. "pid": 595088,
    6. "status": "running",
    7. "bundle": "/root/liang/runc/test/mycontainer",
    8. "rootfs": "/root/liang/runc/test/mycontainer/rootfs",
    9. "created": "2021-05-28T01:07:45.725027405Z",
    10. "owner": ""
    11. }
    1. [root@node02 mycontainer]# runc kill mycontainerid 9
    2. [root@node02 mycontainer]# runc list
    3. ID PID STATUS BUNDLE CREATED OWNER
    4. mycontainerid 0 stopped /root/liang/runc/test/mycontainer 2021-05-28T01:07:45.725027405Z root
    5. [root@node02 mycontainer]# runc delete mycontainerid
    1. [root@node02 mycontainer]# /usr/bin/runc spec
    2. [root@node02 mycontainer]# runc run mycontainerid
    3. / # ps -ef
    4. PID USER TIME COMMAND
    5. 1 root 0:00 sh
    6. 8 root 0:00 ps -ef