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