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