github.com/slene/docker@v1.8.0-rc1/docs/reference/api/docker_remote_api_v1.1.md (about) 1 <!--[metadata]> 2 +++ 3 draft = true 4 title = "Remote API v1.1" 5 description = "API Documentation for Docker" 6 keywords = ["API, Docker, rcli, REST, documentation"] 7 [menu.main] 8 parent = "smn_remoteapi" 9 +++ 10 <![end-metadata]--> 11 12 # Docker Remote API v1.1 13 14 # 1. Brief introduction 15 16 - The Remote API is replacing rcli 17 - Default port in the docker daemon is 2375 18 - The API tends to be REST, but for some complex commands, like attach 19 or pull, the HTTP connection is hijacked to transport stdout stdin 20 and stderr 21 22 # 2. Endpoints 23 24 ## 2.1 Containers 25 26 ### List containers 27 28 `GET /containers/json` 29 30 List containers 31 32 **Example request**: 33 34 GET /containers/json?all=1&before=8dfafdbc3a40 HTTP/1.1 35 36 **Example response**: 37 38 HTTP/1.1 200 OK 39 Content-Type: application/json 40 41 [ 42 { 43 "Id": "8dfafdbc3a40", 44 "Image": "ubuntu:latest", 45 "Command": "echo 1", 46 "Created": 1367854155, 47 "Status": "Exit 0" 48 }, 49 { 50 "Id": "9cd87474be90", 51 "Image": "ubuntu:latest", 52 "Command": "echo 222222", 53 "Created": 1367854155, 54 "Status": "Exit 0" 55 }, 56 { 57 "Id": "3176a2479c92", 58 "Image": "centos:latest", 59 "Command": "echo 3333333333333333", 60 "Created": 1367854154, 61 "Status": "Exit 0" 62 }, 63 { 64 "Id": "4cb07b47f9fb", 65 "Image": "fedora:latest", 66 "Command": "echo 444444444444444444444444444444444", 67 "Created": 1367854152, 68 "Status": "Exit 0" 69 } 70 ] 71 72 Query Parameters: 73 74 - **all** – 1/True/true or 0/False/false, Show all containers. 75 Only running containers are shown by default 76 - **limit** – Show `limit` last created 77 containers, include non-running ones. 78 - **since** – Show only containers created since Id, include 79 non-running ones. 80 - **before** – Show only containers created before Id, include 81 non-running ones. 82 83 Status Codes: 84 85 - **200** – no error 86 - **400** – bad parameter 87 - **500** – server error 88 89 ### Create a container 90 91 `POST /containers/create` 92 93 Create a container 94 95 **Example request**: 96 97 POST /containers/create HTTP/1.1 98 Content-Type: application/json 99 100 { 101 "Hostname":"", 102 "User":"", 103 "Memory":0, 104 "MemorySwap":0, 105 "AttachStdin":false, 106 "AttachStdout":true, 107 "AttachStderr":true, 108 "PortSpecs":null, 109 "Tty":false, 110 "OpenStdin":false, 111 "StdinOnce":false, 112 "Env":null, 113 "Cmd":[ 114 "date" 115 ], 116 "Dns":null, 117 "Image":"ubuntu", 118 "Volumes":{}, 119 "VolumesFrom":"" 120 } 121 122 **Example response**: 123 124 HTTP/1.1 201 Created 125 Content-Type: application/json 126 127 { 128 "Id":"e90e34656806" 129 "Warnings":[] 130 } 131 132 Json Parameters: 133 134 - **config** – the container's configuration 135 136 Status Codes: 137 138 - **201** – no error 139 - **404** – no such container 140 - **406** – impossible to attach (container not running) 141 - **500** – server error 142 143 ### Inspect a container 144 145 `GET /containers/(id)/json` 146 147 Return low-level information on the container `id` 148 149 150 **Example request**: 151 152 GET /containers/4fa6e0f0c678/json HTTP/1.1 153 154 **Example response**: 155 156 HTTP/1.1 200 OK 157 Content-Type: application/json 158 159 { 160 "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2", 161 "Created": "2013-05-07T14:51:42.041847+02:00", 162 "Path": "date", 163 "Args": [], 164 "Config": { 165 "Hostname": "4fa6e0f0c678", 166 "User": "", 167 "Memory": 0, 168 "MemorySwap": 0, 169 "AttachStdin": false, 170 "AttachStdout": true, 171 "AttachStderr": true, 172 "PortSpecs": null, 173 "Tty": false, 174 "OpenStdin": false, 175 "StdinOnce": false, 176 "Env": null, 177 "Cmd": [ 178 "date" 179 ], 180 "Dns": null, 181 "Image": "ubuntu", 182 "Volumes": {}, 183 "VolumesFrom": "" 184 }, 185 "State": { 186 "Running": false, 187 "Pid": 0, 188 "ExitCode": 0, 189 "StartedAt": "2013-05-07T14:51:42.087658+02:01360", 190 "Ghost": false 191 }, 192 "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 193 "NetworkSettings": { 194 "IpAddress": "", 195 "IpPrefixLen": 0, 196 "Gateway": "", 197 "Bridge": "", 198 "PortMapping": null 199 }, 200 "SysInitPath": "/home/kitty/go/src/github.com/docker/docker/bin/docker", 201 "ResolvConfPath": "/etc/resolv.conf", 202 "Volumes": {} 203 } 204 205 Status Codes: 206 207 - **200** – no error 208 - **404** – no such container 209 - **500** – server error 210 211 ### Inspect changes on a container's filesystem 212 213 `GET /containers/(id)/changes` 214 215 Inspect changes on container `id`'s filesystem 216 217 **Example request**: 218 219 GET /containers/4fa6e0f0c678/changes HTTP/1.1 220 221 **Example response**: 222 223 HTTP/1.1 200 OK 224 Content-Type: application/json 225 226 [ 227 { 228 "Path": "/dev", 229 "Kind": 0 230 }, 231 { 232 "Path": "/dev/kmsg", 233 "Kind": 1 234 }, 235 { 236 "Path": "/test", 237 "Kind": 1 238 } 239 ] 240 241 Status Codes: 242 243 - **200** – no error 244 - **404** – no such container 245 - **500** – server error 246 247 ### Export a container 248 249 `GET /containers/(id)/export` 250 251 Export the contents of container `id` 252 253 **Example request**: 254 255 GET /containers/4fa6e0f0c678/export HTTP/1.1 256 257 **Example response**: 258 259 HTTP/1.1 200 OK 260 Content-Type: application/octet-stream 261 262 {{ STREAM }} 263 264 Status Codes: 265 266 - **200** – no error 267 - **404** – no such container 268 - **500** – server error 269 270 ### Start a container 271 272 `POST /containers/(id)/start` 273 274 Start the container `id` 275 276 **Example request**: 277 278 POST /containers/e90e34656806/start HTTP/1.1 279 280 **Example response**: 281 282 HTTP/1.1 200 OK 283 284 Status Codes: 285 286 - **200** – no error 287 - **404** – no such container 288 - **500** – server error 289 290 ### Stop a container 291 292 `POST /containers/(id)/stop` 293 294 Stop the container `id` 295 296 **Example request**: 297 298 POST /containers/e90e34656806/stop?t=5 HTTP/1.1 299 300 **Example response**: 301 302 HTTP/1.1 204 OK 303 304 Query Parameters: 305 306 - **t** – number of seconds to wait before killing the container 307 308 Status Codes: 309 310 - **204** – no error 311 - **404** – no such container 312 - **500** – server error 313 314 ### Restart a container 315 316 `POST /containers/(id)/restart` 317 318 Restart the container `id` 319 320 **Example request**: 321 322 POST /containers/e90e34656806/restart?t=5 HTTP/1.1 323 324 **Example response**: 325 326 HTTP/1.1 204 No Content 327 328 Query Parameters: 329 330 - **t** – number of seconds to wait before killing the container 331 332 Status Codes: 333 334 - **204** – no error 335 - **404** – no such container 336 - **500** – server error 337 338 ### Kill a container 339 340 `POST /containers/(id)/kill` 341 342 Kill the container `id` 343 344 **Example request**: 345 346 POST /containers/e90e34656806/kill HTTP/1.1 347 348 **Example response**: 349 350 HTTP/1.1 204 No Content 351 352 Status Codes: 353 354 - **204** – no error 355 - **404** – no such container 356 - **500** – server error 357 358 ### Attach to a container 359 360 `POST /containers/(id)/attach` 361 362 Attach to the container `id` 363 364 **Example request**: 365 366 POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 367 368 **Example response**: 369 370 HTTP/1.1 200 OK 371 Content-Type: application/vnd.docker.raw-stream 372 373 {{ STREAM }} 374 375 Query Parameters: 376 377 - **logs** – 1/True/true or 0/False/false, return logs. Defaul 378 false 379 - **stream** – 1/True/true or 0/False/false, return stream. 380 Default false 381 - **stdin** – 1/True/true or 0/False/false, if stream=true, attach 382 to stdin. Default false 383 - **stdout** – 1/True/true or 0/False/false, if logs=true, return 384 stdout log, if stream=true, attach to stdout. Default false 385 - **stderr** – 1/True/true or 0/False/false, if logs=true, return 386 stderr log, if stream=true, attach to stderr. Default false 387 388 Status Codes: 389 390 - **200** – no error 391 - **400** – bad parameter 392 - **404** – no such container 393 - **500** – server error 394 395 ### Attach to a container (websocket) 396 397 `GET /containers/(id)/attach/ws` 398 399 Attach to the container `id` via websocket 400 401 Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) 402 403 **Example request** 404 405 GET /containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 406 407 **Example response** 408 409 {{ STREAM }} 410 411 Query Parameters: 412 413 - **logs** – 1/True/true or 0/False/false, return logs. Default false 414 - **stream** – 1/True/true or 0/False/false, return stream. 415 Default false 416 - **stdin** – 1/True/true or 0/False/false, if stream=true, attach 417 to stdin. Default false 418 - **stdout** – 1/True/true or 0/False/false, if logs=true, return 419 stdout log, if stream=true, attach to stdout. Default false 420 - **stderr** – 1/True/true or 0/False/false, if logs=true, return 421 stderr log, if stream=true, attach to stderr. Default false 422 423 Status Codes: 424 425 - **200** – no error 426 - **400** – bad parameter 427 - **404** – no such container 428 - **500** – server error 429 430 ### Wait a container 431 432 `POST /containers/(id)/wait` 433 434 Block until container `id` stops, then returns the exit code 435 436 **Example request**: 437 438 POST /containers/16253994b7c4/wait HTTP/1.1 439 440 **Example response**: 441 442 HTTP/1.1 200 OK 443 Content-Type: application/json 444 445 {"StatusCode": 0} 446 447 Status Codes: 448 449 - **200** – no error 450 - **404** – no such container 451 - **500** – server error 452 453 ### Remove a container 454 455 `DELETE /containers/(id)` 456 457 Remove the container `id` from the filesystem 458 459 **Example request**: 460 461 DELETE /containers/16253994b7c4?v=1 HTTP/1.1 462 463 **Example response**: 464 465 HTTP/1.1 204 OK 466 467 Query Parameters: 468 469 - **v** – 1/True/true or 0/False/false, Remove the volumes 470 associated to the container. Default false 471 472 Status Codes: 473 474 - **204** – no error 475 - **400** – bad parameter 476 - **404** – no such container 477 - **500** – server error 478 479 ## 2.2 Images 480 481 ### List Images 482 483 `GET /images/(format)` 484 485 List images `format` could be json or viz (json default) 486 487 **Example request**: 488 489 GET /images/json?all=0 HTTP/1.1 490 491 **Example response**: 492 493 HTTP/1.1 200 OK 494 Content-Type: application/json 495 496 [ 497 { 498 "Repository":"ubuntu", 499 "Tag":"precise", 500 "Id":"b750fe79269d", 501 "Created":1364102658 502 }, 503 { 504 "Repository":"ubuntu", 505 "Tag":"12.04", 506 "Id":"b750fe79269d", 507 "Created":1364102658 508 } 509 ] 510 511 **Example request**: 512 513 GET /images/viz HTTP/1.1 514 515 **Example response**: 516 517 HTTP/1.1 200 OK 518 Content-Type: text/plain 519 520 digraph docker { 521 "d82cbacda43a" -> "074be284591f" 522 "1496068ca813" -> "08306dc45919" 523 "08306dc45919" -> "0e7893146ac2" 524 "b750fe79269d" -> "1496068ca813" 525 base -> "27cf78414709" [style=invis] 526 "f71189fff3de" -> "9a33b36209ed" 527 "27cf78414709" -> "b750fe79269d" 528 "0e7893146ac2" -> "d6434d954665" 529 "d6434d954665" -> "d82cbacda43a" 530 base -> "e9aa60c60128" [style=invis] 531 "074be284591f" -> "f71189fff3de" 532 "b750fe79269d" [label="b750fe79269d\nubuntu",shape=box,fillcolor="paleturquoise",style="filled,rounded"]; 533 "e9aa60c60128" [label="e9aa60c60128\ncentos",shape=box,fillcolor="paleturquoise",style="filled,rounded"]; 534 "9a33b36209ed" [label="9a33b36209ed\nfedora",shape=box,fillcolor="paleturquoise",style="filled,rounded"]; 535 base [style=invisible] 536 } 537 538 Query Parameters: 539 540 - **all** – 1/True/true or 0/False/false, Show all containers. 541 Only running containers are shown by defaul 542 543 Status Codes: 544 545 - **200** – no error 546 - **400** – bad parameter 547 - **500** – server error 548 549 ### Create an image 550 551 `POST /images/create` 552 553 Create an image, either by pull it from the registry or by importing i 554 555 **Example request**: 556 557 POST /images/create?fromImage=ubuntu HTTP/1.1 558 559 **Example response**: 560 561 HTTP/1.1 200 OK 562 Content-Type: application/json 563 564 {"status":"Pulling..."} 565 {"status":"Pulling", "progress":"1/? (n/a)"} 566 {"error":"Invalid..."} 567 ... 568 569 Query Parameters: 570 571 - **fromImage** – name of the image to pull 572 - **fromSrc** – source to import, - means stdin 573 - **repo** – repository 574 - **tag** – tag 575 - **registry** – the registry to pull from 576 577 Status Codes: 578 579 - **200** – no error 580 - **500** – server error 581 582 ### Insert a file in an image 583 584 `POST /images/(name)/insert` 585 586 Insert a file from `url` in the image `name` at `path` 587 588 **Example request**: 589 590 POST /images/test/insert?path=/usr&url=myurl HTTP/1.1 591 592 **Example response**: 593 594 HTTP/1.1 200 OK 595 Content-Type: application/json 596 597 {"status":"Inserting..."} 598 {"status":"Inserting", "progress":"1/? (n/a)"} 599 {"error":"Invalid..."} 600 ... 601 602 Query Parameters: 603 604 - **url** – The url from where the file is taken 605 - **path** – The path where the file is stored 606 607 Status Codes: 608 609 - **200** – no error 610 - **500** – server error 611 612 ### Inspect an image 613 614 `GET /images/(name)/json` 615 616 Return low-level information on the image `name` 617 618 **Example request**: 619 620 GET /images/centos/json HTTP/1.1 621 622 **Example response**: 623 624 HTTP/1.1 200 OK 625 Content-Type: application/json 626 627 { 628 "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 629 "parent":"27cf784147099545", 630 "created":"2013-03-23T22:24:18.818426-07:00", 631 "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", 632 "container_config": 633 { 634 "Hostname":"", 635 "User":"", 636 "Memory":0, 637 "MemorySwap":0, 638 "AttachStdin":false, 639 "AttachStdout":false, 640 "AttachStderr":false, 641 "PortSpecs":null, 642 "Tty":true, 643 "OpenStdin":true, 644 "StdinOnce":false, 645 "Env":null, 646 "Cmd": ["/bin/bash"], 647 "Dns":null, 648 "Image":"centos", 649 "Volumes":null, 650 "VolumesFrom":"" 651 } 652 } 653 654 Status Codes: 655 656 - **200** – no error 657 - **404** – no such image 658 - **500** – server error 659 660 ### Get the history of an image 661 662 `GET /images/(name)/history` 663 664 Return the history of the image `name` 665 666 **Example request**: 667 668 GET /images/fedora/history HTTP/1.1 669 670 **Example response**: 671 672 HTTP/1.1 200 OK 673 Content-Type: application/json 674 675 [ 676 { 677 "Id": "b750fe79269d", 678 "Created": 1364102658, 679 "CreatedBy": "/bin/bash" 680 }, 681 { 682 "Id": "27cf78414709", 683 "Created": 1364068391, 684 "CreatedBy": "" 685 } 686 ] 687 688 Status Codes: 689 690 - **200** – no error 691 - **404** – no such image 692 - **500** – server error 693 694 ### Push an image on the registry 695 696 `POST /images/(name)/push` 697 698 Push the image `name` on the registry 699 700 > **Example request**: 701 > 702 > POST /images/test/push HTTP/1.1 703 > 704 > **Example response**: 705 706 HTTP/1.1 200 OK 707 Content-Type: application/json 708 709 {"status":"Pushing..."} 710 {"status":"Pushing", "progress":"1/? (n/a)"} 711 {"error":"Invalid..."} 712 ... 713 714 Status Codes: 715 716 - **200** – no error 717 - **404** – no such image 718 - **500** – server error 719 720 ### Tag an image into a repository 721 722 `POST /images/(name)/tag` 723 724 Tag the image `name` into a repository 725 726 **Example request**: 727 728 POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 729 730 **Example response**: 731 732 HTTP/1.1 201 OK 733 734 Query Parameters: 735 736 - **repo** – The repository to tag in 737 - **force** – 1/True/true or 0/False/false, default false 738 - **tag** - The new tag name 739 740 Status Codes: 741 742 - **201** – no error 743 - **400** – bad parameter 744 - **404** – no such image 745 - **409** – conflict 746 - **500** – server error 747 748 ### Remove an image 749 750 `DELETE /images/(name)` 751 752 Remove the image `name` from the filesystem 753 754 **Example request**: 755 756 DELETE /images/test HTTP/1.1 757 758 **Example response**: 759 760 HTTP/1.1 204 No Content 761 762 Status Codes: 763 764 - **204** – no error 765 - **404** – no such image 766 - **500** – server error 767 768 ### Search images 769 770 `GET /images/search` 771 772 Search for an image on [Docker Hub](https://hub.docker.com) 773 774 **Example request**: 775 776 GET /images/search?term=sshd HTTP/1.1 777 778 **Example response**: 779 780 HTTP/1.1 200 OK 781 Content-Type: application/json 782 783 [ 784 { 785 "Name":"cespare/sshd", 786 "Description":"" 787 }, 788 { 789 "Name":"johnfuller/sshd", 790 "Description":"" 791 }, 792 { 793 "Name":"dhrp/mongodb-sshd", 794 "Description":"" 795 } 796 ] 797 798 :query term: term to search 799 :statuscode 200: no error 800 :statuscode 500: server error 801 802 ## 2.3 Misc 803 804 ### Build an image from Dockerfile via stdin 805 806 `POST /build` 807 808 Build an image from Dockerfile via stdin 809 810 **Example request**: 811 812 POST /build HTTP/1.1 813 814 {{ STREAM }} 815 816 **Example response**: 817 818 HTTP/1.1 200 OK 819 820 {{ STREAM }} 821 822 Query Parameters: 823 824 825 826 - **t** – tag to be applied to the resulting image in case of 827 success 828 829 Status Codes: 830 831 - **200** – no error 832 - **500** – server error 833 834 ### Get default username and email 835 836 `GET /auth` 837 838 Get the default username and email 839 840 **Example request**: 841 842 GET /auth HTTP/1.1 843 844 **Example response**: 845 846 HTTP/1.1 200 OK 847 Content-Type: application/json 848 849 { 850 "username":"hannibal", 851 "email":"hannibal@a-team.com" 852 } 853 854 Status Codes: 855 856 - **200** – no error 857 - **500** – server error 858 859 ### Check auth configuration and store i 860 861 `POST /auth` 862 863 Get the default username and email 864 865 **Example request**: 866 867 POST /auth HTTP/1.1 868 Content-Type: application/json 869 870 { 871 "username":"hannibal", 872 "password:"xxxx", 873 "email":"hannibal@a-team.com" 874 } 875 876 **Example response**: 877 878 HTTP/1.1 200 OK 879 Content-Type: text/plain 880 881 Status Codes: 882 883 - **200** – no error 884 - **204** – no error 885 - **500** – server error 886 887 ### Display system-wide information 888 889 `GET /info` 890 891 Display system-wide information 892 893 **Example request**: 894 895 GET /info HTTP/1.1 896 897 **Example response**: 898 899 HTTP/1.1 200 OK 900 Content-Type: application/json 901 902 { 903 "Containers":11, 904 "Images":16, 905 "Debug":false, 906 "NFd": 11, 907 "NGoroutines":21, 908 "MemoryLimit":true, 909 "SwapLimit":false 910 } 911 912 Status Codes: 913 914 - **200** – no error 915 - **500** – server error 916 917 ### Show the docker version information 918 919 `GET /version` 920 921 Show the docker version information 922 923 **Example request**: 924 925 GET /version HTTP/1.1 926 927 **Example response**: 928 929 HTTP/1.1 200 OK 930 Content-Type: application/json 931 932 { 933 "Version":"0.2.2", 934 "GitCommit":"5a2a5cc+CHANGES", 935 "GoVersion":"go1.0.3" 936 } 937 938 Status Codes: 939 940 - **200** – no error 941 - **500** – server error 942 943 ### Create a new image from a container's changes 944 945 `POST /commit` 946 947 Create a new image from a container's changes 948 949 **Example request**: 950 951 POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1 952 Content-Type: application/json 953 954 { 955 "Cmd": ["cat", "/world"], 956 "PortSpecs":["22"] 957 } 958 959 **Example response**: 960 961 HTTP/1.1 201 OK 962 Content-Type: application/vnd.docker.raw-stream 963 964 {"Id": "596069db4bf5"} 965 966 Query Parameters: 967 968 - **container** – source container 969 - **repo** – repository 970 - **tag** – tag 971 - **m** – commit message 972 - **author** – author (e.g., "John Hannibal Smith 973 <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") 974 975 Status Codes: 976 977 - **201** – no error 978 - **404** – no such container 979 - **500** – server error 980 981 # 3. Going further 982 983 ## 3.1 Inside `docker run` 984 985 Here are the steps of `docker run` : 986 987 - Create the container 988 989 - If the status code is 404, it means the image doesn't exist: 990 - Try to pull it 991 - Then retry to create the container 992 993 - Start the container 994 995 - If you are not in detached mode: 996 - Attach to the container, using logs=1 (to have stdout and 997 stderr from the container's start) and stream=1 998 999 - If in detached mode or only stdin is attached: 1000 - Display the container's 1001 1002 ## 3.2 Hijacking 1003 1004 In this version of the API, /attach uses hijacking to transport stdin, 1005 stdout and stderr on the same socket. This might change in the future.