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