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