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