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