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