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