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