1. ctr container help
root@suaxi:~# ctr container help
NAME:
ctr containers - Manage containers
USAGE:
ctr containers [global options] command [command options] [arguments...]
VERSION:
1.7.27
COMMANDS:
create Create container
delete, del, remove, rm Delete one or more existing containers
info Get info about a container
list, ls List containers
label Set and clear labels for a container
checkpoint Checkpoint a container
restore Restore a container from checkpoint
GLOBAL OPTIONS:
--help, -h show help
2. 查看容器
ctr container ls
查看容器中正在跑着的进程
ctr task ls
# 简写
ctr t ls
3. 创建静态容器
# 同上,c 为 container 的简写
ctr c create docker.io/library/nginx:alpine nginx-test
# 查看已创建的容器
ctr container ls
CONTAINER IMAGE RUNTIME
nginx-test docker.io/library/nginx:alpine io.containerd.runc.v2
# 查看容器信息
ctr container info nginx-test
4. 启动容器
# 启动task,即表时在容器中运行了进程(动态容器)
ctr task start -d nginx-test
5. 进入容器
# --exec-id 表示为 exec 进程设置一个id(可以使用随机数,保证该id唯一即可)
ctr task exec --exec-id 1 nginx-test /bin/sh
6. 直接运行动态容器
# --net-host 网络模式为 host
ctr run -d --net-host docker.io/library/nginx:alpine nginx-test
7. 暂停容器
# 查看容器状态
ctr tasks ls
TASK PID STATUS
nginx-test 5687 RUNNING
# 暂停
ctr tasks pause nginx-test
# 再次查看状态
ctr tasks ls
TASK PID STATUS
nginx-test 5687 PAUSED
8. 恢复容器
ctr tasks resume nginx-test
# 查看容器状态
ctr tasks ls
TASK PID STATUS
nginx-test 5687 RUNNING
9. 停止容器
# 使用 kill 命令,在 ctr task -h 帮助文档中可查看详细信息
ctr tasks kill nginx-test
# 查看容器状态
ctr tasks ls
TASK PID STATUS
nginx-test 5687 STOPPED
10. 删除容器
# 停止/删除 task
ctr tasks delete nginx-test
# 删除容器(需先完成上述步骤)
ctr container delete nginx-test
评论 (0)