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