2 个稳定版本
1.42.1 | 2023 年 3 月 1 日 |
---|
#906 在 网络编程
1MB
10K SLoC
Rust API 客户端用于 openapi
Engine API 是由 Docker Engine 提供的 HTTP API。它是 Docker 客户端用来与 Engine 通信的 API,因此 Docker 客户端能做的任何事情都可以通过 API 完成。
客户端的大部分命令直接映射到 API 端点(例如,docker ps
映射到 GET /containers/json
)。唯一的例外是运行容器,它由多个 API 调用组成。
查看
async fn list_containers(config: &Configuration) {
let containers = container_list(config, Some(true), None, None, None);
match containers.await {
Ok(container_summary) => {
for c in container_summary {
println!("{:?}", c.names);
}
}
Err(err) => {
panic!("{}", err)
}
}
}
fn main() {
println!("DOCKER");
let config = &Configuration {
base_path: "http://127.0.0.1:2375".to_string(),
user_agent: None,
client: reqwest::Client::new(),
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
api_key: None,
};
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async {
list_containers(config).await;
})
}
安装
cargo add docker-rust-api
Rust 文档
错误
API 使用标准的 HTTP 状态码来指示 API 调用的成功或失败。响应体将是以下格式的 JSON
{
\"message\": \"page not found\"
}
版本化
API 通常在每个版本中都会更改,因此 API 调用被版本化以确保客户端不会出错。要锁定到 API 的特定版本,请将版本前缀添加到 URL 中,例如,调用 /v1.30/info
使用 /info
端点的 v1.30 版本。如果 URL 中指定的 API 版本不支持守护程序,将返回 HTTP 400 错误请求
错误消息。
如果您省略版本前缀,将使用当前版本的 API(v1.42)。例如,调用 /info
等同于调用 /v1.42/info
。在不带版本前缀的情况下使用 API 已被弃用,将在未来的版本中删除。
未来即将发布的 Engine 版本应支持此版本的 API,因此即使客户端与更新的 Engine 通信,客户端也能继续工作。
API 使用开放的架构模型,这意味着服务器可能会在响应中添加额外的属性。同样,服务器将忽略任何额外的查询参数和请求体属性。在编写客户端时,您需要忽略响应中的额外属性,以确保它们在与较新的守护程序通信时不会出错。
身份验证
注册表的身份验证由客户端处理。客户端必须将身份验证详细信息发送到需要与注册表通信的各种端点,例如 POST /images/(name)/push
。这些以 X-Registry-Auth
标头发送,作为 base64url 编码(JSON)字符串,具有以下结构
{
\"username\": \"string\",
\"password\": \"string\",
\"email\": \"string\",
\"serveraddress\": \"string\"
}
serveraddress
是一个不带协议的域名/IP。在整个结构中,需要使用双引号。
如果您已经从 /auth
端点 获取了身份令牌,您可以直接传递这个令牌而不是凭证
{
\"identitytoken\": \"9cbaf023786cd7...\"
}
概述
此API客户端是由 OpenAPI Generator 项目生成的。通过使用远程服务器的 openapi-spec,您可以轻松生成API客户端。
- API版本:1.42
- 包版本:1.42
- 构建包:
org.openapitools.codegen.languages.RustClientCodegen
安装
将包放入名为 openapi
的目录中,并将以下内容添加到 Cargo.toml
中的 [dependencies]
openapi = { path = "./openapi" }
API端点文档
所有URI都是相对于 https://127.0.0.1/v1.42
类 | 方法 | HTTP请求 | 描述 |
---|---|---|---|
ConfigApi | config_create | POST /configs/create | 创建配置 |
ConfigApi | config_delete | DELETE /configs/{id} | 删除配置 |
ConfigApi | config_inspect | GET /configs/{id} | 检查配置 |
ConfigApi | config_list | GET /configs | 列出配置 |
ConfigApi | config_update | POST /configs/{id}/update | 更新配置 |
ContainerApi | container_archive | GET /containers/{id}/archive | 获取容器中文件系统资源的存档 |
ContainerApi | container_archive_info | HEAD /containers/{id}/archive | 获取容器中文件的信息 |
ContainerApi | container_attach | POST /containers/{id}/attach | 连接到容器 |
ContainerApi | container_attach_websocket | GET /containers/{id}/attach/ws | 通过WebSocket连接到容器 |
ContainerApi | container_changes | GET /containers/{id}/changes | 获取容器文件系统上的更改 |
ContainerApi | container_create | POST /containers/create | 创建容器 |
ContainerApi | container_delete | DELETE /containers/{id} | 删除容器 |
ContainerApi | container_export | GET /containers/{id}/export | 导出容器 |
ContainerApi | container_inspect | GET /containers/{id}/json | 检查容器 |
ContainerApi | container_kill | POST /containers/{id}/kill | 杀死容器 |
ContainerApi | container_list | GET /containers/json | 列出容器 |
ContainerApi | container_logs | GET /containers/{id}/logs | 获取容器日志 |
ContainerApi | container_pause | POST /containers/{id}/pause | 暂停容器 |
ContainerApi | container_prune | POST /containers/prune | 删除已停止的容器 |
ContainerApi | container_rename | POST /containers/{id}/rename | 重命名容器 |
ContainerApi | container_resize | POST /containers/{id}/resize | 调整容器TTY大小 |
ContainerApi | container_restart | POST /containers/{id}/restart | 重启容器 |
ContainerApi | container_start | POST /containers/{id}/start | 启动容器 |
ContainerApi | container_stats | GET /containers/{id}/stats | 基于资源使用情况获取容器统计信息 |
ContainerApi | container_stop | POST /containers/{id}/stop | 停止容器 |
ContainerApi | container_top | GET /containers/{id}/top | 列出容器内运行的进程 |
ContainerApi | container_unpause | POST /containers/{id}/unpause | 取消暂停容器 |
ContainerApi | container_update | POST /containers/{id}/update | 更新容器 |
ContainerApi | container_wait | POST /containers/{id}/wait | 等待一个容器 |
ContainerApi | put_container_archive | PUT /containers/{id}/archive | 将文件或文件夹的存档提取到容器中的目录 |
DistributionApi | distribution_inspect | GET /distribution/{name}/json | 从注册表中获取镜像信息 |
ExecApi | container_exec | POST /containers/{id}/exec | 创建一个exec实例 |
ExecApi | exec_inspect | GET /exec/{id}/json | 检查exec实例 |
ExecApi | exec_resize | POST /exec/{id}/resize | 调整exec实例的大小 |
ExecApi | exec_start | POST /exec/{id}/start | 启动exec实例 |
ImageApi | build_prune | POST /build/prune | 删除构建器缓存 |
ImageApi | image_build | POST /build | 构建镜像 |
ImageApi | image_commit | POST /commit | 从容器创建新的镜像 |
ImageApi | image_create | POST /images/create | 创建镜像 |
ImageApi | image_delete | DELETE /images/{name} | 删除镜像 |
ImageApi | image_get | GET /images/{name}/get | 导出镜像 |
ImageApi | image_get_all | GET /images/get | 导出多个镜像 |
ImageApi | image_history | GET /images/{name}/history | 获取镜像的历史记录 |
ImageApi | image_inspect | GET /images/{name}/json | 检查镜像 |
ImageApi | image_list | GET /images/json | 列出镜像 |
ImageApi | image_load | POST /images/load | 导入镜像 |
ImageApi | image_prune | POST /images/prune | 删除未使用的镜像 |
ImageApi | image_push | POST /images/{name}/push | 推送镜像 |
ImageApi | image_search | GET /images/search | 搜索镜像 |
ImageApi | image_tag | POST /images/{name}/tag | 标记镜像 |
NetworkApi | network_connect | POST /networks/{id}/connect | 将容器连接到网络 |
NetworkApi | network_create | POST /networks/create | 创建网络 |
NetworkApi | network_delete | DELETE /networks/{id} | 删除网络 |
NetworkApi | network_disconnect | POST /networks/{id}/disconnect | 从网络断开容器连接 |
NetworkApi | network_inspect | GET /networks/{id} | 检查网络 |
NetworkApi | network_list | GET /networks | 列出网络 |
NetworkApi | network_prune | POST /networks/prune | 删除未使用的网络 |
NodeApi | node_delete | DELETE /nodes/{id} | 删除节点 |
NodeApi | node_inspect | GET /nodes/{id} | 检查节点 |
NodeApi | node_list | GET /nodes | 列出节点 |
NodeApi | node_update | POST /nodes/{id}/update | 更新节点 |
PluginApi | get_plugin_privileges | GET /plugins/privileges | 获取插件权限 |
PluginApi | plugin_create | POST /plugins/create | 创建插件 |
PluginApi | plugin_delete | DELETE /plugins/{name} | 删除插件 |
PluginApi | plugin_disable | POST /plugins/{name}/disable | 禁用插件 |
PluginApi | plugin_enable | POST /plugins/{name}/enable | 启用插件 |
PluginApi | plugin_inspect | GET /plugins/{name}/json | 检查插件 |
PluginApi | plugin_list | GET /plugins | 列出插件 |
PluginApi | plugin_pull | POST /plugins/pull | 安装插件 |
PluginApi | plugin_push | POST /plugins/{name}/push | 推送插件 |
PluginApi | plugin_set | POST /plugins/{name}/set | 配置插件 |
PluginApi | plugin_upgrade | POST /plugins/{name}/upgrade | 升级插件 |
SecretApi | secret_create | POST /secrets/create | 创建秘密 |
SecretApi | secret_delete | DELETE /secrets/{id} | 删除秘密 |
SecretApi | secret_inspect | GET /secrets/{id} | 检查秘密 |
SecretApi | secret_list | GET /secrets | 列出秘密 |
SecretApi | secret_update | POST /secrets/{id}/update | 更新秘密 |
ServiceApi | service_create | POST /services/create | 创建服务 |
ServiceApi | service_delete | DELETE /services/{id} | 删除服务 |
ServiceApi | service_inspect | GET /services/{id} | 检查服务 |
ServiceApi | service_list | GET /services | 列出服务 |
ServiceApi | service_logs | GET /services/{id}/logs | 获取服务日志 |
ServiceApi | service_update | POST /services/{id}/update | 更新服务 |
SessionApi | session | POST /session | 初始化交互会话 |
SwarmApi | swarm_init | POST /swarm/init | 初始化一个新的集群 |
SwarmApi | swarm_inspect | GET /swarm | 检查集群 |
SwarmApi | swarm_join | POST /swarm/join | 加入现有的集群 |
SwarmApi | swarm_leave | POST /swarm/leave | 离开集群 |
SwarmApi | swarm_unlock | POST /swarm/unlock | 解锁被锁定管理器 |
SwarmApi | swarm_unlockkey | GET /swarm/unlockkey | 获取解锁密钥 |
SwarmApi | swarm_update | POST /swarm/update | 更新集群 |
SystemApi | system_auth | POST /auth | 检查认证配置 |
SystemApi | system_data_usage | GET /system/df | 获取数据使用信息 |
SystemApi | system_events | GET /events | 监控事件 |
SystemApi | system_info | GET /info | 获取系统信息 |
SystemApi | system_ping | GET /_ping | Ping |
SystemApi | system_ping_head | HEAD /_ping | Ping |
SystemApi | system_version | GET /version | 获取版本 |
TaskApi | task_inspect | GET /tasks/{id} | 检查任务 |
TaskApi | task_list | GET /tasks | 列出任务 |
TaskApi | task_logs | GET /tasks/{id}/logs | 获取任务日志 |
VolumeApi | volume_create | POST /volumes/create | 创建卷 |
VolumeApi | volume_delete | DELETE /volumes/{name} | 删除卷 |
VolumeApi | volume_inspect | GET /volumes/{name} | 检查卷 |
VolumeApi | volume_list | GET /volumes | 列出卷 |
VolumeApi | volume_prune | POST /volumes/prune | 删除未使用的卷 |
VolumeApi | volume_update | PUT /volumes/{name} | "更新卷。仅适用于Swarm集群卷" |
模型文档
- 地址
- AuthConfig
- BuildCache
- BuildInfo
- BuildPruneResponse
- ClusterInfo
- ClusterVolume
- ClusterVolumeInfo
- ClusterVolumePublishStatusInner
- ClusterVolumeSpec
- ClusterVolumeSpecAccessMode
- ClusterVolumeSpecAccessModeAccessibilityRequirements
- ClusterVolumeSpecAccessModeCapacityRange
- ClusterVolumeSpecAccessModeSecretsInner
- Commit
- Config
- ConfigCreateRequest
- ConfigSpec
- ContainerChangeResponseItem
- ContainerConfig
- ContainerCreateRequest
- ContainerCreateRequestAllOf
- ContainerCreateResponse
- ContainerInspectResponse
- ContainerPruneResponse
- ContainerState
- ContainerSummary
- ContainerSummaryHostConfig
- ContainerSummaryNetworkSettings
- ContainerTopResponse
- ContainerUpdateRequest
- ContainerUpdateRequestAllOf
- ContainerUpdateResponse
- ContainerWaitExitError
- ContainerWaitResponse
- CreateImageInfo
- DeviceMapping
- DeviceRequest
- DistributionInspect
- Driver
- EndpointIpamConfig
- EndpointPortConfig
- EndpointSettings
- EndpointSpec
- EngineDescription
- EngineDescriptionPluginsInner
- ErrorDetail
- ErrorResponse
- EventActor
- EventMessage
- ExecConfig
- ExecInspectResponse
- ExecStartConfig
- GenericResourcesInner
- GenericResourcesInnerDiscreteResourceSpec
- GenericResourcesInnerNamedResourceSpec
- GraphDriverData
- Health
- HealthConfig
- HealthcheckResult
- HistoryResponseItem
- HostConfig
- HostConfigAllOf
- 主机配置全部日志配置
- 标识响应
- 镜像删除响应项
- 镜像ID
- 镜像检查
- 镜像检查元数据
- 镜像检查根文件系统
- 镜像修剪响应
- 镜像搜索响应项
- 镜像摘要
- 索引信息
- IPAM
- IPAM配置
- 加入令牌
- 限制
- 本地节点状态
- 管理器状态
- 挂载
- 挂载绑定选项
- 挂载点
- 挂载tmpfs选项
- 挂载卷选项
- 挂载卷选项驱动配置
- 网络
- 网络附加配置
- 网络连接请求
- 网络容器
- 网络创建请求
- 网络创建响应
- 网络断开连接请求
- 网络修剪响应
- 网络设置
- 网络配置
- 节点
- 节点描述
- 节点规范
- 节点状态
- 节点状态
- 对象版本
- OCI描述符
- OCI平台
- 对等节点
- 平台
- 插件
- 插件配置
- 插件配置参数
- 插件配置接口
- 插件配置Linux
- 插件配置网络
- 插件配置根文件系统
- 插件配置用户
- 插件设备
- 插件环境
- 插件接口类型
- 插件挂载
- 插件权限
- 插件设置
- 插件信息
- 端口
- 端口绑定
- 进程配置
- 进度详情
- 推送镜像信息
- 可达性
- 注册表服务配置
- 资源对象
- 资源
- 资源BlkioWeightDeviceInner
- 资源UlimitsInner
- 重启策略
- 运行时
- 秘密
- 秘密创建请求
- 秘密规范
- 服务
- 服务创建请求
- 服务创建响应
- 服务端点
- 服务端点虚拟IPsInner
- 服务作业状态
- 服务服务状态
- 服务规范
- 服务规范模式
- 服务规范复制模式
- 服务规范复制作业模式
- 服务规范回滚配置
- 服务规范更新配置
- 服务更新请求
- 服务更新响应
- 服务更新状态
- 集群
- 集群全部
- 集群信息
- 集群初始化请求
- 集群加入请求
- 集群规范
- 集群规范CA配置
- 集群规范CA配置外部CAInner
- 集群规范调度器
- 集群规范加密配置
- 集群规范编排
- 集群规范Raft
- 集群规范任务默认值
- 集群规范任务默认值日志驱动
- 集群解锁请求
- 系统认证响应
- 系统数据使用情况响应
- 系统信息
- 系统信息默认地址池Inner
- 系统版本
- 系统版本组件Inner
- 系统版本平台
- 任务
- 任务规范
- 任务规范容器规范
- 任务规范容器规范配置Inner
- 任务规范容器规范配置Inner文件
- 任务规范容器规范DNS配置
- 任务规范容器规范权限
- 任务规范容器规范权限凭证规范
- 任务规范容器规范权限SeLinux上下文
- 任务规范容器规范秘密Inner
- 任务规范容器规范秘密Inner文件
- 任务规范日志驱动
- 任务规范网络附加规范
- 任务规范放置
- 任务规范放置偏好Inner
- 任务规范放置偏好Inner扩散
- 任务规范插件规范
- 任务规范资源
- 任务规范重启策略
- 任务状态
- 任务状态
- 任务状态容器状态
- 节流设备
- TLS信息
- 解锁密钥响应
- 卷
- 卷创建选项
- 卷列表响应
- 卷修剪响应
- 卷更新请求
- 卷使用数据
要获取存储库生成的文档,请使用
cargo doc --open
作者
依赖
~7–19MB
~288K SLoC