github.com/feiyang21687/docker@v1.5.0/docs/sources/reference/api/docker_remote_api_v1.0.md (about) 1 page_title: Remote API v1.0 2 page_description: API Documentation for Docker 3 page_keywords: API, Docker, rcli, REST, documentation 4 5 # Docker Remote API v1.0 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 {{ TAR 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/vnd.docker.raw-stream 556 557 {{ STREAM }} 558 559 Query Parameters: 560 561 - **fromImage** – name of the image to pull 562 - **fromSrc** – source to import, - means stdin 563 - **repo** – repository 564 - **tag** – tag 565 - **registry** – the registry to pull from 566 567 Status Codes: 568 569 - **200** – no error 570 - **500** – server error 571 572 ### Insert a file in an image 573 574 `POST /images/(name)/insert` 575 576 Insert a file from `url` in the image `name` at `path` 577 578 **Example request**: 579 580 POST /images/test/insert?path=/usr&url=myurl HTTP/1.1 581 582 **Example response**: 583 584 HTTP/1.1 200 OK 585 586 {{ TAR STREAM }} 587 588 Query Parameters: 589 590 - **url** – The url from where the file is taken 591 - **path** – The path where the file is stored 592 593 Status Codes: 594 595 - **200** – no error 596 - **500** – server error 597 598 ### Inspect an image 599 600 `GET /images/(name)/json` 601 602 Return low-level information on the image `name` 603 604 **Example request**: 605 606 GET /images/centos/json HTTP/1.1 607 608 **Example response**: 609 610 HTTP/1.1 200 OK 611 Content-Type: application/json 612 613 { 614 "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 615 "parent":"27cf784147099545", 616 "created":"2013-03-23T22:24:18.818426-07:00", 617 "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", 618 "container_config": 619 { 620 "Hostname":"", 621 "User":"", 622 "Memory":0, 623 "MemorySwap":0, 624 "AttachStdin":false, 625 "AttachStdout":false, 626 "AttachStderr":false, 627 "PortSpecs":null, 628 "Tty":true, 629 "OpenStdin":true, 630 "StdinOnce":false, 631 "Env":null, 632 "Cmd": ["/bin/bash"], 633 "Dns":null, 634 "Image":"centos", 635 "Volumes":null, 636 "VolumesFrom":"" 637 } 638 } 639 640 Status Codes: 641 642 - **200** – no error 643 - **404** – no such image 644 - **500** – server error 645 646 ### Get the history of an image 647 648 `GET /images/(name)/history` 649 650 Return the history of the image `name` 651 652 **Example request**: 653 654 GET /images/fedora/history HTTP/1.1 655 656 **Example response**: 657 658 HTTP/1.1 200 OK 659 Content-Type: application/json 660 661 [ 662 { 663 "Id": "b750fe79269d", 664 "Created": 1364102658, 665 "CreatedBy": "/bin/bash" 666 }, 667 { 668 "Id": "27cf78414709", 669 "Created": 1364068391, 670 "CreatedBy": "" 671 } 672 ] 673 674 Status Codes: 675 676 - **200** – no error 677 - **404** – no such image 678 - **500** – server error 679 680 ### Push an image on the registry 681 682 `POST /images/(name)/push` 683 684 Push the image `name` on the registry 685 686 > **Example request**: 687 > 688 > POST /images/test/push HTTP/1.1 689 > 690 > **Example response**: 691 692 HTTP/1.1 200 OK 693 Content-Type: application/vnd.docker.raw-stream 694 695 {{ STREAM }} 696 697 Status Codes: 698 699 - **200** – no error 700 - **404** – no such image 701 - **500** – server error 702 703 ### Tag an image into a repository 704 705 `POST /images/(name)/tag` 706 707 Tag the image `name` into a repository 708 709 **Example request**: 710 711 POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 712 713 **Example response**: 714 715 HTTP/1.1 201 OK 716 717 Query Parameters: 718 719 - **repo** – The repository to tag in 720 - **force** – 1/True/true or 0/False/false, default false 721 - **tag** - The new tag name 722 723 Status Codes: 724 725 - **201** – no error 726 - **400** – bad parameter 727 - **404** – no such image 728 - **500** – server error 729 730 ### Remove an image 731 732 `DELETE /images/(name)` 733 734 Remove the image `name` from the filesystem 735 736 **Example request**: 737 738 DELETE /images/test HTTP/1.1 739 740 **Example response**: 741 742 HTTP/1.1 204 No Content 743 744 Status Codes: 745 746 - **204** – no error 747 - **404** – no such image 748 - **500** – server error 749 750 ### Search images 751 752 `GET /images/search` 753 754 Search for an image on [Docker Hub](https://hub.docker.com) 755 756 **Example request**: 757 758 GET /images/search?term=sshd HTTP/1.1 759 760 **Example response**: 761 762 HTTP/1.1 200 OK 763 Content-Type: application/json 764 765 [ 766 { 767 "Name":"cespare/sshd", 768 "Description":"" 769 }, 770 { 771 "Name":"johnfuller/sshd", 772 "Description":"" 773 }, 774 { 775 "Name":"dhrp/mongodb-sshd", 776 "Description":"" 777 } 778 ] 779 780 :query term: term to search 781 :statuscode 200: no error 782 :statuscode 500: server error 783 784 ## 2.3 Misc 785 786 ### Build an image from Dockerfile via stdin 787 788 `POST /build` 789 790 Build an image from Dockerfile via stdin 791 792 **Example request**: 793 794 POST /build HTTP/1.1 795 796 {{ TAR STREAM }} 797 798 **Example response**: 799 800 HTTP/1.1 200 OK 801 802 {{ STREAM }} 803 804 Query Parameters: 805 806 - **t** – repository name to be applied to the resulting image in 807 case of success 808 809 Status Codes: 810 811 - **200** – no error 812 - **500** – server error 813 814 ### Get default username and email 815 816 `GET /auth` 817 818 Get the default username and email 819 820 **Example request**: 821 822 GET /auth HTTP/1.1 823 824 **Example response**: 825 826 HTTP/1.1 200 OK 827 Content-Type: application/json 828 829 { 830 "username":"hannibal", 831 "email":"hannibal@a-team.com" 832 } 833 834 Status Codes: 835 836 - **200** – no error 837 - **500** – server error 838 839 ### Check auth configuration and store i 840 841 `POST /auth` 842 843 Get the default username and email 844 845 **Example request**: 846 847 POST /auth HTTP/1.1 848 Content-Type: application/json 849 850 { 851 "username":"hannibal", 852 "password:"xxxx", 853 "email":"hannibal@a-team.com" 854 } 855 856 **Example response**: 857 858 HTTP/1.1 200 OK 859 Content-Type: text/plain 860 861 Status Codes: 862 863 - **200** – no error 864 - **204** – no error 865 - **500** – server error 866 867 ### Display system-wide information 868 869 `GET /info` 870 871 Display system-wide information 872 873 **Example request**: 874 875 GET /info HTTP/1.1 876 877 **Example response**: 878 879 HTTP/1.1 200 OK 880 Content-Type: application/json 881 882 { 883 "Containers":11, 884 "Images":16, 885 "Debug":false, 886 "NFd": 11, 887 "NGoroutines":21, 888 "MemoryLimit":true, 889 "SwapLimit":false 890 } 891 892 Status Codes: 893 894 - **200** – no error 895 - **500** – server error 896 897 ### Show the docker version information 898 899 `GET /version` 900 901 Show the docker version information 902 903 **Example request**: 904 905 GET /version HTTP/1.1 906 907 **Example response**: 908 909 HTTP/1.1 200 OK 910 Content-Type: application/json 911 912 { 913 "Version":"0.2.2", 914 "GitCommit":"5a2a5cc+CHANGES", 915 "GoVersion":"go1.0.3" 916 } 917 918 Status Codes: 919 920 - **200** – no error 921 - **500** – server error 922 923 ### Create a new image from a container's changes 924 925 `POST /commit` 926 927 Create a new image from a container's changes 928 > 929 > **Example request**: 930 931 POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1 932 Content-Type: application/json 933 934 { 935 "Cmd": ["cat", "/world"], 936 "PortSpecs":["22"] 937 } 938 939 **Example response**: 940 941 HTTP/1.1 201 OK 942 Content-Type: application/vnd.docker.raw-stream 943 944 {"Id": "596069db4bf5"} 945 946 Query Parameters: 947 948 - **container** – source container 949 - **repo** – repository 950 - **tag** – tag 951 - **m** – commit message 952 - **author** – author (e.g., "John Hannibal Smith 953 <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") 954 955 Status Codes: 956 957 - **201** – no error 958 - **404** – no such container 959 - **500** – server error 960 961 # 3. Going further 962 963 ## 3.1 Inside `docker run` 964 965 As an example, the `docker run` command line makes the following API calls: 966 967 - Create the container 968 969 - If the status code is 404, it means the image doesn't exist: 970 - Try to pull it 971 - Then retry to create the container 972 973 - Start the container 974 975 - If you are not in detached mode: 976 - Attach to the container, using logs=1 (to have stdout and 977 stderr from the container's start) and stream=1 978 979 - If in detached mode or only stdin is attached: 980 - Display the container's 981 982 ## 3.2 Hijacking 983 984 In this first version of the API, some of the endpoints, like /attach, 985 /pull or /push uses hijacking to transport stdin, stdout and stderr on 986 the same socket. This might change in the future.