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