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