github.com/pritambaral/docker@v1.4.2-0.20150120174542-b2fe1b3dd952/docs/sources/reference/api/docker_remote_api_v1.15.md (about) 1 page_title: Remote API v1.15 2 page_description: API Documentation for Docker 3 page_keywords: API, Docker, rcli, REST, documentation 4 5 # Docker Remote API v1.15 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": "base: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": "base: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": "base: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": "base: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 95 Status Codes: 96 97 - **200** – no error 98 - **400** – bad parameter 99 - **500** – server error 100 101 ### Create a container 102 103 `POST /containers/create` 104 105 Create a container 106 107 **Example request**: 108 109 POST /containers/create HTTP/1.1 110 Content-Type: application/json 111 112 { 113 "Hostname": "", 114 "Domainname": "", 115 "User": "", 116 "Memory": 0, 117 "MemorySwap": 0, 118 "CpuShares": 512, 119 "Cpuset": "0,1", 120 "AttachStdin": false, 121 "AttachStdout": true, 122 "AttachStderr": true, 123 "Tty": false, 124 "OpenStdin": false, 125 "StdinOnce": false, 126 "Env": null, 127 "Cmd": [ 128 "date" 129 ], 130 "Entrypoint": "", 131 "Image": "base", 132 "Volumes": { 133 "/tmp": {} 134 }, 135 "WorkingDir": "", 136 "NetworkDisabled": false, 137 "MacAddress": "12:34:56:78:9a:bc", 138 "ExposedPorts": { 139 "22/tcp": {} 140 }, 141 "SecurityOpts": [""], 142 "HostConfig": { 143 "Binds": ["/tmp:/tmp"], 144 "Links": ["redis3:redis"], 145 "LxcConf": {"lxc.utsname":"docker"}, 146 "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, 147 "PublishAllPorts": false, 148 "Privileged": false, 149 "Dns": ["8.8.8.8"], 150 "DnsSearch": [""], 151 "VolumesFrom": ["parent", "other:ro"], 152 "CapAdd": ["NET_ADMIN"], 153 "CapDrop": ["MKNOD"], 154 "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, 155 "NetworkMode": "bridge", 156 "Devices": [] 157 } 158 } 159 160 **Example response**: 161 162 HTTP/1.1 201 Created 163 Content-Type: application/json 164 165 { 166 "Id": "f91ddc4b01e079c4481a8340bbbeca4dbd33d6e4a10662e499f8eacbb5bf252b" 167 "Warnings": [] 168 } 169 170 Json Parameters: 171 172 - **Hostname** - A string value containing the desired hostname to use for the 173 container. 174 - **Domainname** - A string value containing the desired domain name to use 175 for the container. 176 - **User** - A string value containg the user to use inside the container. 177 - **Memory** - Memory limit in bytes. 178 - **MemorySwap**- Total memory usage (memory + swap); set `-1` to disable swap. 179 - **CpuShares** - An integer value containing the CPU Shares for container 180 (ie. the relative weight vs othercontainers). 181 **CpuSet** - String value containg the cgroups Cpuset to use. 182 - **AttachStdin** - Boolean value, attaches to stdin. 183 - **AttachStdout** - Boolean value, attaches to stdout. 184 - **AttachStderr** - Boolean value, attaches to stderr. 185 - **Tty** - Boolean value, Attach standard streams to a tty, including stdin if it is not closed. 186 - **OpenStdin** - Boolean value, opens stdin, 187 - **StdinOnce** - Boolean value, close stdin after the 1 attached client disconnects. 188 - **Env** - A list of environment variables in the form of `VAR=value` 189 - **Cmd** - Command to run specified as a string or an array of strings. 190 - **Entrypoint** - Set the entrypoint for the container a a string or an array 191 of strings 192 - **Image** - String value containing the image name to use for the container 193 - **Volumes** – An object mapping mountpoint paths (strings) inside the 194 container to empty objects. 195 - **WorkingDir** - A string value containing the working dir for commands to 196 run in. 197 - **NetworkDisabled** - Boolean value, when true disables neworking for the 198 container 199 - **ExposedPorts** - An object mapping ports to an empty object in the form of: 200 `"ExposedPorts": { "<port>/<tcp|udp>: {}" }` 201 - **SecurityOpts**: A list of string values to customize labels for MLS 202 systems, such as SELinux. 203 - **HostConfig** 204 - **Binds** – A list of volume bindings for this container. Each volume 205 binding is a string of the form `container_path` (to create a new 206 volume for the container), `host_path:container_path` (to bind-mount 207 a host path into the container), or `host_path:container_path:ro` 208 (to make the bind-mount read-only inside the container). 209 - **Links** - A list of links for the container. Each link entry should be of 210 of the form "container_name:alias". 211 - **LxcConf** - LXC specific configurations. These configurations will only 212 work when using the `lxc` execution driver. 213 - **PortBindings** - A map of exposed container ports and the host port they 214 should map to. It should be specified in the form 215 `{ <port>/<protocol>: [{ "HostPort": "<port>" }] }` 216 Take note that `port` is specified as a string and not an integer value. 217 - **PublishAllPorts** - Allocates a random host port for all of a container's 218 exposed ports. Specified as a boolean value. 219 - **Privileged** - Gives the container full access to the host. Specified as 220 a boolean value. 221 - **Dns** - A list of dns servers for the container to use. 222 - **DnsSearch** - A list of DNS search domains 223 - **VolumesFrom** - A list of volumes to inherit from another container. 224 Specified in the form `<container name>[:<ro|rw>]` 225 - **CapAdd** - A list of kernel capabilties to add to the container. 226 - **Capdrop** - A list of kernel capabilties to drop from the container. 227 - **RestartPolicy** – The behavior to apply when the container exits. The 228 value is an object with a `Name` property of either `"always"` to 229 always restart or `"on-failure"` to restart only when the container 230 exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` 231 controls the number of times to retry before giving up. 232 The default is not to restart. (optional) 233 An ever increasing delay (double the previous delay, starting at 100mS) 234 is added before each restart to prevent flooding the server. 235 - **NetworkMode** - Sets the networking mode for the container. Supported 236 values are: `bridge`, `host`, and `container:<name|id>` 237 - **Devices** - A list of devices to add to the container specified in the 238 form 239 `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` 240 241 Query Parameters: 242 243 - **name** – Assign the specified name to the container. Must 244 match `/?[a-zA-Z0-9_-]+`. 245 246 Status Codes: 247 248 - **201** – no error 249 - **404** – no such container 250 - **406** – impossible to attach (container not running) 251 - **500** – server error 252 253 ### Inspect a container 254 255 `GET /containers/(id)/json` 256 257 Return low-level information on the container `id` 258 259 260 **Example request**: 261 262 GET /containers/4fa6e0f0c678/json HTTP/1.1 263 264 **Example response**: 265 266 HTTP/1.1 200 OK 267 Content-Type: application/json 268 269 { 270 "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2", 271 "Created": "2013-05-07T14:51:42.041847+02:00", 272 "Path": "date", 273 "Args": [], 274 "Config": { 275 "Hostname": "4fa6e0f0c678", 276 "User": "", 277 "Memory": 0, 278 "MemorySwap": 0, 279 "AttachStdin": false, 280 "AttachStdout": true, 281 "AttachStderr": true, 282 "PortSpecs": null, 283 "Tty": false, 284 "OpenStdin": false, 285 "StdinOnce": false, 286 "Env": null, 287 "Cmd": [ 288 "date" 289 ], 290 "Dns": null, 291 "Image": "base", 292 "Volumes": {}, 293 "VolumesFrom": "", 294 "WorkingDir": "" 295 }, 296 "State": { 297 "Running": false, 298 "Pid": 0, 299 "ExitCode": 0, 300 "StartedAt": "2013-05-07T14:51:42.087658+02:01360", 301 "Ghost": false 302 }, 303 "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 304 "NetworkSettings": { 305 "IpAddress": "", 306 "IpPrefixLen": 0, 307 "Gateway": "", 308 "Bridge": "", 309 "PortMapping": null 310 }, 311 "SysInitPath": "/home/kitty/go/src/github.com/docker/docker/bin/docker", 312 "ResolvConfPath": "/etc/resolv.conf", 313 "Volumes": {}, 314 "HostConfig": { 315 "Binds": null, 316 "ContainerIDFile": "", 317 "LxcConf": [], 318 "Privileged": false, 319 "PortBindings": { 320 "80/tcp": [ 321 { 322 "HostIp": "0.0.0.0", 323 "HostPort": "49153" 324 } 325 ] 326 }, 327 "Links": ["/name:alias"], 328 "PublishAllPorts": false, 329 "CapAdd": ["NET_ADMIN"], 330 "CapDrop": ["MKNOD"] 331 } 332 } 333 334 Status Codes: 335 336 - **200** – no error 337 - **404** – no such container 338 - **500** – server error 339 340 ### List processes running inside a container 341 342 `GET /containers/(id)/top` 343 344 List processes running inside the container `id` 345 346 **Example request**: 347 348 GET /containers/4fa6e0f0c678/top HTTP/1.1 349 350 **Example response**: 351 352 HTTP/1.1 200 OK 353 Content-Type: application/json 354 355 { 356 "Titles": [ 357 "USER", 358 "PID", 359 "%CPU", 360 "%MEM", 361 "VSZ", 362 "RSS", 363 "TTY", 364 "STAT", 365 "START", 366 "TIME", 367 "COMMAND" 368 ], 369 "Processes": [ 370 ["root","20147","0.0","0.1","18060","1864","pts/4","S","10:06","0:00","bash"], 371 ["root","20271","0.0","0.0","4312","352","pts/4","S+","10:07","0:00","sleep","10"] 372 ] 373 } 374 375 Query Parameters: 376 377 - **ps_args** – ps arguments to use (e.g., aux) 378 379 Status Codes: 380 381 - **200** – no error 382 - **404** – no such container 383 - **500** – server error 384 385 ### Get container logs 386 387 `GET /containers/(id)/logs` 388 389 Get stdout and stderr logs from the container ``id`` 390 391 **Example request**: 392 393 GET /containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10 HTTP/1.1 394 395 **Example response**: 396 397 HTTP/1.1 200 OK 398 Content-Type: application/vnd.docker.raw-stream 399 400 {{ STREAM }} 401 402 Query Parameters: 403 404 - **follow** – 1/True/true or 0/False/false, return stream. Default false 405 - **stdout** – 1/True/true or 0/False/false, show stdout log. Default false 406 - **stderr** – 1/True/true or 0/False/false, show stderr log. Default false 407 - **timestamps** – 1/True/true or 0/False/false, print timestamps for 408 every log line. Default false 409 - **tail** – Output specified number of lines at the end of logs: `all` or `<number>`. Default all 410 411 Status Codes: 412 413 - **200** – no error 414 - **404** – no such container 415 - **500** – server error 416 417 ### Inspect changes on a container's filesystem 418 419 `GET /containers/(id)/changes` 420 421 Inspect changes on container `id`'s filesystem 422 423 **Example request**: 424 425 GET /containers/4fa6e0f0c678/changes HTTP/1.1 426 427 **Example response**: 428 429 HTTP/1.1 200 OK 430 Content-Type: application/json 431 432 [ 433 { 434 "Path": "/dev", 435 "Kind": 0 436 }, 437 { 438 "Path": "/dev/kmsg", 439 "Kind": 1 440 }, 441 { 442 "Path": "/test", 443 "Kind": 1 444 } 445 ] 446 447 Status Codes: 448 449 - **200** – no error 450 - **404** – no such container 451 - **500** – server error 452 453 ### Export a container 454 455 `GET /containers/(id)/export` 456 457 Export the contents of container `id` 458 459 **Example request**: 460 461 GET /containers/4fa6e0f0c678/export HTTP/1.1 462 463 **Example response**: 464 465 HTTP/1.1 200 OK 466 Content-Type: application/octet-stream 467 468 {{ TAR STREAM }} 469 470 Status Codes: 471 472 - **200** – no error 473 - **404** – no such container 474 - **500** – server error 475 476 ### Resize a container TTY 477 478 `GET /containers/(id)/resize?h=<height>&w=<width>` 479 480 Resize the TTY of container `id` 481 482 **Example request**: 483 484 GET /containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 485 486 **Example response**: 487 488 HTTP/1.1 200 OK 489 Content-Length: 0 490 Content-Type: text/plain; charset=utf-8 491 492 Status Codes: 493 494 - **200** – no error 495 - **404** – No such container 496 - **500** – bad file descriptor 497 498 ### Start a container 499 500 `POST /containers/(id)/start` 501 502 Start the container `id` 503 504 **Example request**: 505 506 POST /containers/(id)/start HTTP/1.1 507 Content-Type: application/json 508 509 { 510 "Binds": ["/tmp:/tmp"], 511 "Links": ["redis3:redis"], 512 "LxcConf": {"lxc.utsname":"docker"}, 513 "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, 514 "PublishAllPorts": false, 515 "Privileged": false, 516 "Dns": ["8.8.8.8"], 517 "DnsSearch": [""], 518 "VolumesFrom": ["parent", "other:ro"], 519 "CapAdd": ["NET_ADMIN"], 520 "CapDrop": ["MKNOD"], 521 "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, 522 "NetworkMode": "bridge", 523 "Devices": [] 524 } 525 526 **Example response**: 527 528 HTTP/1.1 204 No Content 529 530 Json Parameters: 531 532 - **Binds** – A list of volume bindings for this container. Each volume 533 binding is a string of the form `container_path` (to create a new 534 volume for the container), `host_path:container_path` (to bind-mount 535 a host path into the container), or `host_path:container_path:ro` 536 (to make the bind-mount read-only inside the container). 537 - **Links** - A list of links for the container. Each link entry should be of 538 of the form "container_name:alias". 539 - **LxcConf** - LXC specific configurations. These configurations will only 540 work when using the `lxc` execution driver. 541 - **PortBindings** - A map of exposed container ports and the host port they 542 should map to. It should be specified in the form 543 `{ <port>/<protocol>: [{ "HostPort": "<port>" }] }` 544 Take note that `port` is specified as a string and not an integer value. 545 - **PublishAllPorts** - Allocates a random host port for all of a container's 546 exposed ports. Specified as a boolean value. 547 - **Privileged** - Gives the container full access to the host. Specified as 548 a boolean value. 549 - **Dns** - A list of dns servers for the container to use. 550 - **DnsSearch** - A list of DNS search domains 551 - **VolumesFrom** - A list of volumes to inherit from another container. 552 Specified in the form `<container name>[:<ro|rw>]` 553 - **CapAdd** - A list of kernel capabilties to add to the container. 554 - **Capdrop** - A list of kernel capabilties to drop from the container. 555 - **RestartPolicy** – The behavior to apply when the container exits. The 556 value is an object with a `Name` property of either `"always"` to 557 always restart or `"on-failure"` to restart only when the container 558 exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` 559 controls the number of times to retry before giving up. 560 The default is not to restart. (optional) 561 An ever increasing delay (double the previous delay, starting at 100mS) 562 is added before each restart to prevent flooding the server. 563 - **NetworkMode** - Sets the networking mode for the container. Supported 564 values are: `bridge`, `host`, and `container:<name|id>` 565 - **Devices** - A list of devices to add to the container specified in the 566 form 567 `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` 568 569 Status Codes: 570 571 - **204** – no error 572 - **304** – container already started 573 - **404** – no such container 574 - **500** – server error 575 576 ### Stop a container 577 578 `POST /containers/(id)/stop` 579 580 Stop the container `id` 581 582 **Example request**: 583 584 POST /containers/e90e34656806/stop?t=5 HTTP/1.1 585 586 **Example response**: 587 588 HTTP/1.1 204 No Content 589 590 Query Parameters: 591 592 - **t** – number of seconds to wait before killing the container 593 594 Status Codes: 595 596 - **204** – no error 597 - **304** – container already stopped 598 - **404** – no such container 599 - **500** – server error 600 601 ### Restart a container 602 603 `POST /containers/(id)/restart` 604 605 Restart the container `id` 606 607 **Example request**: 608 609 POST /containers/e90e34656806/restart?t=5 HTTP/1.1 610 611 **Example response**: 612 613 HTTP/1.1 204 No Content 614 615 Query Parameters: 616 617 - **t** – number of seconds to wait before killing the container 618 619 Status Codes: 620 621 - **204** – no error 622 - **404** – no such container 623 - **500** – server error 624 625 ### Kill a container 626 627 `POST /containers/(id)/kill` 628 629 Kill the container `id` 630 631 **Example request**: 632 633 POST /containers/e90e34656806/kill HTTP/1.1 634 635 **Example response**: 636 637 HTTP/1.1 204 No Content 638 639 Query Parameters 640 641 - **signal** - Signal to send to the container: integer or string like "SIGINT". 642 When not set, SIGKILL is assumed and the call will waits for the container to exit. 643 644 Status Codes: 645 646 - **204** – no error 647 - **404** – no such container 648 - **500** – server error 649 650 ### Pause a container 651 652 `POST /containers/(id)/pause` 653 654 Pause the container `id` 655 656 **Example request**: 657 658 POST /containers/e90e34656806/pause HTTP/1.1 659 660 **Example response**: 661 662 HTTP/1.1 204 No Content 663 664 Status Codes: 665 666 - **204** – no error 667 - **404** – no such container 668 - **500** – server error 669 670 ### Unpause a container 671 672 `POST /containers/(id)/unpause` 673 674 Unpause the container `id` 675 676 **Example request**: 677 678 POST /containers/e90e34656806/unpause HTTP/1.1 679 680 **Example response**: 681 682 HTTP/1.1 204 No Content 683 684 Status Codes: 685 686 - **204** – no error 687 - **404** – no such container 688 - **500** – server error 689 690 ### Attach to a container 691 692 `POST /containers/(id)/attach` 693 694 Attach to the container `id` 695 696 **Example request**: 697 698 POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 699 700 **Example response**: 701 702 HTTP/1.1 200 OK 703 Content-Type: application/vnd.docker.raw-stream 704 705 {{ STREAM }} 706 707 Query Parameters: 708 709 - **logs** – 1/True/true or 0/False/false, return logs. Default false 710 - **stream** – 1/True/true or 0/False/false, return stream. 711 Default false 712 - **stdin** – 1/True/true or 0/False/false, if stream=true, attach 713 to stdin. Default false 714 - **stdout** – 1/True/true or 0/False/false, if logs=true, return 715 stdout log, if stream=true, attach to stdout. Default false 716 - **stderr** – 1/True/true or 0/False/false, if logs=true, return 717 stderr log, if stream=true, attach to stderr. Default false 718 719 Status Codes: 720 721 - **200** – no error 722 - **400** – bad parameter 723 - **404** – no such container 724 - **500** – server error 725 726 **Stream details**: 727 728 When using the TTY setting is enabled in 729 [`POST /containers/create` 730 ](/reference/api/docker_remote_api_v1.9/#create-a-container "POST /containers/create"), 731 the stream is the raw data from the process PTY and client's stdin. 732 When the TTY is disabled, then the stream is multiplexed to separate 733 stdout and stderr. 734 735 The format is a **Header** and a **Payload** (frame). 736 737 **HEADER** 738 739 The header will contain the information on which stream write the 740 stream (stdout or stderr). It also contain the size of the 741 associated frame encoded on the last 4 bytes (uint32). 742 743 It is encoded on the first 8 bytes like this: 744 745 header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} 746 747 `STREAM_TYPE` can be: 748 749 - 0: stdin (will be written on stdout) 750 - 1: stdout 751 - 2: stderr 752 753 `SIZE1, SIZE2, SIZE3, SIZE4` are the 4 bytes of 754 the uint32 size encoded as big endian. 755 756 **PAYLOAD** 757 758 The payload is the raw stream. 759 760 **IMPLEMENTATION** 761 762 The simplest way to implement the Attach protocol is the following: 763 764 1. Read 8 bytes 765 2. chose stdout or stderr depending on the first byte 766 3. Extract the frame size from the last 4 byets 767 4. Read the extracted size and output it on the correct output 768 5. Goto 1 769 770 ### Wait a container 771 772 `POST /containers/(id)/wait` 773 774 Block until container `id` stops, then returns the exit code 775 776 **Example request**: 777 778 POST /containers/16253994b7c4/wait HTTP/1.1 779 780 **Example response**: 781 782 HTTP/1.1 200 OK 783 Content-Type: application/json 784 785 {"StatusCode": 0} 786 787 Status Codes: 788 789 - **200** – no error 790 - **404** – no such container 791 - **500** – server error 792 793 ### Remove a container 794 795 `DELETE /containers/(id)` 796 797 Remove the container `id` from the filesystem 798 799 **Example request**: 800 801 DELETE /containers/16253994b7c4?v=1 HTTP/1.1 802 803 **Example response**: 804 805 HTTP/1.1 204 No Content 806 807 Query Parameters: 808 809 - **v** – 1/True/true or 0/False/false, Remove the volumes 810 associated to the container. Default false 811 - **force** - 1/True/true or 0/False/false, Kill then remove the container. 812 Default false 813 814 Status Codes: 815 816 - **204** – no error 817 - **400** – bad parameter 818 - **404** – no such container 819 - **500** – server error 820 821 ### Copy files or folders from a container 822 823 `POST /containers/(id)/copy` 824 825 Copy files or folders of container `id` 826 827 **Example request**: 828 829 POST /containers/4fa6e0f0c678/copy HTTP/1.1 830 Content-Type: application/json 831 832 { 833 "Resource": "test.txt" 834 } 835 836 **Example response**: 837 838 HTTP/1.1 200 OK 839 Content-Type: application/x-tar 840 841 {{ TAR STREAM }} 842 843 Status Codes: 844 845 - **200** – no error 846 - **404** – no such container 847 - **500** – server error 848 849 ## 2.2 Images 850 851 ### List Images 852 853 `GET /images/json` 854 855 **Example request**: 856 857 GET /images/json?all=0 HTTP/1.1 858 859 **Example response**: 860 861 HTTP/1.1 200 OK 862 Content-Type: application/json 863 864 [ 865 { 866 "RepoTags": [ 867 "ubuntu:12.04", 868 "ubuntu:precise", 869 "ubuntu:latest" 870 ], 871 "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", 872 "Created": 1365714795, 873 "Size": 131506275, 874 "VirtualSize": 131506275 875 }, 876 { 877 "RepoTags": [ 878 "ubuntu:12.10", 879 "ubuntu:quantal" 880 ], 881 "ParentId": "27cf784147099545", 882 "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 883 "Created": 1364102658, 884 "Size": 24653, 885 "VirtualSize": 180116135 886 } 887 ] 888 889 890 Query Parameters: 891 892 - **all** – 1/True/true or 0/False/false, default false 893 - **filters** – a json encoded value of the filters (a map[string][]string) to process on the images list. Available filters: 894 - dangling=true 895 896 ### Create an image 897 898 `POST /images/create` 899 900 Create an image, either by pulling it from the registry or by importing it 901 902 **Example request**: 903 904 POST /images/create?fromImage=base HTTP/1.1 905 906 **Example response**: 907 908 HTTP/1.1 200 OK 909 Content-Type: application/json 910 911 {"status": "Pulling..."} 912 {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} 913 {"error": "Invalid..."} 914 ... 915 916 When using this endpoint to pull an image from the registry, the 917 `X-Registry-Auth` header can be used to include 918 a base64-encoded AuthConfig object. 919 920 Query Parameters: 921 922 - **fromImage** – name of the image to pull 923 - **fromSrc** – source to import. The value may be a URL from which the image 924 can be retrieved or `-` to read the image from the request body. 925 - **repo** – repository 926 - **tag** – tag 927 - **registry** – the registry to pull from 928 929 Request Headers: 930 931 - **X-Registry-Auth** – base64-encoded AuthConfig object 932 933 Status Codes: 934 935 - **200** – no error 936 - **500** – server error 937 938 939 940 ### Inspect an image 941 942 `GET /images/(name)/json` 943 944 Return low-level information on the image `name` 945 946 **Example request**: 947 948 GET /images/base/json HTTP/1.1 949 950 **Example response**: 951 952 HTTP/1.1 200 OK 953 Content-Type: application/json 954 955 { 956 "Created": "2013-03-23T22:24:18.818426-07:00", 957 "Container": "3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", 958 "ContainerConfig": 959 { 960 "Hostname": "", 961 "User": "", 962 "Memory": 0, 963 "MemorySwap": 0, 964 "AttachStdin": false, 965 "AttachStdout": false, 966 "AttachStderr": false, 967 "PortSpecs": null, 968 "Tty": true, 969 "OpenStdin": true, 970 "StdinOnce": false, 971 "Env": null, 972 "Cmd": ["/bin/bash"], 973 "Dns": null, 974 "Image": "base", 975 "Volumes": null, 976 "VolumesFrom": "", 977 "WorkingDir": "" 978 }, 979 "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 980 "Parent": "27cf784147099545", 981 "Size": 6824592 982 } 983 984 Status Codes: 985 986 - **200** – no error 987 - **404** – no such image 988 - **500** – server error 989 990 ### Get the history of an image 991 992 `GET /images/(name)/history` 993 994 Return the history of the image `name` 995 996 **Example request**: 997 998 GET /images/base/history HTTP/1.1 999 1000 **Example response**: 1001 1002 HTTP/1.1 200 OK 1003 Content-Type: application/json 1004 1005 [ 1006 { 1007 "Id": "b750fe79269d", 1008 "Created": 1364102658, 1009 "CreatedBy": "/bin/bash" 1010 }, 1011 { 1012 "Id": "27cf78414709", 1013 "Created": 1364068391, 1014 "CreatedBy": "" 1015 } 1016 ] 1017 1018 Status Codes: 1019 1020 - **200** – no error 1021 - **404** – no such image 1022 - **500** – server error 1023 1024 ### Push an image on the registry 1025 1026 `POST /images/(name)/push` 1027 1028 Push the image `name` on the registry 1029 1030 **Example request**: 1031 1032 POST /images/test/push HTTP/1.1 1033 1034 **Example response**: 1035 1036 HTTP/1.1 200 OK 1037 Content-Type: application/json 1038 1039 {"status": "Pushing..."} 1040 {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} 1041 {"error": "Invalid..."} 1042 ... 1043 1044 If you wish to push an image on to a private registry, that image must already have been tagged 1045 into a repository which references that registry host name and port. This repository name should 1046 then be used in the URL. This mirrors the flow of the CLI. 1047 1048 **Example request**: 1049 1050 POST /images/registry.acme.com:5000/test/push HTTP/1.1 1051 1052 1053 Query Parameters: 1054 1055 - **tag** – the tag to associate with the image on the registry, optional 1056 1057 Request Headers: 1058 1059 - **X-Registry-Auth** – include a base64-encoded AuthConfig 1060 object. 1061 1062 Status Codes: 1063 1064 - **200** – no error 1065 - **404** – no such image 1066 - **500** – server error 1067 1068 ### Tag an image into a repository 1069 1070 `POST /images/(name)/tag` 1071 1072 Tag the image `name` into a repository 1073 1074 **Example request**: 1075 1076 POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 1077 1078 **Example response**: 1079 1080 HTTP/1.1 201 OK 1081 1082 Query Parameters: 1083 1084 - **repo** – The repository to tag in 1085 - **force** – 1/True/true or 0/False/false, default false 1086 - **tag** - The new tag name 1087 1088 Status Codes: 1089 1090 - **201** – no error 1091 - **400** – bad parameter 1092 - **404** – no such image 1093 - **409** – conflict 1094 - **500** – server error 1095 1096 ### Remove an image 1097 1098 `DELETE /images/(name)` 1099 1100 Remove the image `name` from the filesystem 1101 1102 **Example request**: 1103 1104 DELETE /images/test HTTP/1.1 1105 1106 **Example response**: 1107 1108 HTTP/1.1 200 OK 1109 Content-type: application/json 1110 1111 [ 1112 {"Untagged": "3e2f21a89f"}, 1113 {"Deleted": "3e2f21a89f"}, 1114 {"Deleted": "53b4f83ac9"} 1115 ] 1116 1117 Query Parameters: 1118 1119 - **force** – 1/True/true or 0/False/false, default false 1120 - **noprune** – 1/True/true or 0/False/false, default false 1121 1122 Status Codes: 1123 1124 - **200** – no error 1125 - **404** – no such image 1126 - **409** – conflict 1127 - **500** – server error 1128 1129 ### Search images 1130 1131 `GET /images/search` 1132 1133 Search for an image on [Docker Hub](https://hub.docker.com). 1134 1135 > **Note**: 1136 > The response keys have changed from API v1.6 to reflect the JSON 1137 > sent by the registry server to the docker daemon's request. 1138 1139 **Example request**: 1140 1141 GET /images/search?term=sshd HTTP/1.1 1142 1143 **Example response**: 1144 1145 HTTP/1.1 200 OK 1146 Content-Type: application/json 1147 1148 [ 1149 { 1150 "description": "", 1151 "is_official": false, 1152 "is_automated": false, 1153 "name": "wma55/u1210sshd", 1154 "star_count": 0 1155 }, 1156 { 1157 "description": "", 1158 "is_official": false, 1159 "is_automated": false, 1160 "name": "jdswinbank/sshd", 1161 "star_count": 0 1162 }, 1163 { 1164 "description": "", 1165 "is_official": false, 1166 "is_automated": false, 1167 "name": "vgauthier/sshd", 1168 "star_count": 0 1169 } 1170 ... 1171 ] 1172 1173 Query Parameters: 1174 1175 - **term** – term to search 1176 1177 Status Codes: 1178 1179 - **200** – no error 1180 - **500** – server error 1181 1182 ## 2.3 Misc 1183 1184 ### Build an image from Dockerfile via stdin 1185 1186 `POST /build` 1187 1188 Build an image from Dockerfile via stdin 1189 1190 **Example request**: 1191 1192 POST /build HTTP/1.1 1193 1194 {{ TAR STREAM }} 1195 1196 **Example response**: 1197 1198 HTTP/1.1 200 OK 1199 Content-Type: application/json 1200 1201 {"stream": "Step 1..."} 1202 {"stream": "..."} 1203 {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} 1204 1205 The stream must be a tar archive compressed with one of the 1206 following algorithms: identity (no compression), gzip, bzip2, xz. 1207 1208 The archive must include a file called `Dockerfile` 1209 at its root. It may include any number of other files, 1210 which will be accessible in the build context (See the [*ADD build 1211 command*](/reference/builder/#dockerbuilder)). 1212 1213 Query Parameters: 1214 1215 - **t** – repository name (and optionally a tag) to be applied to 1216 the resulting image in case of success 1217 - **q** – suppress verbose build output 1218 - **nocache** – do not use the cache when building the image 1219 - **rm** - remove intermediate containers after a successful build (default behavior) 1220 - **forcerm** - always remove intermediate containers (includes rm) 1221 1222 Request Headers: 1223 1224 - **Content-type** – should be set to `"application/tar"`. 1225 - **X-Registry-Config** – base64-encoded ConfigFile objec 1226 1227 Status Codes: 1228 1229 - **200** – no error 1230 - **500** – server error 1231 1232 ### Check auth configuration 1233 1234 `POST /auth` 1235 1236 Get the default username and email 1237 1238 **Example request**: 1239 1240 POST /auth HTTP/1.1 1241 Content-Type: application/json 1242 1243 { 1244 "username":" hannibal", 1245 "password: "xxxx", 1246 "email": "hannibal@a-team.com", 1247 "serveraddress": "https://index.docker.io/v1/" 1248 } 1249 1250 **Example response**: 1251 1252 HTTP/1.1 200 OK 1253 1254 Status Codes: 1255 1256 - **200** – no error 1257 - **204** – no error 1258 - **500** – server error 1259 1260 ### Display system-wide information 1261 1262 `GET /info` 1263 1264 Display system-wide information 1265 1266 **Example request**: 1267 1268 GET /info HTTP/1.1 1269 1270 **Example response**: 1271 1272 HTTP/1.1 200 OK 1273 Content-Type: application/json 1274 1275 { 1276 "Containers": 11, 1277 "Images": 16, 1278 "Driver": "btrfs", 1279 "ExecutionDriver": "native-0.1", 1280 "KernelVersion": "3.12.0-1-amd64" 1281 "Debug": false, 1282 "NFd": 11, 1283 "NGoroutines": 21, 1284 "NEventsListener": 0, 1285 "InitPath": "/usr/bin/docker", 1286 "IndexServerAddress": ["https://index.docker.io/v1/"], 1287 "MemoryLimit": true, 1288 "SwapLimit": false, 1289 "IPv4Forwarding": true 1290 } 1291 1292 Status Codes: 1293 1294 - **200** – no error 1295 - **500** – server error 1296 1297 ### Show the docker version information 1298 1299 `GET /version` 1300 1301 Show the docker version information 1302 1303 **Example request**: 1304 1305 GET /version HTTP/1.1 1306 1307 **Example response**: 1308 1309 HTTP/1.1 200 OK 1310 Content-Type: application/json 1311 1312 { 1313 "ApiVersion": "1.12", 1314 "Version": "0.2.2", 1315 "GitCommit": "5a2a5cc+CHANGES", 1316 "GoVersion": "go1.0.3" 1317 } 1318 1319 Status Codes: 1320 1321 - **200** – no error 1322 - **500** – server error 1323 1324 ### Ping the docker server 1325 1326 `GET /_ping` 1327 1328 Ping the docker server 1329 1330 **Example request**: 1331 1332 GET /_ping HTTP/1.1 1333 1334 **Example response**: 1335 1336 HTTP/1.1 200 OK 1337 Content-Type: text/plain 1338 1339 OK 1340 1341 Status Codes: 1342 1343 - **200** - no error 1344 - **500** - server error 1345 1346 ### Create a new image from a container's changes 1347 1348 `POST /commit` 1349 1350 Create a new image from a container's changes 1351 1352 **Example request**: 1353 1354 POST /commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 1355 Content-Type: application/json 1356 1357 { 1358 "Hostname": "", 1359 "Domainname": "", 1360 "User": "", 1361 "Memory": 0, 1362 "MemorySwap": 0, 1363 "CpuShares": 512, 1364 "Cpuset": "0,1", 1365 "AttachStdin": false, 1366 "AttachStdout": true, 1367 "AttachStderr": true, 1368 "PortSpecs": null, 1369 "Tty": false, 1370 "OpenStdin": false, 1371 "StdinOnce": false, 1372 "Env": null, 1373 "Cmd": [ 1374 "date" 1375 ], 1376 "Volumes": { 1377 "/tmp": {} 1378 }, 1379 "WorkingDir": "", 1380 "NetworkDisabled": false, 1381 "ExposedPorts": { 1382 "22/tcp": {} 1383 } 1384 } 1385 1386 **Example response**: 1387 1388 HTTP/1.1 201 Created 1389 Content-Type: application/vnd.docker.raw-stream 1390 1391 {"Id": "596069db4bf5"} 1392 1393 Json Parameters: 1394 1395 - **config** - the container's configuration 1396 1397 Query Parameters: 1398 1399 - **container** – source container 1400 - **repo** – repository 1401 - **tag** – tag 1402 - **comment** – commit message 1403 - **author** – author (e.g., "John Hannibal Smith 1404 <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") 1405 1406 Status Codes: 1407 1408 - **201** – no error 1409 - **404** – no such container 1410 - **500** – server error 1411 1412 ### Monitor Docker's events 1413 1414 `GET /events` 1415 1416 Get container events from docker, either in real time via streaming, or via 1417 polling (using since). 1418 1419 Docker containers will report the following events: 1420 1421 create, destroy, die, export, kill, pause, restart, start, stop, unpause 1422 1423 and Docker images will report: 1424 1425 untag, delete 1426 1427 **Example request**: 1428 1429 GET /events?since=1374067924 1430 1431 **Example response**: 1432 1433 HTTP/1.1 200 OK 1434 Content-Type: application/json 1435 1436 {"status": "create", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924} 1437 {"status": "start", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924} 1438 {"status": "stop", "id": "dfdf82bd3881","from": "base:latest", "time":1374067966} 1439 {"status": "destroy", "id": "dfdf82bd3881","from": "base:latest", "time":1374067970} 1440 1441 Query Parameters: 1442 1443 - **since** – timestamp used for polling 1444 - **until** – timestamp used for polling 1445 1446 Status Codes: 1447 1448 - **200** – no error 1449 - **500** – server error 1450 1451 ### Get a tarball containing all images in a repository 1452 1453 `GET /images/(name)/get` 1454 1455 Get a tarball containing all images and metadata for the repository specified 1456 by `name`. 1457 1458 If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image 1459 (and its parents) are returned. If `name` is an image ID, similarly only tha 1460 image (and its parents) are returned, but with the exclusion of the 1461 'repositories' file in the tarball, as there were no image names referenced. 1462 1463 See the [image tarball format](#image-tarball-format) for more details. 1464 1465 **Example request** 1466 1467 GET /images/ubuntu/get 1468 1469 **Example response**: 1470 1471 HTTP/1.1 200 OK 1472 Content-Type: application/x-tar 1473 1474 Binary data stream 1475 1476 Status Codes: 1477 1478 - **200** – no error 1479 - **500** – server error 1480 1481 ### Get a tarball containing all images. 1482 1483 `GET /images/get` 1484 1485 Get a tarball containing all images and metadata for one or more repositories. 1486 1487 For each value of the `names` parameter: if it is a specific name and tag (e.g. 1488 ubuntu:latest), then only that image (and its parents) are returned; if it is 1489 an image ID, similarly only that image (and its parents) are returned and there 1490 would be no names referenced in the 'repositories' file for this image ID. 1491 1492 See the [image tarball format](#image-tarball-format) for more details. 1493 1494 **Example request** 1495 1496 GET /images/get?names=myname%2Fmyapp%3Alatest&names=busybox 1497 1498 **Example response**: 1499 1500 HTTP/1.1 200 OK 1501 Content-Type: application/x-tar 1502 1503 Binary data stream 1504 1505 Status Codes: 1506 1507 - **200** – no error 1508 - **500** – server error 1509 1510 ### Load a tarball with a set of images and tags into docker 1511 1512 `POST /images/load` 1513 1514 Load a set of images and tags into the docker repository. 1515 See the [image tarball format](#image-tarball-format) for more details. 1516 1517 **Example request** 1518 1519 POST /images/load 1520 1521 Tarball in body 1522 1523 **Example response**: 1524 1525 HTTP/1.1 200 OK 1526 1527 Status Codes: 1528 1529 - **200** – no error 1530 - **500** – server error 1531 1532 ### Image tarball format 1533 1534 An image tarball contains one directory per image layer (named using its long ID), 1535 each containing three files: 1536 1537 1. `VERSION`: currently `1.0` - the file format version 1538 2. `json`: detailed layer information, similar to `docker inspect layer_id` 1539 3. `layer.tar`: A tarfile containing the filesystem changes in this layer 1540 1541 The `layer.tar` file will contain `aufs` style `.wh..wh.aufs` files and directories 1542 for storing attribute changes and deletions. 1543 1544 If the tarball defines a repository, there will also be a `repositories` file at 1545 the root that contains a list of repository and tag names mapped to layer IDs. 1546 1547 ``` 1548 {"hello-world": 1549 {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} 1550 } 1551 ``` 1552 1553 ### Exec Create 1554 1555 `POST /containers/(id)/exec` 1556 1557 Sets up an exec instance in a running container `id` 1558 1559 **Example request**: 1560 1561 POST /containers/e90e34656806/exec HTTP/1.1 1562 Content-Type: application/json 1563 1564 { 1565 "AttachStdin": false, 1566 "AttachStdout": true, 1567 "AttachStderr": true, 1568 "Tty": false, 1569 "Cmd": [ 1570 "date" 1571 ], 1572 } 1573 1574 **Example response**: 1575 1576 HTTP/1.1 201 OK 1577 Content-Type: application/json 1578 1579 { 1580 "Id": "f90e34656806" 1581 } 1582 1583 Json Parameters: 1584 1585 - **AttachStdin** - Boolean value, attaches to stdin of the exec command. 1586 - **AttachStdout** - Boolean value, attaches to stdout of the exec command. 1587 - **AttachStderr** - Boolean value, attaches to stderr of the exec command. 1588 - **Tty** - Boolean value to allocate a pseudo-TTY 1589 - **Cmd** - Command to run specified as a string or an array of strings. 1590 1591 1592 Status Codes: 1593 1594 - **201** – no error 1595 - **404** – no such container 1596 1597 ### Exec Start 1598 1599 `POST /exec/(id)/start` 1600 1601 Starts a previously set up exec instance `id`. If `detach` is true, this API 1602 returns after starting the `exec` command. Otherwise, this API sets up an 1603 interactive session with the `exec` command. 1604 1605 **Example request**: 1606 1607 POST /exec/e90e34656806/start HTTP/1.1 1608 Content-Type: application/json 1609 1610 { 1611 "Detach": false, 1612 "Tty": false, 1613 } 1614 1615 **Example response**: 1616 1617 HTTP/1.1 201 OK 1618 Content-Type: application/json 1619 1620 {{ STREAM }} 1621 1622 Json Parameters: 1623 1624 - **Detach** - Detach from the exec command 1625 - **Tty** - Boolean value to allocate a pseudo-TTY 1626 1627 Status Codes: 1628 1629 - **201** – no error 1630 - **404** – no such exec instance 1631 1632 **Stream details**: 1633 Similar to the stream behavior of `POST /container/(id)/attach` API 1634 1635 ### Exec Resize 1636 1637 `POST /exec/(id)/resize` 1638 1639 Resizes the tty session used by the exec command `id`. 1640 This API is valid only if `tty` was specified as part of creating and starting the exec command. 1641 1642 **Example request**: 1643 1644 POST /exec/e90e34656806/resize HTTP/1.1 1645 Content-Type: plain/text 1646 1647 **Example response**: 1648 1649 HTTP/1.1 201 OK 1650 Content-Type: plain/text 1651 1652 Query Parameters: 1653 1654 - **h** – height of tty session 1655 - **w** – width 1656 1657 Status Codes: 1658 1659 - **201** – no error 1660 - **404** – no such exec instance 1661 1662 # 3. Going further 1663 1664 ## 3.1 Inside `docker run` 1665 1666 As an example, the `docker run` command line makes the following API calls: 1667 1668 - Create the container 1669 1670 - If the status code is 404, it means the image doesn't exist: 1671 - Try to pull it 1672 - Then retry to create the container 1673 1674 - Start the container 1675 1676 - If you are not in detached mode: 1677 - Attach to the container, using logs=1 (to have stdout and 1678 stderr from the container's start) and stream=1 1679 1680 - If in detached mode or only stdin is attached: 1681 - Display the container's id 1682 1683 ## 3.2 Hijacking 1684 1685 In this version of the API, /attach, uses hijacking to transport stdin, 1686 stdout and stderr on the same socket. This might change in the future. 1687 1688 ## 3.3 CORS Requests 1689 1690 To enable cross origin requests to the remote api add the flag 1691 "--api-enable-cors" when running docker in daemon mode. 1692 1693 $ docker -d -H="192.168.1.9:2375" --api-enable-cors