Dockerctl
Dockerctl 是一个 Docker 服务管理工具,用于管理 Docker 守护进程的生命周期和配置。
注意
请使用 root
用户运行。
命令说明
dockerctl 是一个命令行工具,旨在简化对 Docker 守护程序及其资源的管理。它不用于替代日常命令(如 docker run
或 docker ps
),而是作为管理底层 Docker 服务本身的便捷封装。
主要功能包括:
- 服务控制:轻松启动、停止、重启 Docker 引擎,并检查其状态。
- 系统清理:提供
prune
命令,可快速清理未使用的容器、镜像和卷,将系统维护整合到一个工具中。 - 配置显示:允许您查看当前的 Docker 服务配置。
shell
Usage:
dockerctl [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
prune clear docker data
restart restart docker service
show-config show the config of dockerservice
start start docker service
status show the status of dockerservice
stop stop docker service
dockerctl start
启动 Docker 服务。
shell
dockerctl start
dockerctl stop
停止 Docker 服务。
shell
dockerctl stop
dockerctl status
显示 Docker 服务的当前运行状态。
查看默认配置:
shell
dockerctl status
示例输出:
shell
● docker.service - Docker Application Container Engine
Active: active (running) since 2024-12-02 04:40:33 Monday; 0 days ago
Tasks: 116
Memory: 0.00%
CPU: 0.00%
dockerctl show-config
显示 Docker 服务的当前配置。
shell
dockerctl show-config [flags]
查看默认配置:
shell
dockerctl show-config
示例输出:
json
{
"proxies": {}
}
dockerctl restart
重启 Docker 服务。通常在修改配置后使用此命令使更改生效。
shell
dockerctl restart
管理 Docker 服务配置
Docker 容器服务支持修改 docker 服务配置,添加 proxies
或 registry-mirrors
等。修改以下任意文件,均需要执行 dockerctl restart
使更改生效。
Docker 服务配置文件
/etc/docker/daemon.json
。用法参考 Docker Daemon 官方文档、Docker Hub 官方文档。示例配置如下:json{ "proxies": { "http-proxy": "http://proxy.example.com:3128", "https-proxy": "https://proxy.example.com:3129", "no-proxy": "*.test.example.com,.example.org,127.0.0.0/8" }, "registry-mirrors": ["https://<my-docker-mirror-host>"] }
/tmp/docker-config/config.json
(该文件在开发机重启后会复原,无法持久化保存修改)。用法参考 Docker CLI 官方文档。示例配置如下:json{ "proxies": { "default": { "httpProxy": "http://proxy.example.com:3128", "httpsProxy": "https://proxy.example.com:3129", "noProxy": "*.test.example.com,.example.org,127.0.0.0/8" } } }
警告
请务必注意两份配置文件 proxies
字段差异。
修改 Docker 服务配置
编辑配置文件。
shellmkdir -p /etc/docker # 修改 docker daemon 配置 vim /etc/docker/daemon.json
重启服务以应用更改。
shelldockerctl restart
验证配置是否生效。
shelldockerctl show-config
开机状态下手动清除 Docker 服务数据
Docker 服务共享开发机主容器的 100GiB 存储空间。如需在开机状态下清理已停止的容器、镜像与卷,可以使用 dockerctl prune
命令。具体流程如下:
停止 Docker 服务。
shelldockerctl stop
删除 Docker 服务数据。
shelldockerctl prune
启动 Docker 服务。
shelldockerctl start