gitee.com/bomy/docker.git@v1.13.1/docs/api/v1.19.md (about) 1 --- 2 title: "Engine API v1.19" 3 description: "API Documentation for Docker" 4 keywords: "API, Docker, rcli, REST, documentation" 5 redirect_from: 6 - /engine/reference/api/docker_remote_api_v1.19/ 7 - /reference/api/docker_remote_api_v1.19/ 8 --- 9 10 <!-- This file is maintained within the docker/docker Github 11 repository at https://github.com/docker/docker/. Make all 12 pull requests against that repo. If you see this file in 13 another repository, consider it read-only there, as it will 14 periodically be overwritten by the definitive file. Pull 15 requests which include edits to this file in other repositories 16 will be rejected. 17 --> 18 19 ## 1. Brief introduction 20 21 - The daemon listens on `unix:///var/run/docker.sock` but you can 22 [Bind Docker to another host/port or a Unix socket](../reference/commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). 23 - The API tends to be REST. However, for some complex commands, like `attach` 24 or `pull`, the HTTP connection is hijacked to transport `stdout`, 25 `stdin` and `stderr`. 26 - When the client API version is newer than the daemon's, these calls return an HTTP 27 `400 Bad Request` error message. 28 29 ## 2. Endpoints 30 31 ### 2.1 Containers 32 33 #### List containers 34 35 `GET /containers/json` 36 37 List containers 38 39 **Example request**: 40 41 GET /v1.19/containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 42 43 **Example response**: 44 45 HTTP/1.1 200 OK 46 Content-Type: application/json 47 48 [ 49 { 50 "Id": "8dfafdbc3a40", 51 "Names":["/boring_feynman"], 52 "Image": "ubuntu:latest", 53 "Command": "echo 1", 54 "Created": 1367854155, 55 "Status": "Exit 0", 56 "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], 57 "Labels": { 58 "com.example.vendor": "Acme", 59 "com.example.license": "GPL", 60 "com.example.version": "1.0" 61 }, 62 "SizeRw": 12288, 63 "SizeRootFs": 0 64 }, 65 { 66 "Id": "9cd87474be90", 67 "Names":["/coolName"], 68 "Image": "ubuntu:latest", 69 "Command": "echo 222222", 70 "Created": 1367854155, 71 "Status": "Exit 0", 72 "Ports": [], 73 "Labels": {}, 74 "SizeRw": 12288, 75 "SizeRootFs": 0 76 }, 77 { 78 "Id": "3176a2479c92", 79 "Names":["/sleepy_dog"], 80 "Image": "ubuntu:latest", 81 "Command": "echo 3333333333333333", 82 "Created": 1367854154, 83 "Status": "Exit 0", 84 "Ports":[], 85 "Labels": {}, 86 "SizeRw":12288, 87 "SizeRootFs":0 88 }, 89 { 90 "Id": "4cb07b47f9fb", 91 "Names":["/running_cat"], 92 "Image": "ubuntu:latest", 93 "Command": "echo 444444444444444444444444444444444", 94 "Created": 1367854152, 95 "Status": "Exit 0", 96 "Ports": [], 97 "Labels": {}, 98 "SizeRw": 12288, 99 "SizeRootFs": 0 100 } 101 ] 102 103 **Query parameters**: 104 105 - **all** – 1/True/true or 0/False/false, Show all containers. 106 Only running containers are shown by default (i.e., this defaults to false) 107 - **limit** – Show `limit` last created 108 containers, include non-running ones. 109 - **since** – Show only containers created since Id, include 110 non-running ones. 111 - **before** – Show only containers created before Id, include 112 non-running ones. 113 - **size** – 1/True/true or 0/False/false, Show the containers 114 sizes 115 - **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: 116 - `exited=<int>`; -- containers with exit code of `<int>` ; 117 - `status=`(`restarting`|`running`|`paused`|`exited`) 118 - `label=key` or `label="key=value"` of a container label 119 120 **Status codes**: 121 122 - **200** – no error 123 - **400** – bad parameter 124 - **500** – server error 125 126 #### Create a container 127 128 `POST /containers/create` 129 130 Create a container 131 132 **Example request**: 133 134 POST /v1.19/containers/create HTTP/1.1 135 Content-Type: application/json 136 137 { 138 "Hostname": "", 139 "Domainname": "", 140 "User": "", 141 "AttachStdin": false, 142 "AttachStdout": true, 143 "AttachStderr": true, 144 "Tty": false, 145 "OpenStdin": false, 146 "StdinOnce": false, 147 "Env": [ 148 "FOO=bar", 149 "BAZ=quux" 150 ], 151 "Cmd": [ 152 "date" 153 ], 154 "Entrypoint": null, 155 "Image": "ubuntu", 156 "Labels": { 157 "com.example.vendor": "Acme", 158 "com.example.license": "GPL", 159 "com.example.version": "1.0" 160 }, 161 "Volumes": { 162 "/volumes/data": {} 163 }, 164 "WorkingDir": "", 165 "NetworkDisabled": false, 166 "MacAddress": "12:34:56:78:9a:bc", 167 "ExposedPorts": { 168 "22/tcp": {} 169 }, 170 "HostConfig": { 171 "Binds": ["/tmp:/tmp"], 172 "Links": ["redis3:redis"], 173 "LxcConf": {"lxc.utsname":"docker"}, 174 "Memory": 0, 175 "MemorySwap": 0, 176 "CpuShares": 512, 177 "CpuPeriod": 100000, 178 "CpuQuota": 50000, 179 "CpusetCpus": "0,1", 180 "CpusetMems": "0,1", 181 "BlkioWeight": 300, 182 "OomKillDisable": false, 183 "PidMode": "", 184 "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, 185 "PublishAllPorts": false, 186 "Privileged": false, 187 "ReadonlyRootfs": false, 188 "Dns": ["8.8.8.8"], 189 "DnsSearch": [""], 190 "ExtraHosts": null, 191 "VolumesFrom": ["parent", "other:ro"], 192 "CapAdd": ["NET_ADMIN"], 193 "CapDrop": ["MKNOD"], 194 "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, 195 "NetworkMode": "bridge", 196 "Devices": [], 197 "Ulimits": [{}], 198 "LogConfig": { "Type": "json-file", "Config": {} }, 199 "SecurityOpt": [], 200 "CgroupParent": "" 201 } 202 } 203 204 **Example response**: 205 206 HTTP/1.1 201 Created 207 Content-Type: application/json 208 209 { 210 "Id":"e90e34656806", 211 "Warnings":[] 212 } 213 214 **JSON parameters**: 215 216 - **Hostname** - A string value containing the hostname to use for the 217 container. 218 - **Domainname** - A string value containing the domain name to use 219 for the container. 220 - **User** - A string value specifying the user inside the container. 221 - **AttachStdin** - Boolean value, attaches to `stdin`. 222 - **AttachStdout** - Boolean value, attaches to `stdout`. 223 - **AttachStderr** - Boolean value, attaches to `stderr`. 224 - **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. 225 - **OpenStdin** - Boolean value, opens `stdin`, 226 - **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. 227 - **Env** - A list of environment variables in the form of `["VAR=value", ...]` 228 - **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value", ... }` 229 - **Cmd** - Command to run specified as a string or an array of strings. 230 - **Entrypoint** - Set the entry point for the container as a string or an array 231 of strings. 232 - **Image** - A string specifying the image name to use for the container. 233 - **Volumes** - An object mapping mount point paths (strings) inside the 234 container to empty objects. 235 - **WorkingDir** - A string specifying the working directory for commands to 236 run in. 237 - **NetworkDisabled** - Boolean value, when true disables networking for the 238 container 239 - **ExposedPorts** - An object mapping ports to an empty object in the form of: 240 `"ExposedPorts": { "<port>/<tcp|udp>: {}" }` 241 - **HostConfig** 242 - **Binds** – A list of bind-mounts for this container. Each item is a string in one of these forms: 243 + `host-src:container-dest` to bind-mount a host path into the 244 container. Both `host-src`, and `container-dest` must be an 245 _absolute_ path. 246 + `host-src:container-dest:ro` to make the bind-mount read-only 247 inside the container. Both `host-src`, and `container-dest` must be 248 an _absolute_ path. 249 - **Links** - A list of links for the container. Each link entry should be 250 in the form of `container_name:alias`. 251 - **LxcConf** - LXC specific configurations. These configurations only 252 work when using the `lxc` execution driver. 253 - **Memory** - Memory limit in bytes. 254 - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. 255 You must use this with `memory` and make the swap value larger than `memory`. 256 - **CpuShares** - An integer value containing the container's CPU Shares 257 (ie. the relative weight vs other containers). 258 - **CpuPeriod** - The length of a CPU period in microseconds. 259 - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. 260 - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. 261 - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. 262 - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. 263 - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. 264 - **PidMode** - Set the PID (Process) Namespace mode for the container; 265 `"container:<name|id>"`: joins another container's PID namespace 266 `"host"`: use the host's PID namespace inside the container 267 - **PortBindings** - A map of exposed container ports and the host port they 268 should map to. A JSON object in the form 269 `{ <port>/<protocol>: [{ "HostPort": "<port>" }] }` 270 Take note that `port` is specified as a string and not an integer value. 271 - **PublishAllPorts** - Allocates a random host port for all of a container's 272 exposed ports. Specified as a boolean value. 273 - **Privileged** - Gives the container full access to the host. Specified as 274 a boolean value. 275 - **ReadonlyRootfs** - Mount the container's root filesystem as read only. 276 Specified as a boolean value. 277 - **Dns** - A list of DNS servers for the container to use. 278 - **DnsSearch** - A list of DNS search domains 279 - **ExtraHosts** - A list of hostnames/IP mappings to add to the 280 container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. 281 - **VolumesFrom** - A list of volumes to inherit from another container. 282 Specified in the form `<container name>[:<ro|rw>]` 283 - **CapAdd** - A list of kernel capabilities to add to the container. 284 - **Capdrop** - A list of kernel capabilities to drop from the container. 285 - **RestartPolicy** – The behavior to apply when the container exits. The 286 value is an object with a `Name` property of either `"always"` to 287 always restart or `"on-failure"` to restart only when the container 288 exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` 289 controls the number of times to retry before giving up. 290 The default is not to restart. (optional) 291 An ever increasing delay (double the previous delay, starting at 100mS) 292 is added before each restart to prevent flooding the server. 293 - **NetworkMode** - Sets the networking mode for the container. Supported 294 values are: `bridge`, `host`, `none`, and `container:<name|id>` 295 - **Devices** - A list of devices to add to the container specified as a JSON object in the 296 form 297 `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` 298 - **Ulimits** - A list of ulimits to set in the container, specified as 299 `{ "Name": <name>, "Soft": <soft limit>, "Hard": <hard limit> }`, for example: 300 `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` 301 - **SecurityOpt**: A list of string values to customize labels for MLS 302 systems, such as SELinux. 303 - **LogConfig** - Log configuration for the container, specified as a JSON object in the form 304 `{ "Type": "<driver_name>", "Config": {"key1": "val1"}}`. 305 Available types: `json-file`, `syslog`, `journald`, `none`. 306 `syslog` available options are: `address`. 307 - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. 308 309 **Query parameters**: 310 311 - **name** – Assign the specified name to the container. Must 312 match `/?[a-zA-Z0-9_-]+`. 313 314 **Status codes**: 315 316 - **201** – no error 317 - **400** – bad parameter 318 - **404** – no such container 319 - **406** – impossible to attach (container not running) 320 - **409** – conflict 321 - **500** – server error 322 323 #### Inspect a container 324 325 `GET /containers/(id or name)/json` 326 327 Return low-level information on the container `id` 328 329 **Example request**: 330 331 GET /v1.19/containers/4fa6e0f0c678/json HTTP/1.1 332 333 **Example response**: 334 335 HTTP/1.1 200 OK 336 Content-Type: application/json 337 338 { 339 "AppArmorProfile": "", 340 "Args": [ 341 "-c", 342 "exit 9" 343 ], 344 "Config": { 345 "AttachStderr": true, 346 "AttachStdin": false, 347 "AttachStdout": true, 348 "Cmd": [ 349 "/bin/sh", 350 "-c", 351 "exit 9" 352 ], 353 "Domainname": "", 354 "Entrypoint": null, 355 "Env": [ 356 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 357 ], 358 "ExposedPorts": null, 359 "Hostname": "ba033ac44011", 360 "Image": "ubuntu", 361 "Labels": { 362 "com.example.vendor": "Acme", 363 "com.example.license": "GPL", 364 "com.example.version": "1.0" 365 }, 366 "MacAddress": "", 367 "NetworkDisabled": false, 368 "OnBuild": null, 369 "OpenStdin": false, 370 "PortSpecs": null, 371 "StdinOnce": false, 372 "Tty": false, 373 "User": "", 374 "Volumes": null, 375 "WorkingDir": "" 376 }, 377 "Created": "2015-01-06T15:47:31.485331387Z", 378 "Driver": "devicemapper", 379 "ExecDriver": "native-0.2", 380 "ExecIDs": null, 381 "HostConfig": { 382 "Binds": null, 383 "BlkioWeight": 0, 384 "CapAdd": null, 385 "CapDrop": null, 386 "ContainerIDFile": "", 387 "CpusetCpus": "", 388 "CpusetMems": "", 389 "CpuShares": 0, 390 "CpuPeriod": 100000, 391 "Devices": [], 392 "Dns": null, 393 "DnsSearch": null, 394 "ExtraHosts": null, 395 "IpcMode": "", 396 "Links": null, 397 "LxcConf": [], 398 "Memory": 0, 399 "MemorySwap": 0, 400 "OomKillDisable": false, 401 "NetworkMode": "bridge", 402 "PidMode": "", 403 "PortBindings": {}, 404 "Privileged": false, 405 "ReadonlyRootfs": false, 406 "PublishAllPorts": false, 407 "RestartPolicy": { 408 "MaximumRetryCount": 2, 409 "Name": "on-failure" 410 }, 411 "LogConfig": { 412 "Config": null, 413 "Type": "json-file" 414 }, 415 "SecurityOpt": null, 416 "VolumesFrom": null, 417 "Ulimits": [{}] 418 }, 419 "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", 420 "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", 421 "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", 422 "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", 423 "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", 424 "MountLabel": "", 425 "Name": "/boring_euclid", 426 "NetworkSettings": { 427 "Bridge": "", 428 "Gateway": "", 429 "IPAddress": "", 430 "IPPrefixLen": 0, 431 "MacAddress": "", 432 "PortMapping": null, 433 "Ports": null 434 }, 435 "Path": "/bin/sh", 436 "ProcessLabel": "", 437 "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", 438 "RestartCount": 1, 439 "State": { 440 "Error": "", 441 "ExitCode": 9, 442 "FinishedAt": "2015-01-06T15:47:32.080254511Z", 443 "OOMKilled": false, 444 "Paused": false, 445 "Pid": 0, 446 "Restarting": false, 447 "Running": true, 448 "StartedAt": "2015-01-06T15:47:32.072697474Z" 449 }, 450 "Volumes": {}, 451 "VolumesRW": {} 452 } 453 454 **Status codes**: 455 456 - **200** – no error 457 - **404** – no such container 458 - **500** – server error 459 460 #### List processes running inside a container 461 462 `GET /containers/(id or name)/top` 463 464 List processes running inside the container `id`. On Unix systems this 465 is done by running the `ps` command. This endpoint is not 466 supported on Windows. 467 468 **Example request**: 469 470 GET /v1.19/containers/4fa6e0f0c678/top HTTP/1.1 471 472 **Example response**: 473 474 HTTP/1.1 200 OK 475 Content-Type: application/json 476 477 { 478 "Titles" : [ 479 "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" 480 ], 481 "Processes" : [ 482 [ 483 "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" 484 ], 485 [ 486 "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" 487 ] 488 ] 489 } 490 491 **Example request**: 492 493 GET /v1.19/containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 494 495 **Example response**: 496 497 HTTP/1.1 200 OK 498 Content-Type: application/json 499 500 { 501 "Titles" : [ 502 "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" 503 ] 504 "Processes" : [ 505 [ 506 "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" 507 ], 508 [ 509 "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" 510 ] 511 ], 512 } 513 514 **Query parameters**: 515 516 - **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` 517 518 **Status codes**: 519 520 - **200** – no error 521 - **404** – no such container 522 - **500** – server error 523 524 #### Get container logs 525 526 `GET /containers/(id or name)/logs` 527 528 Get `stdout` and `stderr` logs from the container ``id`` 529 530 > **Note**: 531 > This endpoint works only for containers with the `json-file` or `journald` logging drivers. 532 533 **Example request**: 534 535 GET /v1.19/containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 536 537 **Example response**: 538 539 HTTP/1.1 101 UPGRADED 540 Content-Type: application/vnd.docker.raw-stream 541 Connection: Upgrade 542 Upgrade: tcp 543 544 {% raw %} 545 {{ STREAM }} 546 {% endraw %} 547 548 **Query parameters**: 549 550 - **follow** – 1/True/true or 0/False/false, return stream. Default `false`. 551 - **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. 552 - **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. 553 - **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp 554 will only output log-entries since that timestamp. Default: 0 (unfiltered) 555 - **timestamps** – 1/True/true or 0/False/false, print timestamps for 556 every log line. Default `false`. 557 - **tail** – Output specified number of lines at the end of logs: `all` or `<number>`. Default all. 558 559 **Status codes**: 560 561 - **101** – no error, hints proxy about hijacking 562 - **200** – no error, no upgrade header found 563 - **404** – no such container 564 - **500** – server error 565 566 #### Inspect changes on a container's filesystem 567 568 `GET /containers/(id or name)/changes` 569 570 Inspect changes on container `id`'s filesystem 571 572 **Example request**: 573 574 GET /v1.19/containers/4fa6e0f0c678/changes HTTP/1.1 575 576 **Example response**: 577 578 HTTP/1.1 200 OK 579 Content-Type: application/json 580 581 [ 582 { 583 "Path": "/dev", 584 "Kind": 0 585 }, 586 { 587 "Path": "/dev/kmsg", 588 "Kind": 1 589 }, 590 { 591 "Path": "/test", 592 "Kind": 1 593 } 594 ] 595 596 Values for `Kind`: 597 598 - `0`: Modify 599 - `1`: Add 600 - `2`: Delete 601 602 **Status codes**: 603 604 - **200** – no error 605 - **404** – no such container 606 - **500** – server error 607 608 #### Export a container 609 610 `GET /containers/(id or name)/export` 611 612 Export the contents of container `id` 613 614 **Example request**: 615 616 GET /v1.19/containers/4fa6e0f0c678/export HTTP/1.1 617 618 **Example response**: 619 620 HTTP/1.1 200 OK 621 Content-Type: application/octet-stream 622 623 {% raw %} 624 {{ TAR STREAM }} 625 {% endraw %} 626 627 **Status codes**: 628 629 - **200** – no error 630 - **404** – no such container 631 - **500** – server error 632 633 #### Get container stats based on resource usage 634 635 `GET /containers/(id or name)/stats` 636 637 This endpoint returns a live stream of a container's resource usage statistics. 638 639 **Example request**: 640 641 GET /v1.19/containers/redis1/stats HTTP/1.1 642 643 **Example response**: 644 645 HTTP/1.1 200 OK 646 Content-Type: application/json 647 648 { 649 "read" : "2015-01-08T22:57:31.547920715Z", 650 "network" : { 651 "rx_dropped" : 0, 652 "rx_bytes" : 648, 653 "rx_errors" : 0, 654 "tx_packets" : 8, 655 "tx_dropped" : 0, 656 "rx_packets" : 8, 657 "tx_errors" : 0, 658 "tx_bytes" : 648 659 }, 660 "memory_stats" : { 661 "stats" : { 662 "total_pgmajfault" : 0, 663 "cache" : 0, 664 "mapped_file" : 0, 665 "total_inactive_file" : 0, 666 "pgpgout" : 414, 667 "rss" : 6537216, 668 "total_mapped_file" : 0, 669 "writeback" : 0, 670 "unevictable" : 0, 671 "pgpgin" : 477, 672 "total_unevictable" : 0, 673 "pgmajfault" : 0, 674 "total_rss" : 6537216, 675 "total_rss_huge" : 6291456, 676 "total_writeback" : 0, 677 "total_inactive_anon" : 0, 678 "rss_huge" : 6291456, 679 "hierarchical_memory_limit" : 67108864, 680 "total_pgfault" : 964, 681 "total_active_file" : 0, 682 "active_anon" : 6537216, 683 "total_active_anon" : 6537216, 684 "total_pgpgout" : 414, 685 "total_cache" : 0, 686 "inactive_anon" : 0, 687 "active_file" : 0, 688 "pgfault" : 964, 689 "inactive_file" : 0, 690 "total_pgpgin" : 477 691 }, 692 "max_usage" : 6651904, 693 "usage" : 6537216, 694 "failcnt" : 0, 695 "limit" : 67108864 696 }, 697 "blkio_stats" : {}, 698 "cpu_stats" : { 699 "cpu_usage" : { 700 "percpu_usage" : [ 701 8646879, 702 24472255, 703 36438778, 704 30657443 705 ], 706 "usage_in_usermode" : 50000000, 707 "total_usage" : 100215355, 708 "usage_in_kernelmode" : 30000000 709 }, 710 "system_cpu_usage" : 739306590000000, 711 "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} 712 }, 713 "precpu_stats" : { 714 "cpu_usage" : { 715 "percpu_usage" : [ 716 8646879, 717 24350896, 718 36438778, 719 30657443 720 ], 721 "usage_in_usermode" : 50000000, 722 "total_usage" : 100093996, 723 "usage_in_kernelmode" : 30000000 724 }, 725 "system_cpu_usage" : 9492140000000, 726 "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} 727 } 728 } 729 730 The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. 731 732 **Query parameters**: 733 734 - **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. 735 736 **Status codes**: 737 738 - **200** – no error 739 - **404** – no such container 740 - **500** – server error 741 742 #### Resize a container TTY 743 744 `POST /containers/(id or name)/resize?h=<height>&w=<width>` 745 746 Resize the TTY for container with `id`. You must restart the container for the resize to take effect. 747 748 **Example request**: 749 750 POST /v1.19/containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 751 752 **Example response**: 753 754 HTTP/1.1 200 OK 755 Content-Length: 0 756 Content-Type: text/plain; charset=utf-8 757 758 **Query parameters**: 759 760 - **h** – height of `tty` session 761 - **w** – width 762 763 **Status codes**: 764 765 - **200** – no error 766 - **404** – No such container 767 - **500** – Cannot resize container 768 769 #### Start a container 770 771 `POST /containers/(id or name)/start` 772 773 Start the container `id` 774 775 > **Note**: 776 > For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. 777 > See [create a container](#create-a-container) for details. 778 779 **Example request**: 780 781 POST /v1.19/containers/e90e34656806/start HTTP/1.1 782 783 **Example response**: 784 785 HTTP/1.1 204 No Content 786 787 **Status codes**: 788 789 - **204** – no error 790 - **304** – container already started 791 - **404** – no such container 792 - **500** – server error 793 794 #### Stop a container 795 796 `POST /containers/(id or name)/stop` 797 798 Stop the container `id` 799 800 **Example request**: 801 802 POST /v1.19/containers/e90e34656806/stop?t=5 HTTP/1.1 803 804 **Example response**: 805 806 HTTP/1.1 204 No Content 807 808 **Query parameters**: 809 810 - **t** – number of seconds to wait before killing the container 811 812 **Status codes**: 813 814 - **204** – no error 815 - **304** – container already stopped 816 - **404** – no such container 817 - **500** – server error 818 819 #### Restart a container 820 821 `POST /containers/(id or name)/restart` 822 823 Restart the container `id` 824 825 **Example request**: 826 827 POST /v1.19/containers/e90e34656806/restart?t=5 HTTP/1.1 828 829 **Example response**: 830 831 HTTP/1.1 204 No Content 832 833 **Query parameters**: 834 835 - **t** – number of seconds to wait before killing the container 836 837 **Status codes**: 838 839 - **204** – no error 840 - **404** – no such container 841 - **500** – server error 842 843 #### Kill a container 844 845 `POST /containers/(id or name)/kill` 846 847 Kill the container `id` 848 849 **Example request**: 850 851 POST /v1.19/containers/e90e34656806/kill HTTP/1.1 852 853 **Example response**: 854 855 HTTP/1.1 204 No Content 856 857 **Query parameters**: 858 859 - **signal** - Signal to send to the container: integer or string like `SIGINT`. 860 When not set, `SIGKILL` is assumed and the call waits for the container to exit. 861 862 **Status codes**: 863 864 - **204** – no error 865 - **404** – no such container 866 - **500** – server error 867 868 #### Rename a container 869 870 `POST /containers/(id or name)/rename` 871 872 Rename the container `id` to a `new_name` 873 874 **Example request**: 875 876 POST /v1.19/containers/e90e34656806/rename?name=new_name HTTP/1.1 877 878 **Example response**: 879 880 HTTP/1.1 204 No Content 881 882 **Query parameters**: 883 884 - **name** – new name for the container 885 886 **Status codes**: 887 888 - **204** – no error 889 - **404** – no such container 890 - **409** - conflict name already assigned 891 - **500** – server error 892 893 #### Pause a container 894 895 `POST /containers/(id or name)/pause` 896 897 Pause the container `id` 898 899 **Example request**: 900 901 POST /v1.19/containers/e90e34656806/pause HTTP/1.1 902 903 **Example response**: 904 905 HTTP/1.1 204 No Content 906 907 **Status codes**: 908 909 - **204** – no error 910 - **404** – no such container 911 - **500** – server error 912 913 #### Unpause a container 914 915 `POST /containers/(id or name)/unpause` 916 917 Unpause the container `id` 918 919 **Example request**: 920 921 POST /v1.19/containers/e90e34656806/unpause HTTP/1.1 922 923 **Example response**: 924 925 HTTP/1.1 204 No Content 926 927 **Status codes**: 928 929 - **204** – no error 930 - **404** – no such container 931 - **500** – server error 932 933 #### Attach to a container 934 935 `POST /containers/(id or name)/attach` 936 937 Attach to the container `id` 938 939 **Example request**: 940 941 POST /v1.19/containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 942 943 **Example response**: 944 945 HTTP/1.1 101 UPGRADED 946 Content-Type: application/vnd.docker.raw-stream 947 Connection: Upgrade 948 Upgrade: tcp 949 950 {% raw %} 951 {{ STREAM }} 952 {% endraw %} 953 954 **Query parameters**: 955 956 - **logs** – 1/True/true or 0/False/false, return logs. Default `false`. 957 - **stream** – 1/True/true or 0/False/false, return stream. 958 Default `false`. 959 - **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach 960 to `stdin`. Default `false`. 961 - **stdout** – 1/True/true or 0/False/false, if `logs=true`, return 962 `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. 963 - **stderr** – 1/True/true or 0/False/false, if `logs=true`, return 964 `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. 965 966 **Status codes**: 967 968 - **101** – no error, hints proxy about hijacking 969 - **200** – no error, no upgrade header found 970 - **400** – bad parameter 971 - **404** – no such container 972 - **500** – server error 973 974 **Stream details**: 975 976 When using the TTY setting is enabled in 977 [`POST /containers/create` 978 ](#create-a-container), 979 the stream is the raw data from the process PTY and client's `stdin`. 980 When the TTY is disabled, then the stream is multiplexed to separate 981 `stdout` and `stderr`. 982 983 The format is a **Header** and a **Payload** (frame). 984 985 **HEADER** 986 987 The header contains the information which the stream writes (`stdout` or 988 `stderr`). It also contains the size of the associated frame encoded in the 989 last four bytes (`uint32`). 990 991 It is encoded on the first eight bytes like this: 992 993 header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} 994 995 `STREAM_TYPE` can be: 996 997 - 0: `stdin` (is written on `stdout`) 998 - 1: `stdout` 999 - 2: `stderr` 1000 1001 `SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of 1002 the `uint32` size encoded as big endian. 1003 1004 **PAYLOAD** 1005 1006 The payload is the raw stream. 1007 1008 **IMPLEMENTATION** 1009 1010 The simplest way to implement the Attach protocol is the following: 1011 1012 1. Read eight bytes. 1013 2. Choose `stdout` or `stderr` depending on the first byte. 1014 3. Extract the frame size from the last four bytes. 1015 4. Read the extracted size and output it on the correct output. 1016 5. Goto 1. 1017 1018 #### Attach to a container (websocket) 1019 1020 `GET /containers/(id or name)/attach/ws` 1021 1022 Attach to the container `id` via websocket 1023 1024 Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) 1025 1026 **Example request** 1027 1028 GET /v1.19/containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 1029 1030 **Example response** 1031 1032 {% raw %} 1033 {{ STREAM }} 1034 {% endraw %} 1035 1036 **Query parameters**: 1037 1038 - **logs** – 1/True/true or 0/False/false, return logs. Default `false`. 1039 - **stream** – 1/True/true or 0/False/false, return stream. 1040 Default `false`. 1041 - **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach 1042 to `stdin`. Default `false`. 1043 - **stdout** – 1/True/true or 0/False/false, if `logs=true`, return 1044 `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. 1045 - **stderr** – 1/True/true or 0/False/false, if `logs=true`, return 1046 `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. 1047 1048 **Status codes**: 1049 1050 - **200** – no error 1051 - **400** – bad parameter 1052 - **404** – no such container 1053 - **500** – server error 1054 1055 #### Wait a container 1056 1057 `POST /containers/(id or name)/wait` 1058 1059 Block until container `id` stops, then returns the exit code 1060 1061 **Example request**: 1062 1063 POST /v1.19/containers/16253994b7c4/wait HTTP/1.1 1064 1065 **Example response**: 1066 1067 HTTP/1.1 200 OK 1068 Content-Type: application/json 1069 1070 {"StatusCode": 0} 1071 1072 **Status codes**: 1073 1074 - **200** – no error 1075 - **404** – no such container 1076 - **500** – server error 1077 1078 #### Remove a container 1079 1080 `DELETE /containers/(id or name)` 1081 1082 Remove the container `id` from the filesystem 1083 1084 **Example request**: 1085 1086 DELETE /v1.19/containers/16253994b7c4?v=1 HTTP/1.1 1087 1088 **Example response**: 1089 1090 HTTP/1.1 204 No Content 1091 1092 **Query parameters**: 1093 1094 - **v** – 1/True/true or 0/False/false, Remove the volumes 1095 associated to the container. Default `false`. 1096 - **force** - 1/True/true or 0/False/false, Kill then remove the container. 1097 Default `false`. 1098 1099 **Status codes**: 1100 1101 - **204** – no error 1102 - **400** – bad parameter 1103 - **404** – no such container 1104 - **409** – conflict 1105 - **500** – server error 1106 1107 #### Copy files or folders from a container 1108 1109 `POST /containers/(id or name)/copy` 1110 1111 Copy files or folders of container `id` 1112 1113 **Example request**: 1114 1115 POST /v1.19/containers/4fa6e0f0c678/copy HTTP/1.1 1116 Content-Type: application/json 1117 1118 { 1119 "Resource": "test.txt" 1120 } 1121 1122 **Example response**: 1123 1124 HTTP/1.1 200 OK 1125 Content-Type: application/x-tar 1126 1127 {% raw %} 1128 {{ TAR STREAM }} 1129 {% endraw %} 1130 1131 **Status codes**: 1132 1133 - **200** – no error 1134 - **404** – no such container 1135 - **500** – server error 1136 1137 ### 2.2 Images 1138 1139 #### List Images 1140 1141 `GET /images/json` 1142 1143 **Example request**: 1144 1145 GET /v1.19/images/json?all=0 HTTP/1.1 1146 1147 **Example response**: 1148 1149 HTTP/1.1 200 OK 1150 Content-Type: application/json 1151 1152 [ 1153 { 1154 "RepoTags": [ 1155 "ubuntu:12.04", 1156 "ubuntu:precise", 1157 "ubuntu:latest" 1158 ], 1159 "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", 1160 "Created": 1365714795, 1161 "Size": 131506275, 1162 "VirtualSize": 131506275, 1163 "Labels": {} 1164 }, 1165 { 1166 "RepoTags": [ 1167 "ubuntu:12.10", 1168 "ubuntu:quantal" 1169 ], 1170 "ParentId": "27cf784147099545", 1171 "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 1172 "Created": 1364102658, 1173 "Size": 24653, 1174 "VirtualSize": 180116135, 1175 "Labels": { 1176 "com.example.version": "v1" 1177 } 1178 } 1179 ] 1180 1181 **Example request, with digest information**: 1182 1183 GET /v1.19/images/json?digests=1 HTTP/1.1 1184 1185 **Example response, with digest information**: 1186 1187 HTTP/1.1 200 OK 1188 Content-Type: application/json 1189 1190 [ 1191 { 1192 "Created": 1420064636, 1193 "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", 1194 "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", 1195 "RepoDigests": [ 1196 "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" 1197 ], 1198 "RepoTags": [ 1199 "localhost:5000/test/busybox:latest", 1200 "playdate:latest" 1201 ], 1202 "Size": 0, 1203 "VirtualSize": 2429728, 1204 "Labels": {} 1205 } 1206 ] 1207 1208 The response shows a single image `Id` associated with two repositories 1209 (`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use 1210 either of the `RepoTags` values `localhost:5000/test/busybox:latest` or 1211 `playdate:latest` to reference the image. 1212 1213 You can also use `RepoDigests` values to reference an image. In this response, 1214 the array has only one reference and that is to the 1215 `localhost:5000/test/busybox` repository; the `playdate` repository has no 1216 digest. You can reference this digest using the value: 1217 `localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` 1218 1219 See the `docker run` and `docker build` commands for examples of digest and tag 1220 references on the command line. 1221 1222 **Query parameters**: 1223 1224 - **all** – 1/True/true or 0/False/false, default false 1225 - **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: 1226 - `dangling=true` 1227 - `label=key` or `label="key=value"` of an image label 1228 - **filter** - only return images with the specified name 1229 1230 #### Build image from a Dockerfile 1231 1232 `POST /build` 1233 1234 Build an image from a Dockerfile 1235 1236 **Example request**: 1237 1238 POST /v1.19/build HTTP/1.1 1239 1240 {% raw %} 1241 {{ TAR STREAM }} 1242 {% endraw %} 1243 1244 **Example response**: 1245 1246 HTTP/1.1 200 OK 1247 Content-Type: application/json 1248 1249 {"stream": "Step 1/5..."} 1250 {"stream": "..."} 1251 {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} 1252 1253 The input stream must be a `tar` archive compressed with one of the 1254 following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. 1255 1256 The archive must include a build instructions file, typically called 1257 `Dockerfile` at the archive's root. The `dockerfile` parameter may be 1258 used to specify a different build instructions file. To do this, its value must be 1259 the path to the alternate build instructions file to use. 1260 1261 The archive may include any number of other files, 1262 which are accessible in the build context (See the [*ADD build 1263 command*](../reference/builder.md#add)). 1264 1265 The Docker daemon performs a preliminary validation of the `Dockerfile` before 1266 starting the build, and returns an error if the syntax is incorrect. After that, 1267 each instruction is run one-by-one until the ID of the new image is output. 1268 1269 The build is canceled if the client drops the connection by quitting 1270 or being killed. 1271 1272 **Query parameters**: 1273 1274 - **dockerfile** - Path within the build context to the Dockerfile. This is 1275 ignored if `remote` is specified and points to an individual filename. 1276 - **t** – A name and optional tag to apply to the image in the `name:tag` format. 1277 If you omit the `tag` the default `latest` value is assumed. 1278 - **remote** – A Git repository URI or HTTP/HTTPS URI build source. If the 1279 URI specifies a filename, the file's contents are placed into a file 1280 called `Dockerfile`. 1281 - **q** – Suppress verbose build output. 1282 - **nocache** – Do not use the cache when building the image. 1283 - **pull** - Attempt to pull the image even if an older image exists locally. 1284 - **rm** - Remove intermediate containers after a successful build (default behavior). 1285 - **forcerm** - Always remove intermediate containers (includes `rm`). 1286 - **memory** - Set memory limit for build. 1287 - **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. 1288 - **cpushares** - CPU shares (relative weight). 1289 - **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). 1290 - **cpuperiod** - The length of a CPU period in microseconds. 1291 - **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. 1292 1293 **Request Headers**: 1294 1295 - **Content-type** – Set to `"application/tar"`. 1296 - **X-Registry-Config** – base64-encoded ConfigFile object 1297 1298 **Status codes**: 1299 1300 - **200** – no error 1301 - **500** – server error 1302 1303 #### Create an image 1304 1305 `POST /images/create` 1306 1307 Create an image either by pulling it from the registry or by importing it 1308 1309 **Example request**: 1310 1311 POST /v1.19/images/create?fromImage=busybox&tag=latest HTTP/1.1 1312 1313 **Example response**: 1314 1315 HTTP/1.1 200 OK 1316 Content-Type: application/json 1317 1318 {"status": "Pulling..."} 1319 {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} 1320 {"error": "Invalid..."} 1321 ... 1322 1323 When using this endpoint to pull an image from the registry, the 1324 `X-Registry-Auth` header can be used to include 1325 a base64-encoded AuthConfig object. 1326 1327 **Query parameters**: 1328 1329 - **fromImage** – Name of the image to pull. 1330 - **fromSrc** – Source to import. The value may be a URL from which the image 1331 can be retrieved or `-` to read the image from the request body. 1332 - **repo** – Repository name. 1333 - **tag** – Tag. If empty when pulling an image, this causes all tags 1334 for the given image to be pulled. 1335 1336 **Request Headers**: 1337 1338 - **X-Registry-Auth** – base64-encoded AuthConfig object 1339 1340 **Status codes**: 1341 1342 - **200** – no error 1343 - **404** - repository does not exist or no read access 1344 - **500** – server error 1345 1346 1347 1348 #### Inspect an image 1349 1350 `GET /images/(name)/json` 1351 1352 Return low-level information on the image `name` 1353 1354 **Example request**: 1355 1356 GET /v1.19/images/ubuntu/json HTTP/1.1 1357 1358 **Example response**: 1359 1360 HTTP/1.1 200 OK 1361 Content-Type: application/json 1362 1363 { 1364 "Created": "2013-03-23T22:24:18.818426-07:00", 1365 "Container": "3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", 1366 "ContainerConfig": { 1367 "Hostname": "", 1368 "User": "", 1369 "AttachStdin": false, 1370 "AttachStdout": false, 1371 "AttachStderr": false, 1372 "Tty": true, 1373 "OpenStdin": true, 1374 "StdinOnce": false, 1375 "Env": null, 1376 "Cmd": ["/bin/bash"], 1377 "Dns": null, 1378 "Image": "ubuntu", 1379 "Labels": { 1380 "com.example.vendor": "Acme", 1381 "com.example.license": "GPL", 1382 "com.example.version": "1.0" 1383 }, 1384 "Volumes": null, 1385 "VolumesFrom": "", 1386 "WorkingDir": "" 1387 }, 1388 "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 1389 "Parent": "27cf784147099545", 1390 "Size": 6824592 1391 } 1392 1393 **Status codes**: 1394 1395 - **200** – no error 1396 - **404** – no such image 1397 - **500** – server error 1398 1399 #### Get the history of an image 1400 1401 `GET /images/(name)/history` 1402 1403 Return the history of the image `name` 1404 1405 **Example request**: 1406 1407 GET /v1.19/images/ubuntu/history HTTP/1.1 1408 1409 **Example response**: 1410 1411 HTTP/1.1 200 OK 1412 Content-Type: application/json 1413 1414 [ 1415 { 1416 "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", 1417 "Created": 1398108230, 1418 "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", 1419 "Tags": [ 1420 "ubuntu:lucid", 1421 "ubuntu:10.04" 1422 ], 1423 "Size": 182964289, 1424 "Comment": "" 1425 }, 1426 { 1427 "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", 1428 "Created": 1398108222, 1429 "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi <admwiggin@gmail.com> - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", 1430 "Tags": null, 1431 "Size": 0, 1432 "Comment": "" 1433 }, 1434 { 1435 "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", 1436 "Created": 1371157430, 1437 "CreatedBy": "", 1438 "Tags": [ 1439 "scratch12:latest", 1440 "scratch:latest" 1441 ], 1442 "Size": 0, 1443 "Comment": "Imported from -" 1444 } 1445 ] 1446 1447 **Status codes**: 1448 1449 - **200** – no error 1450 - **404** – no such image 1451 - **500** – server error 1452 1453 #### Push an image on the registry 1454 1455 `POST /images/(name)/push` 1456 1457 Push the image `name` on the registry 1458 1459 **Example request**: 1460 1461 POST /v1.19/images/test/push HTTP/1.1 1462 1463 **Example response**: 1464 1465 HTTP/1.1 200 OK 1466 Content-Type: application/json 1467 1468 {"status": "Pushing..."} 1469 {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} 1470 {"error": "Invalid..."} 1471 ... 1472 1473 If you wish to push an image on to a private registry, that image must already have a tag 1474 into a repository which references that registry `hostname` and `port`. This repository name should 1475 then be used in the URL. This duplicates the command line's flow. 1476 1477 **Example request**: 1478 1479 POST /v1.19/images/registry.acme.com:5000/test/push HTTP/1.1 1480 1481 1482 **Query parameters**: 1483 1484 - **tag** – The tag to associate with the image on the registry. This is optional. 1485 1486 **Request Headers**: 1487 1488 - **X-Registry-Auth** – base64-encoded AuthConfig object. 1489 1490 **Status codes**: 1491 1492 - **200** – no error 1493 - **404** – no such image 1494 - **500** – server error 1495 1496 #### Tag an image into a repository 1497 1498 `POST /images/(name)/tag` 1499 1500 Tag the image `name` into a repository 1501 1502 **Example request**: 1503 1504 POST /v1.19/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 1505 1506 **Example response**: 1507 1508 HTTP/1.1 201 Created 1509 1510 **Query parameters**: 1511 1512 - **repo** – The repository to tag in 1513 - **force** – 1/True/true or 0/False/false, default false 1514 - **tag** - The new tag name 1515 1516 **Status codes**: 1517 1518 - **201** – no error 1519 - **400** – bad parameter 1520 - **404** – no such image 1521 - **409** – conflict 1522 - **500** – server error 1523 1524 #### Remove an image 1525 1526 `DELETE /images/(name)` 1527 1528 Remove the image `name` from the filesystem 1529 1530 **Example request**: 1531 1532 DELETE /v1.19/images/test HTTP/1.1 1533 1534 **Example response**: 1535 1536 HTTP/1.1 200 OK 1537 Content-type: application/json 1538 1539 [ 1540 {"Untagged": "3e2f21a89f"}, 1541 {"Deleted": "3e2f21a89f"}, 1542 {"Deleted": "53b4f83ac9"} 1543 ] 1544 1545 **Query parameters**: 1546 1547 - **force** – 1/True/true or 0/False/false, default false 1548 - **noprune** – 1/True/true or 0/False/false, default false 1549 1550 **Status codes**: 1551 1552 - **200** – no error 1553 - **404** – no such image 1554 - **409** – conflict 1555 - **500** – server error 1556 1557 #### Search images 1558 1559 `GET /images/search` 1560 1561 Search for an image on [Docker Hub](https://hub.docker.com). This API 1562 returns both `is_trusted` and `is_automated` images. Currently, they 1563 are considered identical. In the future, the `is_trusted` property will 1564 be deprecated and replaced by the `is_automated` property. 1565 1566 > **Note**: 1567 > The response keys have changed from API v1.6 to reflect the JSON 1568 > sent by the registry server to the docker daemon's request. 1569 1570 **Example request**: 1571 1572 GET /v1.19/images/search?term=sshd HTTP/1.1 1573 1574 **Example response**: 1575 1576 HTTP/1.1 200 OK 1577 Content-Type: application/json 1578 1579 [ 1580 { 1581 "star_count": 12, 1582 "is_official": false, 1583 "name": "wma55/u1210sshd", 1584 "is_trusted": false, 1585 "is_automated": false, 1586 "description": "" 1587 }, 1588 { 1589 "star_count": 10, 1590 "is_official": false, 1591 "name": "jdswinbank/sshd", 1592 "is_trusted": false, 1593 "is_automated": false, 1594 "description": "" 1595 }, 1596 { 1597 "star_count": 18, 1598 "is_official": false, 1599 "name": "vgauthier/sshd", 1600 "is_trusted": false, 1601 "is_automated": false, 1602 "description": "" 1603 } 1604 ... 1605 ] 1606 1607 **Query parameters**: 1608 1609 - **term** – term to search 1610 1611 **Status codes**: 1612 1613 - **200** – no error 1614 - **500** – server error 1615 1616 ### 2.3 Misc 1617 1618 #### Check auth configuration 1619 1620 `POST /auth` 1621 1622 Get the default username and email 1623 1624 **Example request**: 1625 1626 POST /v1.19/auth HTTP/1.1 1627 Content-Type: application/json 1628 1629 { 1630 "username": "hannibal", 1631 "password": "xxxx", 1632 "email": "hannibal@a-team.com", 1633 "serveraddress": "https://index.docker.io/v1/" 1634 } 1635 1636 **Example response**: 1637 1638 HTTP/1.1 200 OK 1639 1640 **Status codes**: 1641 1642 - **200** – no error 1643 - **204** – no error 1644 - **500** – server error 1645 1646 #### Display system-wide information 1647 1648 `GET /info` 1649 1650 Display system-wide information 1651 1652 **Example request**: 1653 1654 GET /v1.19/info HTTP/1.1 1655 1656 **Example response**: 1657 1658 HTTP/1.1 200 OK 1659 Content-Type: application/json 1660 1661 { 1662 "Containers": 11, 1663 "CpuCfsPeriod": true, 1664 "CpuCfsQuota": true, 1665 "Debug": false, 1666 "DockerRootDir": "/var/lib/docker", 1667 "Driver": "btrfs", 1668 "DriverStatus": [[""]], 1669 "ExecutionDriver": "native-0.1", 1670 "ExperimentalBuild": false, 1671 "HttpProxy": "http://test:test@localhost:8080", 1672 "HttpsProxy": "https://test:test@localhost:8080", 1673 "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", 1674 "IPv4Forwarding": true, 1675 "Images": 16, 1676 "IndexServerAddress": "https://index.docker.io/v1/", 1677 "InitPath": "/usr/bin/docker", 1678 "InitSha1": "", 1679 "KernelVersion": "3.12.0-1-amd64", 1680 "Labels": [ 1681 "storage=ssd" 1682 ], 1683 "MemTotal": 2099236864, 1684 "MemoryLimit": true, 1685 "NCPU": 1, 1686 "NEventsListener": 0, 1687 "NFd": 11, 1688 "NGoroutines": 21, 1689 "Name": "prod-server-42", 1690 "NoProxy": "9.81.1.160", 1691 "OomKillDisable": true, 1692 "OperatingSystem": "Boot2Docker", 1693 "RegistryConfig": { 1694 "IndexConfigs": { 1695 "docker.io": { 1696 "Mirrors": null, 1697 "Name": "docker.io", 1698 "Official": true, 1699 "Secure": true 1700 } 1701 }, 1702 "InsecureRegistryCIDRs": [ 1703 "127.0.0.0/8" 1704 ] 1705 }, 1706 "SwapLimit": false, 1707 "SystemTime": "2015-03-10T11:11:23.730591467-07:00" 1708 } 1709 1710 **Status codes**: 1711 1712 - **200** – no error 1713 - **500** – server error 1714 1715 #### Show the docker version information 1716 1717 `GET /version` 1718 1719 Show the docker version information 1720 1721 **Example request**: 1722 1723 GET /v1.19/version HTTP/1.1 1724 1725 **Example response**: 1726 1727 HTTP/1.1 200 OK 1728 Content-Type: application/json 1729 1730 { 1731 "Version": "1.5.0", 1732 "Os": "linux", 1733 "KernelVersion": "3.18.5-tinycore64", 1734 "GoVersion": "go1.4.1", 1735 "GitCommit": "a8a31ef", 1736 "Arch": "amd64", 1737 "ApiVersion": "1.19" 1738 } 1739 1740 **Status codes**: 1741 1742 - **200** – no error 1743 - **500** – server error 1744 1745 #### Ping the docker server 1746 1747 `GET /_ping` 1748 1749 Ping the docker server 1750 1751 **Example request**: 1752 1753 GET /v1.19/_ping HTTP/1.1 1754 1755 **Example response**: 1756 1757 HTTP/1.1 200 OK 1758 Content-Type: text/plain 1759 1760 OK 1761 1762 **Status codes**: 1763 1764 - **200** - no error 1765 - **500** - server error 1766 1767 #### Create a new image from a container's changes 1768 1769 `POST /commit` 1770 1771 Create a new image from a container's changes 1772 1773 **Example request**: 1774 1775 POST /v1.19/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 1776 Content-Type: application/json 1777 1778 { 1779 "Hostname": "", 1780 "Domainname": "", 1781 "User": "", 1782 "AttachStdin": false, 1783 "AttachStdout": true, 1784 "AttachStderr": true, 1785 "PortSpecs": null, 1786 "Tty": false, 1787 "OpenStdin": false, 1788 "StdinOnce": false, 1789 "Env": null, 1790 "Cmd": [ 1791 "date" 1792 ], 1793 "Volumes": { 1794 "/tmp": {} 1795 }, 1796 "Labels": { 1797 "key1": "value1", 1798 "key2": "value2" 1799 }, 1800 "WorkingDir": "", 1801 "NetworkDisabled": false, 1802 "ExposedPorts": { 1803 "22/tcp": {} 1804 } 1805 } 1806 1807 **Example response**: 1808 1809 HTTP/1.1 201 Created 1810 Content-Type: application/json 1811 1812 {"Id": "596069db4bf5"} 1813 1814 **JSON parameters**: 1815 1816 - **config** - the container's configuration 1817 1818 **Query parameters**: 1819 1820 - **container** – source container 1821 - **repo** – repository 1822 - **tag** – tag 1823 - **comment** – commit message 1824 - **author** – author (e.g., "John Hannibal Smith 1825 <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") 1826 1827 **Status codes**: 1828 1829 - **201** – no error 1830 - **404** – no such container 1831 - **500** – server error 1832 1833 #### Monitor Docker's events 1834 1835 `GET /events` 1836 1837 Get container events from docker, in real time via streaming. 1838 1839 Docker containers report the following events: 1840 1841 attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause 1842 1843 Docker images report the following events: 1844 1845 untag, delete 1846 1847 **Example request**: 1848 1849 GET /v1.19/events?since=1374067924 1850 1851 **Example response**: 1852 1853 HTTP/1.1 200 OK 1854 Content-Type: application/json 1855 1856 {"status": "create", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} 1857 {"status": "start", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} 1858 {"status": "stop", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067966} 1859 {"status": "destroy", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067970} 1860 1861 **Query parameters**: 1862 1863 - **since** – Timestamp. Show all events created since timestamp and then stream 1864 - **until** – Timestamp. Show events created until given timestamp and stop streaming 1865 - **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: 1866 - `container=<string>`; -- container to filter 1867 - `event=<string>`; -- event to filter 1868 - `image=<string>`; -- image to filter 1869 1870 **Status codes**: 1871 1872 - **200** – no error 1873 - **500** – server error 1874 1875 #### Get a tarball containing all images in a repository 1876 1877 `GET /images/(name)/get` 1878 1879 Get a tarball containing all images and metadata for the repository specified 1880 by `name`. 1881 1882 If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image 1883 (and its parents) are returned. If `name` is an image ID, similarly only that 1884 image (and its parents) are returned, but with the exclusion of the 1885 'repositories' file in the tarball, as there were no image names referenced. 1886 1887 See the [image tarball format](#image-tarball-format) for more details. 1888 1889 **Example request** 1890 1891 GET /v1.19/images/ubuntu/get 1892 1893 **Example response**: 1894 1895 HTTP/1.1 200 OK 1896 Content-Type: application/x-tar 1897 1898 Binary data stream 1899 1900 **Status codes**: 1901 1902 - **200** – no error 1903 - **500** – server error 1904 1905 #### Get a tarball containing all images 1906 1907 `GET /images/get` 1908 1909 Get a tarball containing all images and metadata for one or more repositories. 1910 1911 For each value of the `names` parameter: if it is a specific name and tag (e.g. 1912 `ubuntu:latest`), then only that image (and its parents) are returned; if it is 1913 an image ID, similarly only that image (and its parents) are returned and there 1914 would be no names referenced in the 'repositories' file for this image ID. 1915 1916 See the [image tarball format](#image-tarball-format) for more details. 1917 1918 **Example request** 1919 1920 GET /v1.19/images/get?names=myname%2Fmyapp%3Alatest&names=busybox 1921 1922 **Example response**: 1923 1924 HTTP/1.1 200 OK 1925 Content-Type: application/x-tar 1926 1927 Binary data stream 1928 1929 **Status codes**: 1930 1931 - **200** – no error 1932 - **500** – server error 1933 1934 #### Load a tarball with a set of images and tags into docker 1935 1936 `POST /images/load` 1937 1938 Load a set of images and tags into a Docker repository. 1939 See the [image tarball format](#image-tarball-format) for more details. 1940 1941 **Example request** 1942 1943 POST /v1.19/images/load 1944 Content-Type: application/x-tar 1945 1946 Tarball in body 1947 1948 **Example response**: 1949 1950 HTTP/1.1 200 OK 1951 1952 **Status codes**: 1953 1954 - **200** – no error 1955 - **500** – server error 1956 1957 #### Image tarball format 1958 1959 An image tarball contains one directory per image layer (named using its long ID), 1960 each containing these files: 1961 1962 - `VERSION`: currently `1.0` - the file format version 1963 - `json`: detailed layer information, similar to `docker inspect layer_id` 1964 - `layer.tar`: A tarfile containing the filesystem changes in this layer 1965 1966 The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories 1967 for storing attribute changes and deletions. 1968 1969 If the tarball defines a repository, the tarball should also include a `repositories` file at 1970 the root that contains a list of repository and tag names mapped to layer IDs. 1971 1972 ``` 1973 {"hello-world": 1974 {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} 1975 } 1976 ``` 1977 1978 #### Exec Create 1979 1980 `POST /containers/(id or name)/exec` 1981 1982 Sets up an exec instance in a running container `id` 1983 1984 **Example request**: 1985 1986 POST /v1.19/containers/e90e34656806/exec HTTP/1.1 1987 Content-Type: application/json 1988 1989 { 1990 "AttachStdin": true, 1991 "AttachStdout": true, 1992 "AttachStderr": true, 1993 "Cmd": ["sh"], 1994 "Tty": true, 1995 "User": "123:456" 1996 } 1997 1998 **Example response**: 1999 2000 HTTP/1.1 201 Created 2001 Content-Type: application/json 2002 2003 { 2004 "Id": "f90e34656806", 2005 "Warnings":[] 2006 } 2007 2008 **JSON parameters**: 2009 2010 - **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. 2011 - **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. 2012 - **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. 2013 - **Tty** - Boolean value to allocate a pseudo-TTY. 2014 - **Cmd** - Command to run specified as a string or an array of strings. 2015 - **User** - A string value specifying the user, and optionally, group to run 2016 the exec process inside the container. Format is one of: `"user"`, 2017 `"user:group"`, `"uid"`, or `"uid:gid"`. 2018 2019 **Status codes**: 2020 2021 - **201** – no error 2022 - **404** – no such container 2023 2024 #### Exec Start 2025 2026 `POST /exec/(id)/start` 2027 2028 Starts a previously set up `exec` instance `id`. If `detach` is true, this API 2029 returns after starting the `exec` command. Otherwise, this API sets up an 2030 interactive session with the `exec` command. 2031 2032 **Example request**: 2033 2034 POST /v1.19/exec/e90e34656806/start HTTP/1.1 2035 Content-Type: application/json 2036 2037 { 2038 "Detach": false, 2039 "Tty": false 2040 } 2041 2042 **Example response**: 2043 2044 HTTP/1.1 200 OK 2045 Content-Type: application/vnd.docker.raw-stream 2046 2047 {% raw %} 2048 {{ STREAM }} 2049 {% endraw %} 2050 2051 **JSON parameters**: 2052 2053 - **Detach** - Detach from the `exec` command. 2054 - **Tty** - Boolean value to allocate a pseudo-TTY. 2055 2056 **Status codes**: 2057 2058 - **200** – no error 2059 - **404** – no such exec instance 2060 2061 **Stream details**: 2062 2063 Similar to the stream behavior of `POST /containers/(id or name)/attach` API 2064 2065 #### Exec Resize 2066 2067 `POST /exec/(id)/resize` 2068 2069 Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. 2070 This API is valid only if `tty` was specified as part of creating and starting the `exec` command. 2071 2072 **Example request**: 2073 2074 POST /v1.19/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 2075 Content-Type: text/plain 2076 2077 **Example response**: 2078 2079 HTTP/1.1 201 Created 2080 Content-Type: text/plain 2081 2082 **Query parameters**: 2083 2084 - **h** – height of `tty` session 2085 - **w** – width 2086 2087 **Status codes**: 2088 2089 - **201** – no error 2090 - **404** – no such exec instance 2091 2092 #### Exec Inspect 2093 2094 `GET /exec/(id)/json` 2095 2096 Return low-level information about the `exec` command `id`. 2097 2098 **Example request**: 2099 2100 GET /v1.19/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 2101 2102 **Example response**: 2103 2104 HTTP/1.1 200 OK 2105 Content-Type: plain/text 2106 2107 { 2108 "ID" : "11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39", 2109 "Running" : false, 2110 "ExitCode" : 2, 2111 "ProcessConfig" : { 2112 "privileged" : false, 2113 "user" : "", 2114 "tty" : false, 2115 "entrypoint" : "sh", 2116 "arguments" : [ 2117 "-c", 2118 "exit 2" 2119 ] 2120 }, 2121 "OpenStdin" : false, 2122 "OpenStderr" : false, 2123 "OpenStdout" : false, 2124 "Container" : { 2125 "State" : { 2126 "Running" : true, 2127 "Paused" : false, 2128 "Restarting" : false, 2129 "OOMKilled" : false, 2130 "Pid" : 3650, 2131 "ExitCode" : 0, 2132 "Error" : "", 2133 "StartedAt" : "2014-11-17T22:26:03.717657531Z", 2134 "FinishedAt" : "0001-01-01T00:00:00Z" 2135 }, 2136 "ID" : "8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c", 2137 "Created" : "2014-11-17T22:26:03.626304998Z", 2138 "Path" : "date", 2139 "Args" : [], 2140 "Config" : { 2141 "Hostname" : "8f177a186b97", 2142 "Domainname" : "", 2143 "User" : "", 2144 "AttachStdin" : false, 2145 "AttachStdout" : false, 2146 "AttachStderr" : false, 2147 "PortSpecs": null, 2148 "ExposedPorts" : null, 2149 "Tty" : false, 2150 "OpenStdin" : false, 2151 "StdinOnce" : false, 2152 "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], 2153 "Cmd" : [ 2154 "date" 2155 ], 2156 "Image" : "ubuntu", 2157 "Volumes" : null, 2158 "WorkingDir" : "", 2159 "Entrypoint" : null, 2160 "NetworkDisabled" : false, 2161 "MacAddress" : "", 2162 "OnBuild" : null, 2163 "SecurityOpt" : null 2164 }, 2165 "Image" : "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5", 2166 "NetworkSettings" : { 2167 "IPAddress" : "172.17.0.2", 2168 "IPPrefixLen" : 16, 2169 "MacAddress" : "02:42:ac:11:00:02", 2170 "Gateway" : "172.17.42.1", 2171 "Bridge" : "docker0", 2172 "PortMapping" : null, 2173 "Ports" : {} 2174 }, 2175 "ResolvConfPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/resolv.conf", 2176 "HostnamePath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hostname", 2177 "HostsPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hosts", 2178 "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", 2179 "Name" : "/test", 2180 "Driver" : "aufs", 2181 "ExecDriver" : "native-0.2", 2182 "MountLabel" : "", 2183 "ProcessLabel" : "", 2184 "AppArmorProfile" : "", 2185 "RestartCount" : 0, 2186 "Volumes" : {}, 2187 "VolumesRW" : {} 2188 } 2189 } 2190 2191 **Status codes**: 2192 2193 - **200** – no error 2194 - **404** – no such exec instance 2195 - **500** - server error 2196 2197 ## 3. Going further 2198 2199 ### 3.1 Inside `docker run` 2200 2201 As an example, the `docker run` command line makes the following API calls: 2202 2203 - Create the container 2204 2205 - If the status code is 404, it means the image doesn't exist: 2206 - Try to pull it. 2207 - Then, retry to create the container. 2208 2209 - Start the container. 2210 2211 - If you are not in detached mode: 2212 - Attach to the container, using `logs=1` (to have `stdout` and 2213 `stderr` from the container's start) and `stream=1` 2214 2215 - If in detached mode or only `stdin` is attached, display the container's id. 2216 2217 ### 3.2 Hijacking 2218 2219 In this version of the API, `/attach`, uses hijacking to transport `stdin`, 2220 `stdout`, and `stderr` on the same socket. 2221 2222 To hint potential proxies about connection hijacking, Docker client sends 2223 connection upgrade headers similarly to websocket. 2224 2225 Upgrade: tcp 2226 Connection: Upgrade 2227 2228 When Docker daemon detects the `Upgrade` header, it switches its status code 2229 from **200 OK** to **101 UPGRADED** and resends the same headers. 2230 2231 2232 ### 3.3 CORS Requests 2233 2234 To set cross origin requests to the Engine API please give values to 2235 `--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, 2236 default or blank means CORS disabled 2237 2238 $ docker -d -H="192.168.1.9:2375" --api-cors-header="http://foo.bar"