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