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