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