#docker #error #post #deprecated #api-version #name #error-message

bin+lib docker-rust-api

The Engine API is an HTTP API served by Docker Engine. It is the API the Docker client uses to communicate with the Engine, so everything the Docker client can do can be done with the API. Most of the client’s commands map directly to API endpoints (e.g. docker ps is GET /containers/json). The notable exception is running containers, which consists of several API calls. # Errors The API uses standard HTTP status codes to indicate the success or failure of the API call. The body of the response will be JSON in the following format: { "message": "page not found" } # Versioning The API is usually changed in each release, so API calls are versioned to ensure that clients don’t break. To lock to a specific version of the API, you prefix the URL with its version, for example, call /v1.30/info to use the v1.30 version of the /info endpoint. If the API version specified in the URL is not supported by the daemon, a HTTP 400 Bad Request error message is returned. If you omit the version-prefix, the current version of the API (v1.42) is used. For example, calling /info is the same as calling /v1.42/info. Using the API without a version-prefix is deprecated and will be removed in a future release. Engine releases in the near future should support this version of the API, so your client will continue to work even if it is talking to a newer Engine. The API uses an open schema model, which means server may add extra properties to responses. Likewise, the server will ignore any extra query parameters and request body properties. When you write clients, you need to ignore additional properties in responses to ensure they do not break when talking to newer daemons. # Authentication Authentication for registries is handled client side. The client has to send authentication details to various endpoints that need to communicate with registries, such as POST /images/(name)/push. These are sent as X-Registry-Auth header as a base64url encoded (JSON) string with the following structure: { "username": "string", "password": "string", "email": "string", "serveraddress": "string" } The serveraddress is a domain/IP without a protocol. Throughout this structure, double quotes are required. If you have already got an identity token from the /auth endpoint, you can just pass this instead of credentials: { "identitytoken": "9cbaf023786cd7..." }

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集群卷"

模型文档

要获取存储库生成的文档,请使用

cargo doc --open

作者

依赖

~7–19MB
~288K SLoC