Skip to content

Latest commit

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Runcell 使用文档

Runcell 是一个参照 rustjail 实现的轻量级容器运行时,支持容器的创建、运行和管理。

功能特性

  • 容器生命周期管理: 创建、启动、停止、删除容器
  • 容器列表查看: 列出所有运行中或已停止的容器
  • 容器内执行命令: 类似 docker exec 进入运行中的容器执行命令
  • 交互式终端支持: 支持 -it 参数进行交互式操作
  • 状态持久化: 容器状态保存到磁盘,支持跨进程查询
  • Namespace 隔离: 支持 PID、Mount、UTS、IPC、Network 等命名空间隔离
  • Cgroup 资源限制: 支持 CPU、内存等资源限制

构建

cargo build

基础用法

容器管理命令

提示container 命令可以使用别名 ctr

运行容器

创建并启动一个容器:

sudo ./target/debug/runcell ctr run \
--id <容器ID> \
--image <镜像路径> \
[命令] [参数...]

示例:

# 运行一个 sleep 进程的容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 交互式运行容器(类似 docker run -it)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 后台运行容器(类似 docker run -d)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-d \
/bin/sleep 3600
# 使用 file:// 协议拉取 tar 镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image file:///path/to/rootfs.tar \
/bin/sh
# 使用 dir:// 协议使用目录镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image dir:///path/to/bundle \
/bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--image-m镜像源,支持 file://dir:// 或本地路径
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
--detach-d后台运行(分离模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

列出容器

列出所有容器(支持别名 ls):

# 列出运行中的容器
sudo ./target/debug/runcell ctr ls
# 列出所有容器(包括已停止的)
sudo ./target/debug/runcell ctr ls --all
# JSON 格式输出
sudo ./target/debug/runcell ctr ls --format json

输出示例:

CONTAINER ID PID STATUS CREATED ROOTFS
test 12345 Running 2025-12-20 10:30:00 /tmp/runcell/containers/test/rootfs
mycontainer 0 Stopped 2025-12-20 09:00:00 /tmp/runcell/containers/mycontainer/rootfs

参数说明:

参数简写说明
--format-f输出格式:table(默认)或 json
--all-a显示所有容器(包括已停止的)

在容器内执行命令

在运行中的容器内执行命令(类似 docker exec):

# 执行单个命令
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
[命令] [参数...]
# 交互式进入容器
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
-t -i \
/bin/sh

示例:

# 在容器内执行 ls 命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 在容器内执行带参数的命令
sudo ./target/debug/runcell ctr exec --id test /bin/cat /etc/os-release
# 交互式进入容器的 shell
sudo ./target/debug/runcell ctr exec --id test -t -i /bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

删除容器

支持别名 rm

sudo ./target/debug/runcell ctr rm --id <容器ID>

删除操作会:

  1. 读取容器状态获取 PID
  2. 如果进程仍在运行,发送 SIGKILL 信号终止
  3. 清理 bundle 目录
  4. 清理状态目录
  5. 清理镜像文件

示例:

sudo ./target/debug/runcell ctr rm --id test

创建容器(仅创建,不启动)

sudo ./target/debug/runcell ctr create \
--id <容器ID> \
--rootfs <rootfs路径> \
[--bundle <bundle目录>]

启动容器

sudo ./target/debug/runcell ctr start --id <容器ID>

存储管理命令

拉取镜像

sudo ./target/debug/runcell storage pull \
--image <镜像源> \
--container-id <容器ID>

挂载

sudo ./target/debug/runcell storage mount \
--source <源路径> \
--target <目标路径> \
--options <挂载选项>

卸载

sudo ./target/debug/runcell storage umount --target <挂载点>

清理镜像

sudo ./target/debug/runcell storage cleanup --container-id <容器ID>

完整示例

示例 1:基础容器操作

# 1. 构建项目
cargo build
# 2. 运行容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 3. 查看容器列表
sudo ./target/debug/runcell ctr ls
# 4. 在容器内执行命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 5. 删除容器
sudo ./target/debug/runcell ctr rm --id test

示例 2:交互式容器

# 1. 启动交互式容器
sudo ./target/debug/runcell ctr run \
--id interactive-test \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 2. 在另一个终端查看容器
sudo ./target/debug/runcell ctr ls
# 3. 在另一个终端进入同一容器
sudo ./target/debug/runcell ctr exec \
--id interactive-test \
-t -i \
/bin/sh
# 4. 退出后删除容器
sudo ./target/debug/runcell ctr rm --id interactive-test

状态持久化

容器状态保存在 state.json 文件中,位于 /tmp/runcell/states/<容器ID>/state.json

状态文件格式:

{
"id": "test",
"init_process_pid": 12345,
"init_process_start_time": 1734567890,
"status": "Running",
"bundle": "/tmp/runcell/bundles/test",
"rootfs": "/tmp/runcell/containers/test/rootfs",
"created": 1734567880,
"namespace_paths": {
"mnt": "/proc/12345/ns/mnt",
"pid": "/proc/12345/ns/pid",
"net": "/proc/12345/ns/net",
"ipc": "/proc/12345/ns/ipc",
"uts": "/proc/12345/ns/uts"
}
}

查看容器进程

sudo ps aux | grep -E "sleep|runcell"| grep -v grep

手动进入容器命名空间

使用 nsenter 进入容器的命名空间:

# 先获取容器进程 PID
sudo ./target/debug/runcell ctr ls
# 使用 nsenter 进入容器执行命令
sudo nsenter -t <PID> -m -p -u -i -n <命令>

nsenter 参数说明:

参数说明
-t <PID>目标进程 PID
-m进入 mount 命名空间
-p进入 PID 命名空间
-u进入 UTS 命名空间
-i进入 IPC 命名空间
-n进入 network 命名空间

调试与日志

日志级别控制

Runcell 默认日志级别为 WARN。你可以通过 -v 标志或 RUNCELL_LOG 环境变量来调整:

# 使用 -v 开启 Debug 级别日志
sudo ./target/debug/runcell -v ctr run --id test --image /path/to/rootfs
# 通过环境变量指定级别 (trace, debug, info, warn, error)
sudo RUNCELL_LOG=debug ./target/debug/runcell ctr run --id test --image /path/to/rootfs

日志级别优先级-v/--verbose 标志 > RUNCELL_LOG 环境变量 > 默认 warn

数据目录

目录说明
/tmp/runcell/bundles/<容器ID>OCI bundle 目录,包含 config.json
/tmp/runcell/states/<容器ID>容器状态目录,包含 state.json
/tmp/runcell/containers/<容器ID>容器镜像目录

依赖项

如果你要使用 seccomp 的话,确保本机已安装 libseccomp:

sudo apt update && sudo apt install libseccomp-dev

命令速查表

命令别名说明
container runctr run创建并运行容器
container listctr ls列出容器
container execctr exec在容器内执行命令
container deletectr rm删除容器
container createctr create创建容器(不启动)
container startctr start启动已创建的容器
storage pull-拉取镜像
storage mount-挂载存储
storage umount-卸载存储
storage cleanup-清理镜像

与 Docker 命令对比

DockerRuncell (推荐写法)
docker run -it imageruncell ctr run -m image -t -i /bin/sh
docker run -d image cmdruncell ctr run -m image -d cmd
docker psruncell ctr ls
docker ps -aruncell ctr ls --all
docker exec -it container cmdruncell ctr exec --id container -t -i cmd
docker rm containerruncell ctr rm --id container

About

参考rustjail的容器运行时

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - DragonOS-Community/runcell: 参考rustjail的容器运行时 · GitHub
Skip to content

Latest commit

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Runcell 使用文档

Runcell 是一个参照 rustjail 实现的轻量级容器运行时,支持容器的创建、运行和管理。

功能特性

  • 容器生命周期管理: 创建、启动、停止、删除容器
  • 容器列表查看: 列出所有运行中或已停止的容器
  • 容器内执行命令: 类似 docker exec 进入运行中的容器执行命令
  • 交互式终端支持: 支持 -it 参数进行交互式操作
  • 状态持久化: 容器状态保存到磁盘,支持跨进程查询
  • Namespace 隔离: 支持 PID、Mount、UTS、IPC、Network 等命名空间隔离
  • Cgroup 资源限制: 支持 CPU、内存等资源限制

构建

cargo build

基础用法

容器管理命令

提示container 命令可以使用别名 ctr

运行容器

创建并启动一个容器:

sudo ./target/debug/runcell ctr run \
--id <容器ID> \
--image <镜像路径> \
[命令] [参数...]

示例:

# 运行一个 sleep 进程的容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 交互式运行容器(类似 docker run -it)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 后台运行容器(类似 docker run -d)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-d \
/bin/sleep 3600
# 使用 file:// 协议拉取 tar 镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image file:///path/to/rootfs.tar \
/bin/sh
# 使用 dir:// 协议使用目录镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image dir:///path/to/bundle \
/bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--image-m镜像源,支持 file://dir:// 或本地路径
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
--detach-d后台运行(分离模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

列出容器

列出所有容器(支持别名 ls):

# 列出运行中的容器
sudo ./target/debug/runcell ctr ls
# 列出所有容器(包括已停止的)
sudo ./target/debug/runcell ctr ls --all
# JSON 格式输出
sudo ./target/debug/runcell ctr ls --format json

输出示例:

CONTAINER ID PID STATUS CREATED ROOTFS
test 12345 Running 2025-12-20 10:30:00 /tmp/runcell/containers/test/rootfs
mycontainer 0 Stopped 2025-12-20 09:00:00 /tmp/runcell/containers/mycontainer/rootfs

参数说明:

参数简写说明
--format-f输出格式:table(默认)或 json
--all-a显示所有容器(包括已停止的)

在容器内执行命令

在运行中的容器内执行命令(类似 docker exec):

# 执行单个命令
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
[命令] [参数...]
# 交互式进入容器
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
-t -i \
/bin/sh

示例:

# 在容器内执行 ls 命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 在容器内执行带参数的命令
sudo ./target/debug/runcell ctr exec --id test /bin/cat /etc/os-release
# 交互式进入容器的 shell
sudo ./target/debug/runcell ctr exec --id test -t -i /bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

删除容器

支持别名 rm

sudo ./target/debug/runcell ctr rm --id <容器ID>

删除操作会:

  1. 读取容器状态获取 PID
  2. 如果进程仍在运行,发送 SIGKILL 信号终止
  3. 清理 bundle 目录
  4. 清理状态目录
  5. 清理镜像文件

示例:

sudo ./target/debug/runcell ctr rm --id test

创建容器(仅创建,不启动)

sudo ./target/debug/runcell ctr create \
--id <容器ID> \
--rootfs <rootfs路径> \
[--bundle <bundle目录>]

启动容器

sudo ./target/debug/runcell ctr start --id <容器ID>

存储管理命令

拉取镜像

sudo ./target/debug/runcell storage pull \
--image <镜像源> \
--container-id <容器ID>

挂载

sudo ./target/debug/runcell storage mount \
--source <源路径> \
--target <目标路径> \
--options <挂载选项>

卸载

sudo ./target/debug/runcell storage umount --target <挂载点>

清理镜像

sudo ./target/debug/runcell storage cleanup --container-id <容器ID>

完整示例

示例 1:基础容器操作

# 1. 构建项目
cargo build
# 2. 运行容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 3. 查看容器列表
sudo ./target/debug/runcell ctr ls
# 4. 在容器内执行命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 5. 删除容器
sudo ./target/debug/runcell ctr rm --id test

示例 2:交互式容器

# 1. 启动交互式容器
sudo ./target/debug/runcell ctr run \
--id interactive-test \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 2. 在另一个终端查看容器
sudo ./target/debug/runcell ctr ls
# 3. 在另一个终端进入同一容器
sudo ./target/debug/runcell ctr exec \
--id interactive-test \
-t -i \
/bin/sh
# 4. 退出后删除容器
sudo ./target/debug/runcell ctr rm --id interactive-test

状态持久化

容器状态保存在 state.json 文件中,位于 /tmp/runcell/states/<容器ID>/state.json

状态文件格式:

{
"id": "test",
"init_process_pid": 12345,
"init_process_start_time": 1734567890,
"status": "Running",
"bundle": "/tmp/runcell/bundles/test",
"rootfs": "/tmp/runcell/containers/test/rootfs",
"created": 1734567880,
"namespace_paths": {
"mnt": "/proc/12345/ns/mnt",
"pid": "/proc/12345/ns/pid",
"net": "/proc/12345/ns/net",
"ipc": "/proc/12345/ns/ipc",
"uts": "/proc/12345/ns/uts"
}
}

查看容器进程

sudo ps aux | grep -E "sleep|runcell"| grep -v grep

手动进入容器命名空间

使用 nsenter 进入容器的命名空间:

# 先获取容器进程 PID
sudo ./target/debug/runcell ctr ls
# 使用 nsenter 进入容器执行命令
sudo nsenter -t <PID> -m -p -u -i -n <命令>

nsenter 参数说明:

参数说明
-t <PID>目标进程 PID
-m进入 mount 命名空间
-p进入 PID 命名空间
-u进入 UTS 命名空间
-i进入 IPC 命名空间
-n进入 network 命名空间

调试与日志

日志级别控制

Runcell 默认日志级别为 WARN。你可以通过 -v 标志或 RUNCELL_LOG 环境变量来调整:

# 使用 -v 开启 Debug 级别日志
sudo ./target/debug/runcell -v ctr run --id test --image /path/to/rootfs
# 通过环境变量指定级别 (trace, debug, info, warn, error)
sudo RUNCELL_LOG=debug ./target/debug/runcell ctr run --id test --image /path/to/rootfs

日志级别优先级-v/--verbose 标志 > RUNCELL_LOG 环境变量 > 默认 warn

数据目录

目录说明
/tmp/runcell/bundles/<容器ID>OCI bundle 目录,包含 config.json
/tmp/runcell/states/<容器ID>容器状态目录,包含 state.json
/tmp/runcell/containers/<容器ID>容器镜像目录

依赖项

如果你要使用 seccomp 的话,确保本机已安装 libseccomp:

sudo apt update && sudo apt install libseccomp-dev

命令速查表

命令别名说明
container runctr run创建并运行容器
container listctr ls列出容器
container execctr exec在容器内执行命令
container deletectr rm删除容器
container createctr create创建容器(不启动)
container startctr start启动已创建的容器
storage pull-拉取镜像
storage mount-挂载存储
storage umount-卸载存储
storage cleanup-清理镜像

与 Docker 命令对比

DockerRuncell (推荐写法)
docker run -it imageruncell ctr run -m image -t -i /bin/sh
docker run -d image cmdruncell ctr run -m image -d cmd
docker psruncell ctr ls
docker ps -aruncell ctr ls --all
docker exec -it container cmdruncell ctr exec --id container -t -i cmd
docker rm containerruncell ctr rm --id container

About

参考rustjail的容器运行时

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - DragonOS-Community/runcell: 参考rustjail的容器运行时 · GitHub
Skip to content

Latest commit

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Runcell 使用文档

Runcell 是一个参照 rustjail 实现的轻量级容器运行时,支持容器的创建、运行和管理。

功能特性

  • 容器生命周期管理: 创建、启动、停止、删除容器
  • 容器列表查看: 列出所有运行中或已停止的容器
  • 容器内执行命令: 类似 docker exec 进入运行中的容器执行命令
  • 交互式终端支持: 支持 -it 参数进行交互式操作
  • 状态持久化: 容器状态保存到磁盘,支持跨进程查询
  • Namespace 隔离: 支持 PID、Mount、UTS、IPC、Network 等命名空间隔离
  • Cgroup 资源限制: 支持 CPU、内存等资源限制

构建

cargo build

基础用法

容器管理命令

提示container 命令可以使用别名 ctr

运行容器

创建并启动一个容器:

sudo ./target/debug/runcell ctr run \
--id <容器ID> \
--image <镜像路径> \
[命令] [参数...]

示例:

# 运行一个 sleep 进程的容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 交互式运行容器(类似 docker run -it)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 后台运行容器(类似 docker run -d)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-d \
/bin/sleep 3600
# 使用 file:// 协议拉取 tar 镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image file:///path/to/rootfs.tar \
/bin/sh
# 使用 dir:// 协议使用目录镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image dir:///path/to/bundle \
/bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--image-m镜像源,支持 file://dir:// 或本地路径
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
--detach-d后台运行(分离模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

列出容器

列出所有容器(支持别名 ls):

# 列出运行中的容器
sudo ./target/debug/runcell ctr ls
# 列出所有容器(包括已停止的)
sudo ./target/debug/runcell ctr ls --all
# JSON 格式输出
sudo ./target/debug/runcell ctr ls --format json

输出示例:

CONTAINER ID PID STATUS CREATED ROOTFS
test 12345 Running 2025-12-20 10:30:00 /tmp/runcell/containers/test/rootfs
mycontainer 0 Stopped 2025-12-20 09:00:00 /tmp/runcell/containers/mycontainer/rootfs

参数说明:

参数简写说明
--format-f输出格式:table(默认)或 json
--all-a显示所有容器(包括已停止的)

在容器内执行命令

在运行中的容器内执行命令(类似 docker exec):

# 执行单个命令
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
[命令] [参数...]
# 交互式进入容器
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
-t -i \
/bin/sh

示例:

# 在容器内执行 ls 命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 在容器内执行带参数的命令
sudo ./target/debug/runcell ctr exec --id test /bin/cat /etc/os-release
# 交互式进入容器的 shell
sudo ./target/debug/runcell ctr exec --id test -t -i /bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

删除容器

支持别名 rm

sudo ./target/debug/runcell ctr rm --id <容器ID>

删除操作会:

  1. 读取容器状态获取 PID
  2. 如果进程仍在运行,发送 SIGKILL 信号终止
  3. 清理 bundle 目录
  4. 清理状态目录
  5. 清理镜像文件

示例:

sudo ./target/debug/runcell ctr rm --id test

创建容器(仅创建,不启动)

sudo ./target/debug/runcell ctr create \
--id <容器ID> \
--rootfs <rootfs路径> \
[--bundle <bundle目录>]

启动容器

sudo ./target/debug/runcell ctr start --id <容器ID>

存储管理命令

拉取镜像

sudo ./target/debug/runcell storage pull \
--image <镜像源> \
--container-id <容器ID>

挂载

sudo ./target/debug/runcell storage mount \
--source <源路径> \
--target <目标路径> \
--options <挂载选项>

卸载

sudo ./target/debug/runcell storage umount --target <挂载点>

清理镜像

sudo ./target/debug/runcell storage cleanup --container-id <容器ID>

完整示例

示例 1:基础容器操作

# 1. 构建项目
cargo build
# 2. 运行容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 3. 查看容器列表
sudo ./target/debug/runcell ctr ls
# 4. 在容器内执行命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 5. 删除容器
sudo ./target/debug/runcell ctr rm --id test

示例 2:交互式容器

# 1. 启动交互式容器
sudo ./target/debug/runcell ctr run \
--id interactive-test \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 2. 在另一个终端查看容器
sudo ./target/debug/runcell ctr ls
# 3. 在另一个终端进入同一容器
sudo ./target/debug/runcell ctr exec \
--id interactive-test \
-t -i \
/bin/sh
# 4. 退出后删除容器
sudo ./target/debug/runcell ctr rm --id interactive-test

状态持久化

容器状态保存在 state.json 文件中,位于 /tmp/runcell/states/<容器ID>/state.json

状态文件格式:

{
"id": "test",
"init_process_pid": 12345,
"init_process_start_time": 1734567890,
"status": "Running",
"bundle": "/tmp/runcell/bundles/test",
"rootfs": "/tmp/runcell/containers/test/rootfs",
"created": 1734567880,
"namespace_paths": {
"mnt": "/proc/12345/ns/mnt",
"pid": "/proc/12345/ns/pid",
"net": "/proc/12345/ns/net",
"ipc": "/proc/12345/ns/ipc",
"uts": "/proc/12345/ns/uts"
}
}

查看容器进程

sudo ps aux | grep -E "sleep|runcell"| grep -v grep

手动进入容器命名空间

使用 nsenter 进入容器的命名空间:

# 先获取容器进程 PID
sudo ./target/debug/runcell ctr ls
# 使用 nsenter 进入容器执行命令
sudo nsenter -t <PID> -m -p -u -i -n <命令>

nsenter 参数说明:

参数说明
-t <PID>目标进程 PID
-m进入 mount 命名空间
-p进入 PID 命名空间
-u进入 UTS 命名空间
-i进入 IPC 命名空间
-n进入 network 命名空间

调试与日志

日志级别控制

Runcell 默认日志级别为 WARN。你可以通过 -v 标志或 RUNCELL_LOG 环境变量来调整:

# 使用 -v 开启 Debug 级别日志
sudo ./target/debug/runcell -v ctr run --id test --image /path/to/rootfs
# 通过环境变量指定级别 (trace, debug, info, warn, error)
sudo RUNCELL_LOG=debug ./target/debug/runcell ctr run --id test --image /path/to/rootfs

日志级别优先级-v/--verbose 标志 > RUNCELL_LOG 环境变量 > 默认 warn

数据目录

目录说明
/tmp/runcell/bundles/<容器ID>OCI bundle 目录,包含 config.json
/tmp/runcell/states/<容器ID>容器状态目录,包含 state.json
/tmp/runcell/containers/<容器ID>容器镜像目录

依赖项

如果你要使用 seccomp 的话,确保本机已安装 libseccomp:

sudo apt update && sudo apt install libseccomp-dev

命令速查表

命令别名说明
container runctr run创建并运行容器
container listctr ls列出容器
container execctr exec在容器内执行命令
container deletectr rm删除容器
container createctr create创建容器(不启动)
container startctr start启动已创建的容器
storage pull-拉取镜像
storage mount-挂载存储
storage umount-卸载存储
storage cleanup-清理镜像

与 Docker 命令对比

DockerRuncell (推荐写法)
docker run -it imageruncell ctr run -m image -t -i /bin/sh
docker run -d image cmdruncell ctr run -m image -d cmd
docker psruncell ctr ls
docker ps -aruncell ctr ls --all
docker exec -it container cmdruncell ctr exec --id container -t -i cmd
docker rm containerruncell ctr rm --id container

About

参考rustjail的容器运行时

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - DragonOS-Community/runcell: 参考rustjail的容器运行时 · GitHub
Skip to content

Latest commit

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Runcell 使用文档

Runcell 是一个参照 rustjail 实现的轻量级容器运行时,支持容器的创建、运行和管理。

功能特性

  • 容器生命周期管理: 创建、启动、停止、删除容器
  • 容器列表查看: 列出所有运行中或已停止的容器
  • 容器内执行命令: 类似 docker exec 进入运行中的容器执行命令
  • 交互式终端支持: 支持 -it 参数进行交互式操作
  • 状态持久化: 容器状态保存到磁盘,支持跨进程查询
  • Namespace 隔离: 支持 PID、Mount、UTS、IPC、Network 等命名空间隔离
  • Cgroup 资源限制: 支持 CPU、内存等资源限制

构建

cargo build

基础用法

容器管理命令

提示container 命令可以使用别名 ctr

运行容器

创建并启动一个容器:

sudo ./target/debug/runcell ctr run \
--id <容器ID> \
--image <镜像路径> \
[命令] [参数...]

示例:

# 运行一个 sleep 进程的容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 交互式运行容器(类似 docker run -it)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 后台运行容器(类似 docker run -d)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-d \
/bin/sleep 3600
# 使用 file:// 协议拉取 tar 镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image file:///path/to/rootfs.tar \
/bin/sh
# 使用 dir:// 协议使用目录镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image dir:///path/to/bundle \
/bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--image-m镜像源,支持 file://dir:// 或本地路径
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
--detach-d后台运行(分离模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

列出容器

列出所有容器(支持别名 ls):

# 列出运行中的容器
sudo ./target/debug/runcell ctr ls
# 列出所有容器(包括已停止的)
sudo ./target/debug/runcell ctr ls --all
# JSON 格式输出
sudo ./target/debug/runcell ctr ls --format json

输出示例:

CONTAINER ID PID STATUS CREATED ROOTFS
test 12345 Running 2025-12-20 10:30:00 /tmp/runcell/containers/test/rootfs
mycontainer 0 Stopped 2025-12-20 09:00:00 /tmp/runcell/containers/mycontainer/rootfs

参数说明:

参数简写说明
--format-f输出格式:table(默认)或 json
--all-a显示所有容器(包括已停止的)

在容器内执行命令

在运行中的容器内执行命令(类似 docker exec):

# 执行单个命令
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
[命令] [参数...]
# 交互式进入容器
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
-t -i \
/bin/sh

示例:

# 在容器内执行 ls 命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 在容器内执行带参数的命令
sudo ./target/debug/runcell ctr exec --id test /bin/cat /etc/os-release
# 交互式进入容器的 shell
sudo ./target/debug/runcell ctr exec --id test -t -i /bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

删除容器

支持别名 rm

sudo ./target/debug/runcell ctr rm --id <容器ID>

删除操作会:

  1. 读取容器状态获取 PID
  2. 如果进程仍在运行,发送 SIGKILL 信号终止
  3. 清理 bundle 目录
  4. 清理状态目录
  5. 清理镜像文件

示例:

sudo ./target/debug/runcell ctr rm --id test

创建容器(仅创建,不启动)

sudo ./target/debug/runcell ctr create \
--id <容器ID> \
--rootfs <rootfs路径> \
[--bundle <bundle目录>]

启动容器

sudo ./target/debug/runcell ctr start --id <容器ID>

存储管理命令

拉取镜像

sudo ./target/debug/runcell storage pull \
--image <镜像源> \
--container-id <容器ID>

挂载

sudo ./target/debug/runcell storage mount \
--source <源路径> \
--target <目标路径> \
--options <挂载选项>

卸载

sudo ./target/debug/runcell storage umount --target <挂载点>

清理镜像

sudo ./target/debug/runcell storage cleanup --container-id <容器ID>

完整示例

示例 1:基础容器操作

# 1. 构建项目
cargo build
# 2. 运行容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 3. 查看容器列表
sudo ./target/debug/runcell ctr ls
# 4. 在容器内执行命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 5. 删除容器
sudo ./target/debug/runcell ctr rm --id test

示例 2:交互式容器

# 1. 启动交互式容器
sudo ./target/debug/runcell ctr run \
--id interactive-test \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 2. 在另一个终端查看容器
sudo ./target/debug/runcell ctr ls
# 3. 在另一个终端进入同一容器
sudo ./target/debug/runcell ctr exec \
--id interactive-test \
-t -i \
/bin/sh
# 4. 退出后删除容器
sudo ./target/debug/runcell ctr rm --id interactive-test

状态持久化

容器状态保存在 state.json 文件中,位于 /tmp/runcell/states/<容器ID>/state.json

状态文件格式:

{
"id": "test",
"init_process_pid": 12345,
"init_process_start_time": 1734567890,
"status": "Running",
"bundle": "/tmp/runcell/bundles/test",
"rootfs": "/tmp/runcell/containers/test/rootfs",
"created": 1734567880,
"namespace_paths": {
"mnt": "/proc/12345/ns/mnt",
"pid": "/proc/12345/ns/pid",
"net": "/proc/12345/ns/net",
"ipc": "/proc/12345/ns/ipc",
"uts": "/proc/12345/ns/uts"
}
}

查看容器进程

sudo ps aux | grep -E "sleep|runcell"| grep -v grep

手动进入容器命名空间

使用 nsenter 进入容器的命名空间:

# 先获取容器进程 PID
sudo ./target/debug/runcell ctr ls
# 使用 nsenter 进入容器执行命令
sudo nsenter -t <PID> -m -p -u -i -n <命令>

nsenter 参数说明:

参数说明
-t <PID>目标进程 PID
-m进入 mount 命名空间
-p进入 PID 命名空间
-u进入 UTS 命名空间
-i进入 IPC 命名空间
-n进入 network 命名空间

调试与日志

日志级别控制

Runcell 默认日志级别为 WARN。你可以通过 -v 标志或 RUNCELL_LOG 环境变量来调整:

# 使用 -v 开启 Debug 级别日志
sudo ./target/debug/runcell -v ctr run --id test --image /path/to/rootfs
# 通过环境变量指定级别 (trace, debug, info, warn, error)
sudo RUNCELL_LOG=debug ./target/debug/runcell ctr run --id test --image /path/to/rootfs

日志级别优先级-v/--verbose 标志 > RUNCELL_LOG 环境变量 > 默认 warn

数据目录

目录说明
/tmp/runcell/bundles/<容器ID>OCI bundle 目录,包含 config.json
/tmp/runcell/states/<容器ID>容器状态目录,包含 state.json
/tmp/runcell/containers/<容器ID>容器镜像目录

依赖项

如果你要使用 seccomp 的话,确保本机已安装 libseccomp:

sudo apt update && sudo apt install libseccomp-dev

命令速查表

命令别名说明
container runctr run创建并运行容器
container listctr ls列出容器
container execctr exec在容器内执行命令
container deletectr rm删除容器
container createctr create创建容器(不启动)
container startctr start启动已创建的容器
storage pull-拉取镜像
storage mount-挂载存储
storage umount-卸载存储
storage cleanup-清理镜像

与 Docker 命令对比

DockerRuncell (推荐写法)
docker run -it imageruncell ctr run -m image -t -i /bin/sh
docker run -d image cmdruncell ctr run -m image -d cmd
docker psruncell ctr ls
docker ps -aruncell ctr ls --all
docker exec -it container cmdruncell ctr exec --id container -t -i cmd
docker rm containerruncell ctr rm --id container

About

参考rustjail的容器运行时

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - DragonOS-Community/runcell: 参考rustjail的容器运行时 · GitHub
Skip to content

Latest commit

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Runcell 使用文档

Runcell 是一个参照 rustjail 实现的轻量级容器运行时,支持容器的创建、运行和管理。

功能特性

  • 容器生命周期管理: 创建、启动、停止、删除容器
  • 容器列表查看: 列出所有运行中或已停止的容器
  • 容器内执行命令: 类似 docker exec 进入运行中的容器执行命令
  • 交互式终端支持: 支持 -it 参数进行交互式操作
  • 状态持久化: 容器状态保存到磁盘,支持跨进程查询
  • Namespace 隔离: 支持 PID、Mount、UTS、IPC、Network 等命名空间隔离
  • Cgroup 资源限制: 支持 CPU、内存等资源限制

构建

cargo build

基础用法

容器管理命令

提示container 命令可以使用别名 ctr

运行容器

创建并启动一个容器:

sudo ./target/debug/runcell ctr run \
--id <容器ID> \
--image <镜像路径> \
[命令] [参数...]

示例:

# 运行一个 sleep 进程的容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 交互式运行容器(类似 docker run -it)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 后台运行容器(类似 docker run -d)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-d \
/bin/sleep 3600
# 使用 file:// 协议拉取 tar 镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image file:///path/to/rootfs.tar \
/bin/sh
# 使用 dir:// 协议使用目录镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image dir:///path/to/bundle \
/bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--image-m镜像源,支持 file://dir:// 或本地路径
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
--detach-d后台运行(分离模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

列出容器

列出所有容器(支持别名 ls):

# 列出运行中的容器
sudo ./target/debug/runcell ctr ls
# 列出所有容器(包括已停止的)
sudo ./target/debug/runcell ctr ls --all
# JSON 格式输出
sudo ./target/debug/runcell ctr ls --format json

输出示例:

CONTAINER ID PID STATUS CREATED ROOTFS
test 12345 Running 2025-12-20 10:30:00 /tmp/runcell/containers/test/rootfs
mycontainer 0 Stopped 2025-12-20 09:00:00 /tmp/runcell/containers/mycontainer/rootfs

参数说明:

参数简写说明
--format-f输出格式:table(默认)或 json
--all-a显示所有容器(包括已停止的)

在容器内执行命令

在运行中的容器内执行命令(类似 docker exec):

# 执行单个命令
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
[命令] [参数...]
# 交互式进入容器
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
-t -i \
/bin/sh

示例:

# 在容器内执行 ls 命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 在容器内执行带参数的命令
sudo ./target/debug/runcell ctr exec --id test /bin/cat /etc/os-release
# 交互式进入容器的 shell
sudo ./target/debug/runcell ctr exec --id test -t -i /bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

删除容器

支持别名 rm

sudo ./target/debug/runcell ctr rm --id <容器ID>

删除操作会:

  1. 读取容器状态获取 PID
  2. 如果进程仍在运行,发送 SIGKILL 信号终止
  3. 清理 bundle 目录
  4. 清理状态目录
  5. 清理镜像文件

示例:

sudo ./target/debug/runcell ctr rm --id test

创建容器(仅创建,不启动)

sudo ./target/debug/runcell ctr create \
--id <容器ID> \
--rootfs <rootfs路径> \
[--bundle <bundle目录>]

启动容器

sudo ./target/debug/runcell ctr start --id <容器ID>

存储管理命令

拉取镜像

sudo ./target/debug/runcell storage pull \
--image <镜像源> \
--container-id <容器ID>

挂载

sudo ./target/debug/runcell storage mount \
--source <源路径> \
--target <目标路径> \
--options <挂载选项>

卸载

sudo ./target/debug/runcell storage umount --target <挂载点>

清理镜像

sudo ./target/debug/runcell storage cleanup --container-id <容器ID>

完整示例

示例 1:基础容器操作

# 1. 构建项目
cargo build
# 2. 运行容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 3. 查看容器列表
sudo ./target/debug/runcell ctr ls
# 4. 在容器内执行命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 5. 删除容器
sudo ./target/debug/runcell ctr rm --id test

示例 2:交互式容器

# 1. 启动交互式容器
sudo ./target/debug/runcell ctr run \
--id interactive-test \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 2. 在另一个终端查看容器
sudo ./target/debug/runcell ctr ls
# 3. 在另一个终端进入同一容器
sudo ./target/debug/runcell ctr exec \
--id interactive-test \
-t -i \
/bin/sh
# 4. 退出后删除容器
sudo ./target/debug/runcell ctr rm --id interactive-test

状态持久化

容器状态保存在 state.json 文件中,位于 /tmp/runcell/states/<容器ID>/state.json

状态文件格式:

{
"id": "test",
"init_process_pid": 12345,
"init_process_start_time": 1734567890,
"status": "Running",
"bundle": "/tmp/runcell/bundles/test",
"rootfs": "/tmp/runcell/containers/test/rootfs",
"created": 1734567880,
"namespace_paths": {
"mnt": "/proc/12345/ns/mnt",
"pid": "/proc/12345/ns/pid",
"net": "/proc/12345/ns/net",
"ipc": "/proc/12345/ns/ipc",
"uts": "/proc/12345/ns/uts"
}
}

查看容器进程

sudo ps aux | grep -E "sleep|runcell"| grep -v grep

手动进入容器命名空间

使用 nsenter 进入容器的命名空间:

# 先获取容器进程 PID
sudo ./target/debug/runcell ctr ls
# 使用 nsenter 进入容器执行命令
sudo nsenter -t <PID> -m -p -u -i -n <命令>

nsenter 参数说明:

参数说明
-t <PID>目标进程 PID
-m进入 mount 命名空间
-p进入 PID 命名空间
-u进入 UTS 命名空间
-i进入 IPC 命名空间
-n进入 network 命名空间

调试与日志

日志级别控制

Runcell 默认日志级别为 WARN。你可以通过 -v 标志或 RUNCELL_LOG 环境变量来调整:

# 使用 -v 开启 Debug 级别日志
sudo ./target/debug/runcell -v ctr run --id test --image /path/to/rootfs
# 通过环境变量指定级别 (trace, debug, info, warn, error)
sudo RUNCELL_LOG=debug ./target/debug/runcell ctr run --id test --image /path/to/rootfs

日志级别优先级-v/--verbose 标志 > RUNCELL_LOG 环境变量 > 默认 warn

数据目录

目录说明
/tmp/runcell/bundles/<容器ID>OCI bundle 目录,包含 config.json
/tmp/runcell/states/<容器ID>容器状态目录,包含 state.json
/tmp/runcell/containers/<容器ID>容器镜像目录

依赖项

如果你要使用 seccomp 的话,确保本机已安装 libseccomp:

sudo apt update && sudo apt install libseccomp-dev

命令速查表

命令别名说明
container runctr run创建并运行容器
container listctr ls列出容器
container execctr exec在容器内执行命令
container deletectr rm删除容器
container createctr create创建容器(不启动)
container startctr start启动已创建的容器
storage pull-拉取镜像
storage mount-挂载存储
storage umount-卸载存储
storage cleanup-清理镜像

与 Docker 命令对比

DockerRuncell (推荐写法)
docker run -it imageruncell ctr run -m image -t -i /bin/sh
docker run -d image cmdruncell ctr run -m image -d cmd
docker psruncell ctr ls
docker ps -aruncell ctr ls --all
docker exec -it container cmdruncell ctr exec --id container -t -i cmd
docker rm containerruncell ctr rm --id container

About

参考rustjail的容器运行时

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - DragonOS-Community/runcell: 参考rustjail的容器运行时 · GitHub
Skip to content

Latest commit

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Runcell 使用文档

Runcell 是一个参照 rustjail 实现的轻量级容器运行时,支持容器的创建、运行和管理。

功能特性

  • 容器生命周期管理: 创建、启动、停止、删除容器
  • 容器列表查看: 列出所有运行中或已停止的容器
  • 容器内执行命令: 类似 docker exec 进入运行中的容器执行命令
  • 交互式终端支持: 支持 -it 参数进行交互式操作
  • 状态持久化: 容器状态保存到磁盘,支持跨进程查询
  • Namespace 隔离: 支持 PID、Mount、UTS、IPC、Network 等命名空间隔离
  • Cgroup 资源限制: 支持 CPU、内存等资源限制

构建

cargo build

基础用法

容器管理命令

提示container 命令可以使用别名 ctr

运行容器

创建并启动一个容器:

sudo ./target/debug/runcell ctr run \
--id <容器ID> \
--image <镜像路径> \
[命令] [参数...]

示例:

# 运行一个 sleep 进程的容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 交互式运行容器(类似 docker run -it)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 后台运行容器(类似 docker run -d)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-d \
/bin/sleep 3600
# 使用 file:// 协议拉取 tar 镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image file:///path/to/rootfs.tar \
/bin/sh
# 使用 dir:// 协议使用目录镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image dir:///path/to/bundle \
/bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--image-m镜像源,支持 file://dir:// 或本地路径
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
--detach-d后台运行(分离模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

列出容器

列出所有容器(支持别名 ls):

# 列出运行中的容器
sudo ./target/debug/runcell ctr ls
# 列出所有容器(包括已停止的)
sudo ./target/debug/runcell ctr ls --all
# JSON 格式输出
sudo ./target/debug/runcell ctr ls --format json

输出示例:

CONTAINER ID PID STATUS CREATED ROOTFS
test 12345 Running 2025-12-20 10:30:00 /tmp/runcell/containers/test/rootfs
mycontainer 0 Stopped 2025-12-20 09:00:00 /tmp/runcell/containers/mycontainer/rootfs

参数说明:

参数简写说明
--format-f输出格式:table(默认)或 json
--all-a显示所有容器(包括已停止的)

在容器内执行命令

在运行中的容器内执行命令(类似 docker exec):

# 执行单个命令
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
[命令] [参数...]
# 交互式进入容器
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
-t -i \
/bin/sh

示例:

# 在容器内执行 ls 命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 在容器内执行带参数的命令
sudo ./target/debug/runcell ctr exec --id test /bin/cat /etc/os-release
# 交互式进入容器的 shell
sudo ./target/debug/runcell ctr exec --id test -t -i /bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

删除容器

支持别名 rm

sudo ./target/debug/runcell ctr rm --id <容器ID>

删除操作会:

  1. 读取容器状态获取 PID
  2. 如果进程仍在运行,发送 SIGKILL 信号终止
  3. 清理 bundle 目录
  4. 清理状态目录
  5. 清理镜像文件

示例:

sudo ./target/debug/runcell ctr rm --id test

创建容器(仅创建,不启动)

sudo ./target/debug/runcell ctr create \
--id <容器ID> \
--rootfs <rootfs路径> \
[--bundle <bundle目录>]

启动容器

sudo ./target/debug/runcell ctr start --id <容器ID>

存储管理命令

拉取镜像

sudo ./target/debug/runcell storage pull \
--image <镜像源> \
--container-id <容器ID>

挂载

sudo ./target/debug/runcell storage mount \
--source <源路径> \
--target <目标路径> \
--options <挂载选项>

卸载

sudo ./target/debug/runcell storage umount --target <挂载点>

清理镜像

sudo ./target/debug/runcell storage cleanup --container-id <容器ID>

完整示例

示例 1:基础容器操作

# 1. 构建项目
cargo build
# 2. 运行容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 3. 查看容器列表
sudo ./target/debug/runcell ctr ls
# 4. 在容器内执行命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 5. 删除容器
sudo ./target/debug/runcell ctr rm --id test

示例 2:交互式容器

# 1. 启动交互式容器
sudo ./target/debug/runcell ctr run \
--id interactive-test \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 2. 在另一个终端查看容器
sudo ./target/debug/runcell ctr ls
# 3. 在另一个终端进入同一容器
sudo ./target/debug/runcell ctr exec \
--id interactive-test \
-t -i \
/bin/sh
# 4. 退出后删除容器
sudo ./target/debug/runcell ctr rm --id interactive-test

状态持久化

容器状态保存在 state.json 文件中,位于 /tmp/runcell/states/<容器ID>/state.json

状态文件格式:

{
"id": "test",
"init_process_pid": 12345,
"init_process_start_time": 1734567890,
"status": "Running",
"bundle": "/tmp/runcell/bundles/test",
"rootfs": "/tmp/runcell/containers/test/rootfs",
"created": 1734567880,
"namespace_paths": {
"mnt": "/proc/12345/ns/mnt",
"pid": "/proc/12345/ns/pid",
"net": "/proc/12345/ns/net",
"ipc": "/proc/12345/ns/ipc",
"uts": "/proc/12345/ns/uts"
}
}

查看容器进程

sudo ps aux | grep -E "sleep|runcell"| grep -v grep

手动进入容器命名空间

使用 nsenter 进入容器的命名空间:

# 先获取容器进程 PID
sudo ./target/debug/runcell ctr ls
# 使用 nsenter 进入容器执行命令
sudo nsenter -t <PID> -m -p -u -i -n <命令>

nsenter 参数说明:

参数说明
-t <PID>目标进程 PID
-m进入 mount 命名空间
-p进入 PID 命名空间
-u进入 UTS 命名空间
-i进入 IPC 命名空间
-n进入 network 命名空间

调试与日志

日志级别控制

Runcell 默认日志级别为 WARN。你可以通过 -v 标志或 RUNCELL_LOG 环境变量来调整:

# 使用 -v 开启 Debug 级别日志
sudo ./target/debug/runcell -v ctr run --id test --image /path/to/rootfs
# 通过环境变量指定级别 (trace, debug, info, warn, error)
sudo RUNCELL_LOG=debug ./target/debug/runcell ctr run --id test --image /path/to/rootfs

日志级别优先级-v/--verbose 标志 > RUNCELL_LOG 环境变量 > 默认 warn

数据目录

目录说明
/tmp/runcell/bundles/<容器ID>OCI bundle 目录,包含 config.json
/tmp/runcell/states/<容器ID>容器状态目录,包含 state.json
/tmp/runcell/containers/<容器ID>容器镜像目录

依赖项

如果你要使用 seccomp 的话,确保本机已安装 libseccomp:

sudo apt update && sudo apt install libseccomp-dev

命令速查表

命令别名说明
container runctr run创建并运行容器
container listctr ls列出容器
container execctr exec在容器内执行命令
container deletectr rm删除容器
container createctr create创建容器(不启动)
container startctr start启动已创建的容器
storage pull-拉取镜像
storage mount-挂载存储
storage umount-卸载存储
storage cleanup-清理镜像

与 Docker 命令对比

DockerRuncell (推荐写法)
docker run -it imageruncell ctr run -m image -t -i /bin/sh
docker run -d image cmdruncell ctr run -m image -d cmd
docker psruncell ctr ls
docker ps -aruncell ctr ls --all
docker exec -it container cmdruncell ctr exec --id container -t -i cmd
docker rm containerruncell ctr rm --id container

About

参考rustjail的容器运行时

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - DragonOS-Community/runcell: 参考rustjail的容器运行时 · GitHub
Skip to content

Latest commit

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Runcell 使用文档

Runcell 是一个参照 rustjail 实现的轻量级容器运行时,支持容器的创建、运行和管理。

功能特性

  • 容器生命周期管理: 创建、启动、停止、删除容器
  • 容器列表查看: 列出所有运行中或已停止的容器
  • 容器内执行命令: 类似 docker exec 进入运行中的容器执行命令
  • 交互式终端支持: 支持 -it 参数进行交互式操作
  • 状态持久化: 容器状态保存到磁盘,支持跨进程查询
  • Namespace 隔离: 支持 PID、Mount、UTS、IPC、Network 等命名空间隔离
  • Cgroup 资源限制: 支持 CPU、内存等资源限制

构建

cargo build

基础用法

容器管理命令

提示container 命令可以使用别名 ctr

运行容器

创建并启动一个容器:

sudo ./target/debug/runcell ctr run \
--id <容器ID> \
--image <镜像路径> \
[命令] [参数...]

示例:

# 运行一个 sleep 进程的容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 交互式运行容器(类似 docker run -it)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 后台运行容器(类似 docker run -d)
sudo ./target/debug/runcell ctr run \
--id mycontainer \
--image /path/to/rootfs \
-d \
/bin/sleep 3600
# 使用 file:// 协议拉取 tar 镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image file:///path/to/rootfs.tar \
/bin/sh
# 使用 dir:// 协议使用目录镜像
sudo ./target/debug/runcell ctr run \
--id test \
--image dir:///path/to/bundle \
/bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--image-m镜像源,支持 file://dir:// 或本地路径
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
--detach-d后台运行(分离模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

列出容器

列出所有容器(支持别名 ls):

# 列出运行中的容器
sudo ./target/debug/runcell ctr ls
# 列出所有容器(包括已停止的)
sudo ./target/debug/runcell ctr ls --all
# JSON 格式输出
sudo ./target/debug/runcell ctr ls --format json

输出示例:

CONTAINER ID PID STATUS CREATED ROOTFS
test 12345 Running 2025-12-20 10:30:00 /tmp/runcell/containers/test/rootfs
mycontainer 0 Stopped 2025-12-20 09:00:00 /tmp/runcell/containers/mycontainer/rootfs

参数说明:

参数简写说明
--format-f输出格式:table(默认)或 json
--all-a显示所有容器(包括已停止的)

在容器内执行命令

在运行中的容器内执行命令(类似 docker exec):

# 执行单个命令
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
[命令] [参数...]
# 交互式进入容器
sudo ./target/debug/runcell ctr exec \
--id <容器ID> \
-t -i \
/bin/sh

示例:

# 在容器内执行 ls 命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 在容器内执行带参数的命令
sudo ./target/debug/runcell ctr exec --id test /bin/cat /etc/os-release
# 交互式进入容器的 shell
sudo ./target/debug/runcell ctr exec --id test -t -i /bin/sh

参数说明:

参数简写说明
--id容器 ID(必需)
--tty-t分配伪终端(TTY)
--interactive-i保持 STDIN 打开(交互模式)
命令参数要执行的命令及其参数(放在最后,可选,默认 /bin/sh

删除容器

支持别名 rm

sudo ./target/debug/runcell ctr rm --id <容器ID>

删除操作会:

  1. 读取容器状态获取 PID
  2. 如果进程仍在运行,发送 SIGKILL 信号终止
  3. 清理 bundle 目录
  4. 清理状态目录
  5. 清理镜像文件

示例:

sudo ./target/debug/runcell ctr rm --id test

创建容器(仅创建,不启动)

sudo ./target/debug/runcell ctr create \
--id <容器ID> \
--rootfs <rootfs路径> \
[--bundle <bundle目录>]

启动容器

sudo ./target/debug/runcell ctr start --id <容器ID>

存储管理命令

拉取镜像

sudo ./target/debug/runcell storage pull \
--image <镜像源> \
--container-id <容器ID>

挂载

sudo ./target/debug/runcell storage mount \
--source <源路径> \
--target <目标路径> \
--options <挂载选项>

卸载

sudo ./target/debug/runcell storage umount --target <挂载点>

清理镜像

sudo ./target/debug/runcell storage cleanup --container-id <容器ID>

完整示例

示例 1:基础容器操作

# 1. 构建项目
cargo build
# 2. 运行容器
sudo ./target/debug/runcell ctr run \
--id test \
--image /path/to/rootfs \
/bin/sleep 180
# 3. 查看容器列表
sudo ./target/debug/runcell ctr ls
# 4. 在容器内执行命令
sudo ./target/debug/runcell ctr exec --id test /bin/ls /
# 5. 删除容器
sudo ./target/debug/runcell ctr rm --id test

示例 2:交互式容器

# 1. 启动交互式容器
sudo ./target/debug/runcell ctr run \
--id interactive-test \
--image /path/to/rootfs \
-t -i \
/bin/sh
# 2. 在另一个终端查看容器
sudo ./target/debug/runcell ctr ls
# 3. 在另一个终端进入同一容器
sudo ./target/debug/runcell ctr exec \
--id interactive-test \
-t -i \
/bin/sh
# 4. 退出后删除容器
sudo ./target/debug/runcell ctr rm --id interactive-test

状态持久化

容器状态保存在 state.json 文件中,位于 /tmp/runcell/states/<容器ID>/state.json

状态文件格式:

{
"id": "test",
"init_process_pid": 12345,
"init_process_start_time": 1734567890,
"status": "Running",
"bundle": "/tmp/runcell/bundles/test",
"rootfs": "/tmp/runcell/containers/test/rootfs",
"created": 1734567880,
"namespace_paths": {
"mnt": "/proc/12345/ns/mnt",
"pid": "/proc/12345/ns/pid",
"net": "/proc/12345/ns/net",
"ipc": "/proc/12345/ns/ipc",
"uts": "/proc/12345/ns/uts"
}
}

查看容器进程

sudo ps aux | grep -E "sleep|runcell"| grep -v grep

手动进入容器命名空间

使用 nsenter 进入容器的命名空间:

# 先获取容器进程 PID
sudo ./target/debug/runcell ctr ls
# 使用 nsenter 进入容器执行命令
sudo nsenter -t <PID> -m -p -u -i -n <命令>

nsenter 参数说明:

参数说明
-t <PID>目标进程 PID
-m进入 mount 命名空间
-p进入 PID 命名空间
-u进入 UTS 命名空间
-i进入 IPC 命名空间
-n进入 network 命名空间

调试与日志

日志级别控制

Runcell 默认日志级别为 WARN。你可以通过 -v 标志或 RUNCELL_LOG 环境变量来调整:

# 使用 -v 开启 Debug 级别日志
sudo ./target/debug/runcell -v ctr run --id test --image /path/to/rootfs
# 通过环境变量指定级别 (trace, debug, info, warn, error)
sudo RUNCELL_LOG=debug ./target/debug/runcell ctr run --id test --image /path/to/rootfs

日志级别优先级-v/--verbose 标志 > RUNCELL_LOG 环境变量 > 默认 warn

数据目录

目录说明
/tmp/runcell/bundles/<容器ID>OCI bundle 目录,包含 config.json
/tmp/runcell/states/<容器ID>容器状态目录,包含 state.json
/tmp/runcell/containers/<容器ID>容器镜像目录

依赖项

如果你要使用 seccomp 的话,确保本机已安装 libseccomp:

sudo apt update && sudo apt install libseccomp-dev

命令速查表

命令别名说明
container runctr run创建并运行容器
container listctr ls列出容器
container execctr exec在容器内执行命令
container deletectr rm删除容器
container createctr create创建容器(不启动)
container startctr start启动已创建的容器
storage pull-拉取镜像
storage mount-挂载存储
storage umount-卸载存储
storage cleanup-清理镜像

与 Docker 命令对比

DockerRuncell (推荐写法)
docker run -it imageruncell ctr run -m image -t -i /bin/sh
docker run -d image cmdruncell ctr run -m image -d cmd
docker psruncell ctr ls
docker ps -aruncell ctr ls --all
docker exec -it container cmdruncell ctr exec --id container -t -i cmd
docker rm containerruncell ctr rm --id container

About

参考rustjail的容器运行时

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages