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