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