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