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