Docker通过API

时间:2017-03-21 14:09:51

标签: docker docker-api

是否等同于docker service update --secret-add [SOME SECRET] [SERVICE]

文档在我可以做到的任何地方都没有提到: https://docs.docker.com/engine/api/v1.25/#tag/Service

但我之前已经告知docker命令使用API​​,所以我假设API 在某处?< / p>

在相关的说明中,我注意到通过API检查一个秘密会给出一个&#34; UpdatedAt&#34;领域。这是否意味着将来可以更新同一秘密,而不必创建新秘密?

2 个答案:

答案 0 :(得分:0)

您可以使用“服务”端点来更新服务。请求正文包含一个用于定义新秘密的部分:TaskTemplate.ContainerSpec.Secrets。

这样的事情应该有效:

{
  "Name": "top",
  "TaskTemplate": {
    "ContainerSpec": {
      "Image": "busybox",
      "Args": [],
      "Secrets: [
        "SecretID": <id_of_your_secret>
      ]
    },
    "Resources": {},
    "RestartPolicy": {},
    "Placement": { },
    "ForceUpdate": 0
  },
  "Mode": {
    "Replicated": {}
  },
  "UpdateConfig": {
    "Parallelism": 2,
    "Delay": 1000000000,
    "FailureAction": "pause",
    "Monitor": 15000000000,
    "MaxFailureRatio": 0.15
  },
  "RollbackConfig": {
    "Parallelism": 1,
    "Delay": 1000000000,
    "FailureAction": "pause",
    "Monitor": 15000000000,
    "MaxFailureRatio": 0.15
  },
  "EndpointSpec": {
    "Mode": "vip"
  }
}

答案 1 :(得分:0)

我知道这个问题很老,但我可以帮助其他人。答案在文档 here 中。

端点

/services/create

示例请求:

{
  "Name": "web",
  "TaskTemplate": {
    "ContainerSpec": {
      "Image": "nginx:alpine",
      "Mounts": [
        {
          "ReadOnly": true,
          "Source": "web-data",
          "Target": "/usr/share/nginx/html",
          "Type": "volume",
          "VolumeOptions": {
            "DriverConfig": {},
            "Labels": {
              "com.example.something": "something-value"
            }
          }
        }
      ],
      "User": "33",
      "DNSConfig": {
        "Nameservers": [
          "8.8.8.8"
        ],
        "Search": [
          "example.org"
        ],
        "Options": [
          "timeout:3"
        ]
      }
    },
    "LogDriver": {
      "Name": "json-file",
      "Options": {
        "max-file": "3",
        "max-size": "10M"
      }
    },
    "Placement": {},
    "Resources": {
      "Limits": {
        "MemoryBytes": 104857600
      },
      "Reservations": {}
    },
    "RestartPolicy": {
      "Condition": "on-failure",
      "Delay": 10000000000,
      "MaxAttempts": 10
    }
  },
  "Mode": {
    "Replicated": {
      "Replicas": 4
    }
  },
  "UpdateConfig": {
    "Delay": 30000000000,
    "Parallelism": 2,
    "FailureAction": "pause"
  },
  "EndpointSpec": {
    "Ports": [
      {
        "Protocol": "tcp",
        "PublishedPort": 8080,
        "TargetPort": 80
      }
    ]
  },
  "Labels": {
    "foo": "bar"
  }
}

示例响应

{
  "ID": "ak7w3gjqoa3kuz8xcpnyy0pvl",
  "Warning": "unable to pin image doesnotexist:latest to digest: image library/doesnotexist:latest not found"
}