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