github.com/pritambaral/docker@v1.4.2-0.20150120174542-b2fe1b3dd952/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 ### Wait a container 389 390 `POST /containers/(id)/wait` 391 392 Block until container `id` stops, then returns the exit code 393 394 **Example request**: 395 396 POST /containers/16253994b7c4/wait HTTP/1.1 397 398 **Example response**: 399 400 HTTP/1.1 200 OK 401 Content-Type: application/json 402 403 {"StatusCode": 0} 404 405 Status Codes: 406 407 - **200** – no error 408 - **404** – no such container 409 - **500** – server error 410 411 ### Remove a container 412 413 `DELETE /containers/(id)` 414 415 Remove the container `id` from the filesystem 416 417 **Example request**: 418 419 DELETE /containers/16253994b7c4?v=1 HTTP/1.1 420 421 **Example response**: 422 423 HTTP/1.1 204 OK 424 425 Query Parameters: 426 427 - **v** – 1/True/true or 0/False/false, Remove the volumes 428 associated to the container. Default false 429 430 Status Codes: 431 432 - **204** – no error 433 - **400** – bad parameter 434 - **404** – no such container 435 - **500** – server error 436 437 ## 2.2 Images 438 439 ### List Images 440 441 `GET /images/(format)` 442 443 List images `format` could be json or viz (json default) 444 445 **Example request**: 446 447 GET /images/json?all=0 HTTP/1.1 448 449 **Example response**: 450 451 HTTP/1.1 200 OK 452 Content-Type: application/json 453 454 [ 455 { 456 "Repository":"ubuntu", 457 "Tag":"precise", 458 "Id":"b750fe79269d", 459 "Created":1364102658 460 }, 461 { 462 "Repository":"ubuntu", 463 "Tag":"12.04", 464 "Id":"b750fe79269d", 465 "Created":1364102658 466 } 467 ] 468 469 **Example request**: 470 471 GET /images/viz HTTP/1.1 472 473 **Example response**: 474 475 HTTP/1.1 200 OK 476 Content-Type: text/plain 477 478 digraph docker { 479 "d82cbacda43a" -> "074be284591f" 480 "1496068ca813" -> "08306dc45919" 481 "08306dc45919" -> "0e7893146ac2" 482 "b750fe79269d" -> "1496068ca813" 483 base -> "27cf78414709" [style=invis] 484 "f71189fff3de" -> "9a33b36209ed" 485 "27cf78414709" -> "b750fe79269d" 486 "0e7893146ac2" -> "d6434d954665" 487 "d6434d954665" -> "d82cbacda43a" 488 base -> "e9aa60c60128" [style=invis] 489 "074be284591f" -> "f71189fff3de" 490 "b750fe79269d" [label="b750fe79269d\nubuntu",shape=box,fillcolor="paleturquoise",style="filled,rounded"]; 491 "e9aa60c60128" [label="e9aa60c60128\ncentos",shape=box,fillcolor="paleturquoise",style="filled,rounded"]; 492 "9a33b36209ed" [label="9a33b36209ed\nfedora",shape=box,fillcolor="paleturquoise",style="filled,rounded"]; 493 base [style=invisible] 494 } 495 496 Query Parameters: 497 498 - **all** – 1/True/true or 0/False/false, Show all containers. 499 Only running containers are shown by defaul 500 501 Status Codes: 502 503 - **200** – no error 504 - **400** – bad parameter 505 - **500** – server error 506 507 ### Create an image 508 509 `POST /images/create` 510 511 Create an image, either by pull it from the registry or by importing i 512 513 **Example request**: 514 515 POST /images/create?fromImage=ubuntu HTTP/1.1 516 517 **Example response**: 518 519 HTTP/1.1 200 OK 520 Content-Type: application/json 521 522 {"status":"Pulling..."} 523 {"status":"Pulling", "progress":"1/? (n/a)"} 524 {"error":"Invalid..."} 525 ... 526 527 Query Parameters: 528 529 - **fromImage** – name of the image to pull 530 - **fromSrc** – source to import, - means stdin 531 - **repo** – repository 532 - **tag** – tag 533 - **registry** – the registry to pull from 534 535 Status Codes: 536 537 - **200** – no error 538 - **500** – server error 539 540 ### Insert a file in an image 541 542 `POST /images/(name)/insert` 543 544 Insert a file from `url` in the image `name` at `path` 545 546 **Example request**: 547 548 POST /images/test/insert?path=/usr&url=myurl HTTP/1.1 549 550 **Example response**: 551 552 HTTP/1.1 200 OK 553 Content-Type: application/json 554 555 {"status":"Inserting..."} 556 {"status":"Inserting", "progress":"1/? (n/a)"} 557 {"error":"Invalid..."} 558 ... 559 560 Query Parameters: 561 562 - **url** – The url from where the file is taken 563 - **path** – The path where the file is stored 564 565 Status Codes: 566 567 - **200** – no error 568 - **500** – server error 569 570 ### Inspect an image 571 572 `GET /images/(name)/json` 573 574 Return low-level information on the image `name` 575 576 **Example request**: 577 578 GET /images/centos/json HTTP/1.1 579 580 **Example response**: 581 582 HTTP/1.1 200 OK 583 Content-Type: application/json 584 585 { 586 "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 587 "parent":"27cf784147099545", 588 "created":"2013-03-23T22:24:18.818426-07:00", 589 "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", 590 "container_config": 591 { 592 "Hostname":"", 593 "User":"", 594 "Memory":0, 595 "MemorySwap":0, 596 "AttachStdin":false, 597 "AttachStdout":false, 598 "AttachStderr":false, 599 "PortSpecs":null, 600 "Tty":true, 601 "OpenStdin":true, 602 "StdinOnce":false, 603 "Env":null, 604 "Cmd": ["/bin/bash"], 605 "Dns":null, 606 "Image":"centos", 607 "Volumes":null, 608 "VolumesFrom":"" 609 } 610 } 611 612 Status Codes: 613 614 - **200** – no error 615 - **404** – no such image 616 - **500** – server error 617 618 ### Get the history of an image 619 620 `GET /images/(name)/history` 621 622 Return the history of the image `name` 623 624 **Example request**: 625 626 GET /images/fedora/history HTTP/1.1 627 628 **Example response**: 629 630 HTTP/1.1 200 OK 631 Content-Type: application/json 632 633 [ 634 { 635 "Id": "b750fe79269d", 636 "Created": 1364102658, 637 "CreatedBy": "/bin/bash" 638 }, 639 { 640 "Id": "27cf78414709", 641 "Created": 1364068391, 642 "CreatedBy": "" 643 } 644 ] 645 646 Status Codes: 647 648 - **200** – no error 649 - **404** – no such image 650 - **500** – server error 651 652 ### Push an image on the registry 653 654 `POST /images/(name)/push` 655 656 Push the image `name` on the registry 657 658 > **Example request**: 659 > 660 > POST /images/test/push HTTP/1.1 661 > 662 > **Example response**: 663 664 HTTP/1.1 200 OK 665 Content-Type: application/json 666 667 {"status":"Pushing..."} 668 {"status":"Pushing", "progress":"1/? (n/a)"} 669 {"error":"Invalid..."} 670 ... 671 672 Status Codes: 673 674 - **200** – no error 675 - **404** – no such image 676 - **500** – server error 677 678 ### Tag an image into a repository 679 680 `POST /images/(name)/tag` 681 682 Tag the image `name` into a repository 683 684 **Example request**: 685 686 POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 687 688 **Example response**: 689 690 HTTP/1.1 201 OK 691 692 Query Parameters: 693 694 - **repo** – The repository to tag in 695 - **force** – 1/True/true or 0/False/false, default false 696 - **tag** - The new tag name 697 698 Status Codes: 699 700 - **201** – no error 701 - **400** – bad parameter 702 - **404** – no such image 703 - **409** – conflict 704 - **500** – server error 705 706 ### Remove an image 707 708 `DELETE /images/(name)` 709 710 Remove the image `name` from the filesystem 711 712 **Example request**: 713 714 DELETE /images/test HTTP/1.1 715 716 **Example response**: 717 718 HTTP/1.1 204 No Content 719 720 Status Codes: 721 722 - **204** – no error 723 - **404** – no such image 724 - **500** – server error 725 726 ### Search images 727 728 `GET /images/search` 729 730 Search for an image on [Docker Hub](https://hub.docker.com) 731 732 **Example request**: 733 734 GET /images/search?term=sshd HTTP/1.1 735 736 **Example response**: 737 738 HTTP/1.1 200 OK 739 Content-Type: application/json 740 741 [ 742 { 743 "Name":"cespare/sshd", 744 "Description":"" 745 }, 746 { 747 "Name":"johnfuller/sshd", 748 "Description":"" 749 }, 750 { 751 "Name":"dhrp/mongodb-sshd", 752 "Description":"" 753 } 754 ] 755 756 :query term: term to search 757 :statuscode 200: no error 758 :statuscode 500: server error 759 760 ## 2.3 Misc 761 762 ### Build an image from Dockerfile via stdin 763 764 `POST /build` 765 766 Build an image from Dockerfile via stdin 767 768 **Example request**: 769 770 POST /build HTTP/1.1 771 772 {{ STREAM }} 773 774 **Example response**: 775 776 HTTP/1.1 200 OK 777 778 {{ STREAM }} 779 780 Query Parameters: 781 782 783 784 - **t** – tag to be applied to the resulting image in case of 785 success 786 787 Status Codes: 788 789 - **200** – no error 790 - **500** – server error 791 792 ### Get default username and email 793 794 `GET /auth` 795 796 Get the default username and email 797 798 **Example request**: 799 800 GET /auth HTTP/1.1 801 802 **Example response**: 803 804 HTTP/1.1 200 OK 805 Content-Type: application/json 806 807 { 808 "username":"hannibal", 809 "email":"hannibal@a-team.com" 810 } 811 812 Status Codes: 813 814 - **200** – no error 815 - **500** – server error 816 817 ### Check auth configuration and store i 818 819 `POST /auth` 820 821 Get the default username and email 822 823 **Example request**: 824 825 POST /auth HTTP/1.1 826 Content-Type: application/json 827 828 { 829 "username":"hannibal", 830 "password:"xxxx", 831 "email":"hannibal@a-team.com" 832 } 833 834 **Example response**: 835 836 HTTP/1.1 200 OK 837 Content-Type: text/plain 838 839 Status Codes: 840 841 - **200** – no error 842 - **204** – no error 843 - **500** – server error 844 845 ### Display system-wide information 846 847 `GET /info` 848 849 Display system-wide information 850 851 **Example request**: 852 853 GET /info HTTP/1.1 854 855 **Example response**: 856 857 HTTP/1.1 200 OK 858 Content-Type: application/json 859 860 { 861 "Containers":11, 862 "Images":16, 863 "Debug":false, 864 "NFd": 11, 865 "NGoroutines":21, 866 "MemoryLimit":true, 867 "SwapLimit":false 868 } 869 870 Status Codes: 871 872 - **200** – no error 873 - **500** – server error 874 875 ### Show the docker version information 876 877 `GET /version` 878 879 Show the docker version information 880 881 **Example request**: 882 883 GET /version HTTP/1.1 884 885 **Example response**: 886 887 HTTP/1.1 200 OK 888 Content-Type: application/json 889 890 { 891 "Version":"0.2.2", 892 "GitCommit":"5a2a5cc+CHANGES", 893 "GoVersion":"go1.0.3" 894 } 895 896 Status Codes: 897 898 - **200** – no error 899 - **500** – server error 900 901 ### Create a new image from a container's changes 902 903 `POST /commit` 904 905 Create a new image from a container's changes 906 907 **Example request**: 908 909 POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1 910 Content-Type: application/json 911 912 { 913 "Cmd": ["cat", "/world"], 914 "PortSpecs":["22"] 915 } 916 917 **Example response**: 918 919 HTTP/1.1 201 OK 920 Content-Type: application/vnd.docker.raw-stream 921 922 {"Id": "596069db4bf5"} 923 924 Query Parameters: 925 926 - **container** – source container 927 - **repo** – repository 928 - **tag** – tag 929 - **m** – commit message 930 - **author** – author (e.g., "John Hannibal Smith 931 <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") 932 933 Status Codes: 934 935 - **201** – no error 936 - **404** – no such container 937 - **500** – server error 938 939 # 3. Going further 940 941 ## 3.1 Inside `docker run` 942 943 Here are the steps of `docker run` : 944 945 - Create the container 946 947 - If the status code is 404, it means the image doesn't exist: 948 - Try to pull it 949 - Then retry to create the container 950 951 - Start the container 952 953 - If you are not in detached mode: 954 - Attach to the container, using logs=1 (to have stdout and 955 stderr from the container's start) and stream=1 956 957 - If in detached mode or only stdin is attached: 958 - Display the container's 959 960 ## 3.2 Hijacking 961 962 In this version of the API, /attach uses hijacking to transport stdin, 963 stdout and stderr on the same socket. This might change in the future.