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