github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/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 - **link** - 1/True/true or 0/False/false, Remove the specified 1099 link associated to the container. Default `false`. 1100 1101 **Status codes**: 1102 1103 - **204** – no error 1104 - **400** – bad parameter 1105 - **404** – no such container 1106 - **409** – conflict 1107 - **500** – server error 1108 1109 #### Copy files or folders from a container 1110 1111 `POST /containers/(id or name)/copy` 1112 1113 Copy files or folders of container `id` 1114 1115 **Example request**: 1116 1117 POST /v1.19/containers/4fa6e0f0c678/copy HTTP/1.1 1118 Content-Type: application/json 1119 1120 { 1121 "Resource": "test.txt" 1122 } 1123 1124 **Example response**: 1125 1126 HTTP/1.1 200 OK 1127 Content-Type: application/x-tar 1128 1129 {% raw %} 1130 {{ TAR STREAM }} 1131 {% endraw %} 1132 1133 **Status codes**: 1134 1135 - **200** – no error 1136 - **404** – no such container 1137 - **500** – server error 1138 1139 ### 2.2 Images 1140 1141 #### List Images 1142 1143 `GET /images/json` 1144 1145 **Example request**: 1146 1147 GET /v1.19/images/json?all=0 HTTP/1.1 1148 1149 **Example response**: 1150 1151 HTTP/1.1 200 OK 1152 Content-Type: application/json 1153 1154 [ 1155 { 1156 "RepoTags": [ 1157 "ubuntu:12.04", 1158 "ubuntu:precise", 1159 "ubuntu:latest" 1160 ], 1161 "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", 1162 "Created": 1365714795, 1163 "Size": 131506275, 1164 "VirtualSize": 131506275, 1165 "Labels": {} 1166 }, 1167 { 1168 "RepoTags": [ 1169 "ubuntu:12.10", 1170 "ubuntu:quantal" 1171 ], 1172 "ParentId": "27cf784147099545", 1173 "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 1174 "Created": 1364102658, 1175 "Size": 24653, 1176 "VirtualSize": 180116135, 1177 "Labels": { 1178 "com.example.version": "v1" 1179 } 1180 } 1181 ] 1182 1183 **Example request, with digest information**: 1184 1185 GET /v1.19/images/json?digests=1 HTTP/1.1 1186 1187 **Example response, with digest information**: 1188 1189 HTTP/1.1 200 OK 1190 Content-Type: application/json 1191 1192 [ 1193 { 1194 "Created": 1420064636, 1195 "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", 1196 "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", 1197 "RepoDigests": [ 1198 "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" 1199 ], 1200 "RepoTags": [ 1201 "localhost:5000/test/busybox:latest", 1202 "playdate:latest" 1203 ], 1204 "Size": 0, 1205 "VirtualSize": 2429728, 1206 "Labels": {} 1207 } 1208 ] 1209 1210 The response shows a single image `Id` associated with two repositories 1211 (`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use 1212 either of the `RepoTags` values `localhost:5000/test/busybox:latest` or 1213 `playdate:latest` to reference the image. 1214 1215 You can also use `RepoDigests` values to reference an image. In this response, 1216 the array has only one reference and that is to the 1217 `localhost:5000/test/busybox` repository; the `playdate` repository has no 1218 digest. You can reference this digest using the value: 1219 `localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` 1220 1221 See the `docker run` and `docker build` commands for examples of digest and tag 1222 references on the command line. 1223 1224 **Query parameters**: 1225 1226 - **all** – 1/True/true or 0/False/false, default false 1227 - **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: 1228 - `dangling=true` 1229 - `label=key` or `label="key=value"` of an image label 1230 - **filter** - only return images with the specified name 1231 1232 #### Build image from a Dockerfile 1233 1234 `POST /build` 1235 1236 Build an image from a Dockerfile 1237 1238 **Example request**: 1239 1240 POST /v1.19/build HTTP/1.1 1241 Content-Type: application/x-tar 1242 1243 {% raw %} 1244 {{ TAR STREAM }} 1245 {% endraw %} 1246 1247 **Example response**: 1248 1249 HTTP/1.1 200 OK 1250 Content-Type: application/json 1251 1252 {"stream": "Step 1/5..."} 1253 {"stream": "..."} 1254 {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} 1255 1256 The input stream must be a `tar` archive compressed with one of the 1257 following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. 1258 1259 The archive must include a build instructions file, typically called 1260 `Dockerfile` at the archive's root. The `dockerfile` parameter may be 1261 used to specify a different build instructions file. To do this, its value must be 1262 the path to the alternate build instructions file to use. 1263 1264 The archive may include any number of other files, 1265 which are accessible in the build context (See the [*ADD build 1266 command*](../reference/builder.md#add)). 1267 1268 The Docker daemon performs a preliminary validation of the `Dockerfile` before 1269 starting the build, and returns an error if the syntax is incorrect. After that, 1270 each instruction is run one-by-one until the ID of the new image is output. 1271 1272 The build is canceled if the client drops the connection by quitting 1273 or being killed. 1274 1275 **Query parameters**: 1276 1277 - **dockerfile** - Path within the build context to the Dockerfile. This is 1278 ignored if `remote` is specified and points to an individual filename. 1279 - **t** – A name and optional tag to apply to the image in the `name:tag` format. 1280 If you omit the `tag` the default `latest` value is assumed. 1281 - **remote** – A Git repository URI or HTTP/HTTPS URI build source. If the 1282 URI specifies a filename, the file's contents are placed into a file 1283 called `Dockerfile`. 1284 - **q** – Suppress verbose build output. 1285 - **nocache** – Do not use the cache when building the image. 1286 - **pull** - Attempt to pull the image even if an older image exists locally. 1287 - **rm** - Remove intermediate containers after a successful build (default behavior). 1288 - **forcerm** - Always remove intermediate containers (includes `rm`). 1289 - **memory** - Set memory limit for build. 1290 - **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. 1291 - **cpushares** - CPU shares (relative weight). 1292 - **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). 1293 - **cpuperiod** - The length of a CPU period in microseconds. 1294 - **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. 1295 1296 **Request Headers**: 1297 1298 - **Content-type** – Set to `"application/x-tar"`. 1299 - **X-Registry-Config** – base64-encoded ConfigFile object 1300 1301 **Status codes**: 1302 1303 - **200** – no error 1304 - **500** – server error 1305 1306 #### Create an image 1307 1308 `POST /images/create` 1309 1310 Create an image either by pulling it from the registry or by importing it 1311 1312 **Example request**: 1313 1314 POST /v1.19/images/create?fromImage=busybox&tag=latest HTTP/1.1 1315 1316 **Example response**: 1317 1318 HTTP/1.1 200 OK 1319 Content-Type: application/json 1320 1321 {"status": "Pulling..."} 1322 {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} 1323 {"error": "Invalid..."} 1324 ... 1325 1326 When using this endpoint to pull an image from the registry, the 1327 `X-Registry-Auth` header can be used to include 1328 a base64-encoded AuthConfig object. 1329 1330 **Query parameters**: 1331 1332 - **fromImage** – Name of the image to pull. 1333 - **fromSrc** – Source to import. The value may be a URL from which the image 1334 can be retrieved or `-` to read the image from the request body. 1335 - **repo** – Repository name. 1336 - **tag** – Tag. If empty when pulling an image, this causes all tags 1337 for the given image to be pulled. 1338 1339 **Request Headers**: 1340 1341 - **X-Registry-Auth** – base64-encoded AuthConfig object 1342 1343 **Status codes**: 1344 1345 - **200** – no error 1346 - **404** - repository does not exist or no read access 1347 - **500** – server error 1348 1349 1350 1351 #### Inspect an image 1352 1353 `GET /images/(name)/json` 1354 1355 Return low-level information on the image `name` 1356 1357 **Example request**: 1358 1359 GET /v1.19/images/ubuntu/json HTTP/1.1 1360 1361 **Example response**: 1362 1363 HTTP/1.1 200 OK 1364 Content-Type: application/json 1365 1366 { 1367 "Created": "2013-03-23T22:24:18.818426-07:00", 1368 "Container": "3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", 1369 "ContainerConfig": { 1370 "Hostname": "", 1371 "User": "", 1372 "AttachStdin": false, 1373 "AttachStdout": false, 1374 "AttachStderr": false, 1375 "Tty": true, 1376 "OpenStdin": true, 1377 "StdinOnce": false, 1378 "Env": null, 1379 "Cmd": ["/bin/bash"], 1380 "Dns": null, 1381 "Image": "ubuntu", 1382 "Labels": { 1383 "com.example.vendor": "Acme", 1384 "com.example.license": "GPL", 1385 "com.example.version": "1.0" 1386 }, 1387 "Volumes": null, 1388 "VolumesFrom": "", 1389 "WorkingDir": "" 1390 }, 1391 "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 1392 "Parent": "27cf784147099545", 1393 "Size": 6824592 1394 } 1395 1396 **Status codes**: 1397 1398 - **200** – no error 1399 - **404** – no such image 1400 - **500** – server error 1401 1402 #### Get the history of an image 1403 1404 `GET /images/(name)/history` 1405 1406 Return the history of the image `name` 1407 1408 **Example request**: 1409 1410 GET /v1.19/images/ubuntu/history HTTP/1.1 1411 1412 **Example response**: 1413 1414 HTTP/1.1 200 OK 1415 Content-Type: application/json 1416 1417 [ 1418 { 1419 "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", 1420 "Created": 1398108230, 1421 "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", 1422 "Tags": [ 1423 "ubuntu:lucid", 1424 "ubuntu:10.04" 1425 ], 1426 "Size": 182964289, 1427 "Comment": "" 1428 }, 1429 { 1430 "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", 1431 "Created": 1398108222, 1432 "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/", 1433 "Tags": null, 1434 "Size": 0, 1435 "Comment": "" 1436 }, 1437 { 1438 "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", 1439 "Created": 1371157430, 1440 "CreatedBy": "", 1441 "Tags": [ 1442 "scratch12:latest", 1443 "scratch:latest" 1444 ], 1445 "Size": 0, 1446 "Comment": "Imported from -" 1447 } 1448 ] 1449 1450 **Status codes**: 1451 1452 - **200** – no error 1453 - **404** – no such image 1454 - **500** – server error 1455 1456 #### Push an image on the registry 1457 1458 `POST /images/(name)/push` 1459 1460 Push the image `name` on the registry 1461 1462 **Example request**: 1463 1464 POST /v1.19/images/test/push HTTP/1.1 1465 1466 **Example response**: 1467 1468 HTTP/1.1 200 OK 1469 Content-Type: application/json 1470 1471 {"status": "Pushing..."} 1472 {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} 1473 {"error": "Invalid..."} 1474 ... 1475 1476 If you wish to push an image on to a private registry, that image must already have a tag 1477 into a repository which references that registry `hostname` and `port`. This repository name should 1478 then be used in the URL. This duplicates the command line's flow. 1479 1480 **Example request**: 1481 1482 POST /v1.19/images/registry.acme.com:5000/test/push HTTP/1.1 1483 1484 1485 **Query parameters**: 1486 1487 - **tag** – The tag to associate with the image on the registry. This is optional. 1488 1489 **Request Headers**: 1490 1491 - **X-Registry-Auth** – base64-encoded AuthConfig object. 1492 1493 **Status codes**: 1494 1495 - **200** – no error 1496 - **404** – no such image 1497 - **500** – server error 1498 1499 #### Tag an image into a repository 1500 1501 `POST /images/(name)/tag` 1502 1503 Tag the image `name` into a repository 1504 1505 **Example request**: 1506 1507 POST /v1.19/images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 1508 1509 **Example response**: 1510 1511 HTTP/1.1 201 Created 1512 1513 **Query parameters**: 1514 1515 - **repo** – The repository to tag in 1516 - **force** – 1/True/true or 0/False/false, default false 1517 - **tag** - The new tag name 1518 1519 **Status codes**: 1520 1521 - **201** – no error 1522 - **400** – bad parameter 1523 - **404** – no such image 1524 - **409** – conflict 1525 - **500** – server error 1526 1527 #### Remove an image 1528 1529 `DELETE /images/(name)` 1530 1531 Remove the image `name` from the filesystem 1532 1533 **Example request**: 1534 1535 DELETE /v1.19/images/test HTTP/1.1 1536 1537 **Example response**: 1538 1539 HTTP/1.1 200 OK 1540 Content-type: application/json 1541 1542 [ 1543 {"Untagged": "3e2f21a89f"}, 1544 {"Deleted": "3e2f21a89f"}, 1545 {"Deleted": "53b4f83ac9"} 1546 ] 1547 1548 **Query parameters**: 1549 1550 - **force** – 1/True/true or 0/False/false, default false 1551 - **noprune** – 1/True/true or 0/False/false, default false 1552 1553 **Status codes**: 1554 1555 - **200** – no error 1556 - **404** – no such image 1557 - **409** – conflict 1558 - **500** – server error 1559 1560 #### Search images 1561 1562 `GET /images/search` 1563 1564 Search for an image on [Docker Hub](https://hub.docker.com). This API 1565 returns both `is_trusted` and `is_automated` images. Currently, they 1566 are considered identical. In the future, the `is_trusted` property will 1567 be deprecated and replaced by the `is_automated` property. 1568 1569 > **Note**: 1570 > The response keys have changed from API v1.6 to reflect the JSON 1571 > sent by the registry server to the docker daemon's request. 1572 1573 **Example request**: 1574 1575 GET /v1.19/images/search?term=sshd HTTP/1.1 1576 1577 **Example response**: 1578 1579 HTTP/1.1 200 OK 1580 Content-Type: application/json 1581 1582 [ 1583 { 1584 "star_count": 12, 1585 "is_official": false, 1586 "name": "wma55/u1210sshd", 1587 "is_trusted": false, 1588 "is_automated": false, 1589 "description": "" 1590 }, 1591 { 1592 "star_count": 10, 1593 "is_official": false, 1594 "name": "jdswinbank/sshd", 1595 "is_trusted": false, 1596 "is_automated": false, 1597 "description": "" 1598 }, 1599 { 1600 "star_count": 18, 1601 "is_official": false, 1602 "name": "vgauthier/sshd", 1603 "is_trusted": false, 1604 "is_automated": false, 1605 "description": "" 1606 } 1607 ... 1608 ] 1609 1610 **Query parameters**: 1611 1612 - **term** – term to search 1613 1614 **Status codes**: 1615 1616 - **200** – no error 1617 - **500** – server error 1618 1619 ### 2.3 Misc 1620 1621 #### Check auth configuration 1622 1623 `POST /auth` 1624 1625 Get the default username and email 1626 1627 **Example request**: 1628 1629 POST /v1.19/auth HTTP/1.1 1630 Content-Type: application/json 1631 1632 { 1633 "username": "hannibal", 1634 "password": "xxxx", 1635 "email": "hannibal@a-team.com", 1636 "serveraddress": "https://index.docker.io/v1/" 1637 } 1638 1639 **Example response**: 1640 1641 HTTP/1.1 200 OK 1642 1643 **Status codes**: 1644 1645 - **200** – no error 1646 - **204** – no error 1647 - **500** – server error 1648 1649 #### Display system-wide information 1650 1651 `GET /info` 1652 1653 Display system-wide information 1654 1655 **Example request**: 1656 1657 GET /v1.19/info HTTP/1.1 1658 1659 **Example response**: 1660 1661 HTTP/1.1 200 OK 1662 Content-Type: application/json 1663 1664 { 1665 "Containers": 11, 1666 "CpuCfsPeriod": true, 1667 "CpuCfsQuota": true, 1668 "Debug": false, 1669 "DockerRootDir": "/var/lib/docker", 1670 "Driver": "btrfs", 1671 "DriverStatus": [[""]], 1672 "ExecutionDriver": "native-0.1", 1673 "ExperimentalBuild": false, 1674 "HttpProxy": "http://test:test@localhost:8080", 1675 "HttpsProxy": "https://test:test@localhost:8080", 1676 "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", 1677 "IPv4Forwarding": true, 1678 "Images": 16, 1679 "IndexServerAddress": "https://index.docker.io/v1/", 1680 "InitPath": "/usr/bin/docker", 1681 "InitSha1": "", 1682 "KernelVersion": "3.12.0-1-amd64", 1683 "Labels": [ 1684 "storage=ssd" 1685 ], 1686 "MemTotal": 2099236864, 1687 "MemoryLimit": true, 1688 "NCPU": 1, 1689 "NEventsListener": 0, 1690 "NFd": 11, 1691 "NGoroutines": 21, 1692 "Name": "prod-server-42", 1693 "NoProxy": "9.81.1.160", 1694 "OomKillDisable": true, 1695 "OperatingSystem": "Boot2Docker", 1696 "RegistryConfig": { 1697 "IndexConfigs": { 1698 "docker.io": { 1699 "Mirrors": null, 1700 "Name": "docker.io", 1701 "Official": true, 1702 "Secure": true 1703 } 1704 }, 1705 "InsecureRegistryCIDRs": [ 1706 "127.0.0.0/8" 1707 ] 1708 }, 1709 "SwapLimit": false, 1710 "SystemTime": "2015-03-10T11:11:23.730591467-07:00" 1711 } 1712 1713 **Status codes**: 1714 1715 - **200** – no error 1716 - **500** – server error 1717 1718 #### Show the docker version information 1719 1720 `GET /version` 1721 1722 Show the docker version information 1723 1724 **Example request**: 1725 1726 GET /v1.19/version HTTP/1.1 1727 1728 **Example response**: 1729 1730 HTTP/1.1 200 OK 1731 Content-Type: application/json 1732 1733 { 1734 "Version": "1.5.0", 1735 "Os": "linux", 1736 "KernelVersion": "3.18.5-tinycore64", 1737 "GoVersion": "go1.4.1", 1738 "GitCommit": "a8a31ef", 1739 "Arch": "amd64", 1740 "ApiVersion": "1.19" 1741 } 1742 1743 **Status codes**: 1744 1745 - **200** – no error 1746 - **500** – server error 1747 1748 #### Ping the docker server 1749 1750 `GET /_ping` 1751 1752 Ping the docker server 1753 1754 **Example request**: 1755 1756 GET /v1.19/_ping HTTP/1.1 1757 1758 **Example response**: 1759 1760 HTTP/1.1 200 OK 1761 Content-Type: text/plain 1762 1763 OK 1764 1765 **Status codes**: 1766 1767 - **200** - no error 1768 - **500** - server error 1769 1770 #### Create a new image from a container's changes 1771 1772 `POST /commit` 1773 1774 Create a new image from a container's changes 1775 1776 **Example request**: 1777 1778 POST /v1.19/commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 1779 Content-Type: application/json 1780 1781 { 1782 "Hostname": "", 1783 "Domainname": "", 1784 "User": "", 1785 "AttachStdin": false, 1786 "AttachStdout": true, 1787 "AttachStderr": true, 1788 "PortSpecs": null, 1789 "Tty": false, 1790 "OpenStdin": false, 1791 "StdinOnce": false, 1792 "Env": null, 1793 "Cmd": [ 1794 "date" 1795 ], 1796 "Volumes": { 1797 "/tmp": {} 1798 }, 1799 "Labels": { 1800 "key1": "value1", 1801 "key2": "value2" 1802 }, 1803 "WorkingDir": "", 1804 "NetworkDisabled": false, 1805 "ExposedPorts": { 1806 "22/tcp": {} 1807 } 1808 } 1809 1810 **Example response**: 1811 1812 HTTP/1.1 201 Created 1813 Content-Type: application/json 1814 1815 {"Id": "596069db4bf5"} 1816 1817 **JSON parameters**: 1818 1819 - **config** - the container's configuration 1820 1821 **Query parameters**: 1822 1823 - **container** – source container 1824 - **repo** – repository 1825 - **tag** – tag 1826 - **comment** – commit message 1827 - **author** – author (e.g., "John Hannibal Smith 1828 <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") 1829 1830 **Status codes**: 1831 1832 - **201** – no error 1833 - **404** – no such container 1834 - **500** – server error 1835 1836 #### Monitor Docker's events 1837 1838 `GET /events` 1839 1840 Get container events from docker, in real time via streaming. 1841 1842 Docker containers report the following events: 1843 1844 attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause 1845 1846 Docker images report the following events: 1847 1848 untag, delete 1849 1850 **Example request**: 1851 1852 GET /v1.19/events?since=1374067924 1853 1854 **Example response**: 1855 1856 HTTP/1.1 200 OK 1857 Content-Type: application/json 1858 1859 {"status": "create", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} 1860 {"status": "start", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067924} 1861 {"status": "stop", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067966} 1862 {"status": "destroy", "id": "dfdf82bd3881","from": "ubuntu:latest", "time":1374067970} 1863 1864 **Query parameters**: 1865 1866 - **since** – Timestamp. Show all events created since timestamp and then stream 1867 - **until** – Timestamp. Show events created until given timestamp and stop streaming 1868 - **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: 1869 - `container=<string>`; -- container to filter 1870 - `event=<string>`; -- event to filter 1871 - `image=<string>`; -- image to filter 1872 1873 **Status codes**: 1874 1875 - **200** – no error 1876 - **500** – server error 1877 1878 #### Get a tarball containing all images in a repository 1879 1880 `GET /images/(name)/get` 1881 1882 Get a tarball containing all images and metadata for the repository specified 1883 by `name`. 1884 1885 If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image 1886 (and its parents) are returned. If `name` is an image ID, similarly only that 1887 image (and its parents) are returned, but with the exclusion of the 1888 'repositories' file in the tarball, as there were no image names referenced. 1889 1890 See the [image tarball format](#image-tarball-format) for more details. 1891 1892 **Example request** 1893 1894 GET /v1.19/images/ubuntu/get 1895 1896 **Example response**: 1897 1898 HTTP/1.1 200 OK 1899 Content-Type: application/x-tar 1900 1901 Binary data stream 1902 1903 **Status codes**: 1904 1905 - **200** – no error 1906 - **500** – server error 1907 1908 #### Get a tarball containing all images 1909 1910 `GET /images/get` 1911 1912 Get a tarball containing all images and metadata for one or more repositories. 1913 1914 For each value of the `names` parameter: if it is a specific name and tag (e.g. 1915 `ubuntu:latest`), then only that image (and its parents) are returned; if it is 1916 an image ID, similarly only that image (and its parents) are returned and there 1917 would be no names referenced in the 'repositories' file for this image ID. 1918 1919 See the [image tarball format](#image-tarball-format) for more details. 1920 1921 **Example request** 1922 1923 GET /v1.19/images/get?names=myname%2Fmyapp%3Alatest&names=busybox 1924 1925 **Example response**: 1926 1927 HTTP/1.1 200 OK 1928 Content-Type: application/x-tar 1929 1930 Binary data stream 1931 1932 **Status codes**: 1933 1934 - **200** – no error 1935 - **500** – server error 1936 1937 #### Load a tarball with a set of images and tags into docker 1938 1939 `POST /images/load` 1940 1941 Load a set of images and tags into a Docker repository. 1942 See the [image tarball format](#image-tarball-format) for more details. 1943 1944 **Example request** 1945 1946 POST /v1.19/images/load 1947 Content-Type: application/x-tar 1948 1949 Tarball in body 1950 1951 **Example response**: 1952 1953 HTTP/1.1 200 OK 1954 1955 **Status codes**: 1956 1957 - **200** – no error 1958 - **500** – server error 1959 1960 #### Image tarball format 1961 1962 An image tarball contains one directory per image layer (named using its long ID), 1963 each containing these files: 1964 1965 - `VERSION`: currently `1.0` - the file format version 1966 - `json`: detailed layer information, similar to `docker inspect layer_id` 1967 - `layer.tar`: A tarfile containing the filesystem changes in this layer 1968 1969 The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories 1970 for storing attribute changes and deletions. 1971 1972 If the tarball defines a repository, the tarball should also include a `repositories` file at 1973 the root that contains a list of repository and tag names mapped to layer IDs. 1974 1975 ``` 1976 {"hello-world": 1977 {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} 1978 } 1979 ``` 1980 1981 #### Exec Create 1982 1983 `POST /containers/(id or name)/exec` 1984 1985 Sets up an exec instance in a running container `id` 1986 1987 **Example request**: 1988 1989 POST /v1.19/containers/e90e34656806/exec HTTP/1.1 1990 Content-Type: application/json 1991 1992 { 1993 "AttachStdin": true, 1994 "AttachStdout": true, 1995 "AttachStderr": true, 1996 "Cmd": ["sh"], 1997 "Tty": true, 1998 "User": "123:456" 1999 } 2000 2001 **Example response**: 2002 2003 HTTP/1.1 201 Created 2004 Content-Type: application/json 2005 2006 { 2007 "Id": "f90e34656806", 2008 "Warnings":[] 2009 } 2010 2011 **JSON parameters**: 2012 2013 - **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. 2014 - **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. 2015 - **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. 2016 - **Tty** - Boolean value to allocate a pseudo-TTY. 2017 - **Cmd** - Command to run specified as a string or an array of strings. 2018 - **User** - A string value specifying the user, and optionally, group to run 2019 the exec process inside the container. Format is one of: `"user"`, 2020 `"user:group"`, `"uid"`, or `"uid:gid"`. 2021 2022 **Status codes**: 2023 2024 - **201** – no error 2025 - **404** – no such container 2026 2027 #### Exec Start 2028 2029 `POST /exec/(id)/start` 2030 2031 Starts a previously set up `exec` instance `id`. If `detach` is true, this API 2032 returns after starting the `exec` command. Otherwise, this API sets up an 2033 interactive session with the `exec` command. 2034 2035 **Example request**: 2036 2037 POST /v1.19/exec/e90e34656806/start HTTP/1.1 2038 Content-Type: application/json 2039 2040 { 2041 "Detach": false, 2042 "Tty": false 2043 } 2044 2045 **Example response**: 2046 2047 HTTP/1.1 200 OK 2048 Content-Type: application/vnd.docker.raw-stream 2049 2050 {% raw %} 2051 {{ STREAM }} 2052 {% endraw %} 2053 2054 **JSON parameters**: 2055 2056 - **Detach** - Detach from the `exec` command. 2057 - **Tty** - Boolean value to allocate a pseudo-TTY. 2058 2059 **Status codes**: 2060 2061 - **200** – no error 2062 - **404** – no such exec instance 2063 2064 **Stream details**: 2065 2066 Similar to the stream behavior of `POST /containers/(id or name)/attach` API 2067 2068 #### Exec Resize 2069 2070 `POST /exec/(id)/resize` 2071 2072 Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. 2073 This API is valid only if `tty` was specified as part of creating and starting the `exec` command. 2074 2075 **Example request**: 2076 2077 POST /v1.19/exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 2078 Content-Type: text/plain 2079 2080 **Example response**: 2081 2082 HTTP/1.1 201 Created 2083 Content-Type: text/plain 2084 2085 **Query parameters**: 2086 2087 - **h** – height of `tty` session 2088 - **w** – width 2089 2090 **Status codes**: 2091 2092 - **201** – no error 2093 - **404** – no such exec instance 2094 2095 #### Exec Inspect 2096 2097 `GET /exec/(id)/json` 2098 2099 Return low-level information about the `exec` command `id`. 2100 2101 **Example request**: 2102 2103 GET /v1.19/exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 2104 2105 **Example response**: 2106 2107 HTTP/1.1 200 OK 2108 Content-Type: plain/text 2109 2110 { 2111 "ID" : "11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39", 2112 "Running" : false, 2113 "ExitCode" : 2, 2114 "ProcessConfig" : { 2115 "privileged" : false, 2116 "user" : "", 2117 "tty" : false, 2118 "entrypoint" : "sh", 2119 "arguments" : [ 2120 "-c", 2121 "exit 2" 2122 ] 2123 }, 2124 "OpenStdin" : false, 2125 "OpenStderr" : false, 2126 "OpenStdout" : false, 2127 "Container" : { 2128 "State" : { 2129 "Running" : true, 2130 "Paused" : false, 2131 "Restarting" : false, 2132 "OOMKilled" : false, 2133 "Pid" : 3650, 2134 "ExitCode" : 0, 2135 "Error" : "", 2136 "StartedAt" : "2014-11-17T22:26:03.717657531Z", 2137 "FinishedAt" : "0001-01-01T00:00:00Z" 2138 }, 2139 "ID" : "8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c", 2140 "Created" : "2014-11-17T22:26:03.626304998Z", 2141 "Path" : "date", 2142 "Args" : [], 2143 "Config" : { 2144 "Hostname" : "8f177a186b97", 2145 "Domainname" : "", 2146 "User" : "", 2147 "AttachStdin" : false, 2148 "AttachStdout" : false, 2149 "AttachStderr" : false, 2150 "PortSpecs": null, 2151 "ExposedPorts" : null, 2152 "Tty" : false, 2153 "OpenStdin" : false, 2154 "StdinOnce" : false, 2155 "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], 2156 "Cmd" : [ 2157 "date" 2158 ], 2159 "Image" : "ubuntu", 2160 "Volumes" : null, 2161 "WorkingDir" : "", 2162 "Entrypoint" : null, 2163 "NetworkDisabled" : false, 2164 "MacAddress" : "", 2165 "OnBuild" : null, 2166 "SecurityOpt" : null 2167 }, 2168 "Image" : "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5", 2169 "NetworkSettings" : { 2170 "IPAddress" : "172.17.0.2", 2171 "IPPrefixLen" : 16, 2172 "MacAddress" : "02:42:ac:11:00:02", 2173 "Gateway" : "172.17.42.1", 2174 "Bridge" : "docker0", 2175 "PortMapping" : null, 2176 "Ports" : {} 2177 }, 2178 "ResolvConfPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/resolv.conf", 2179 "HostnamePath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hostname", 2180 "HostsPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hosts", 2181 "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", 2182 "Name" : "/test", 2183 "Driver" : "aufs", 2184 "ExecDriver" : "native-0.2", 2185 "MountLabel" : "", 2186 "ProcessLabel" : "", 2187 "AppArmorProfile" : "", 2188 "RestartCount" : 0, 2189 "Volumes" : {}, 2190 "VolumesRW" : {} 2191 } 2192 } 2193 2194 **Status codes**: 2195 2196 - **200** – no error 2197 - **404** – no such exec instance 2198 - **500** - server error 2199 2200 ## 3. Going further 2201 2202 ### 3.1 Inside `docker run` 2203 2204 As an example, the `docker run` command line makes the following API calls: 2205 2206 - Create the container 2207 2208 - If the status code is 404, it means the image doesn't exist: 2209 - Try to pull it. 2210 - Then, retry to create the container. 2211 2212 - Start the container. 2213 2214 - If you are not in detached mode: 2215 - Attach to the container, using `logs=1` (to have `stdout` and 2216 `stderr` from the container's start) and `stream=1` 2217 2218 - If in detached mode or only `stdin` is attached, display the container's id. 2219 2220 ### 3.2 Hijacking 2221 2222 In this version of the API, `/attach`, uses hijacking to transport `stdin`, 2223 `stdout`, and `stderr` on the same socket. 2224 2225 To hint potential proxies about connection hijacking, Docker client sends 2226 connection upgrade headers similarly to websocket. 2227 2228 Upgrade: tcp 2229 Connection: Upgrade 2230 2231 When Docker daemon detects the `Upgrade` header, it switches its status code 2232 from **200 OK** to **101 UPGRADED** and resends the same headers. 2233 2234 2235 ### 3.3 CORS Requests 2236 2237 To set cross origin requests to the Engine API please give values to 2238 `--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, 2239 default or blank means CORS disabled 2240 2241 $ docker -d -H="192.168.1.9:2375" --api-cors-header="http://foo.bar"