api.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. =================
  2. Docker Remote API
  3. =================
  4. .. contents:: Table of Contents
  5. 1. Brief introduction
  6. =====================
  7. - The Remote API is replacing rcli
  8. - Default port in the docker deamon is 4243
  9. - The API tends to be REST, but for some complex commands, like attach or pull, the HTTP connection in hijacked to transport stdout stdin and stderr
  10. 2. Endpoints
  11. ============
  12. 2.1 Containers
  13. --------------
  14. List containers
  15. ***************
  16. .. http:get:: /containers
  17. List containers
  18. **Example request**:
  19. .. sourcecode:: http
  20. GET /containers?trunc_cmd=0&all=1&only_ids=0 HTTP/1.1
  21. **Example response**:
  22. .. sourcecode:: http
  23. HTTP/1.1 200 OK
  24. [
  25. {
  26. "Id": "8dfafdbc3a40",
  27. "Image": "base:latest",
  28. "Command": "echo 1",
  29. "Created": 1367854155,
  30. "Status": "Exit 0"
  31. },
  32. {
  33. "Id": "9cd87474be90",
  34. "Image": "base:latest",
  35. "Command": "echo 222222",
  36. "Created": 1367854155,
  37. "Status": "Exit 0"
  38. },
  39. {
  40. "Id": "3176a2479c92",
  41. "Image": "base:latest",
  42. "Command": "echo 3333333333333333",
  43. "Created": 1367854154,
  44. "Status": "Exit 0"
  45. },
  46. {
  47. "Id": "4cb07b47f9fb",
  48. "Image": "base:latest",
  49. "Command": "echo 444444444444444444444444444444444",
  50. "Created": 1367854152,
  51. "Status": "Exit 0"
  52. }
  53. ]
  54. :query only_ids: 1 or 0, Only display numeric IDs. Default 0
  55. :query all: 1 or 0, Show all containers. Only running containers are shown by default
  56. :query trunc_cmd: 1 or 0, Truncate output. Output is truncated by default
  57. :query limit: Show ``limit`` last created containers, include non-running ones.
  58. :statuscode 200: no error
  59. :statuscode 500: server error
  60. Create a container
  61. ******************
  62. .. http:post:: /containers
  63. Create a container
  64. **Example request**:
  65. .. sourcecode:: http
  66. POST /containers HTTP/1.1
  67. {
  68. "Hostname":"",
  69. "User":"",
  70. "Memory":0,
  71. "MemorySwap":0,
  72. "AttachStdin":false,
  73. "AttachStdout":true,
  74. "AttachStderr":true,
  75. "PortSpecs":null,
  76. "Tty":false,
  77. "OpenStdin":false,
  78. "StdinOnce":false,
  79. "Env":null,
  80. "Cmd":[
  81. "date"
  82. ],
  83. "Dns":null,
  84. "Image":"base",
  85. "Volumes":{},
  86. "VolumesFrom":""
  87. }
  88. **Example response**:
  89. .. sourcecode:: http
  90. HTTP/1.1 200 OK
  91. {
  92. "Id":"e90e34656806"
  93. "Warnings":[]
  94. }
  95. :jsonparam config: the container's configuration
  96. :statuscode 200: no error
  97. :statuscode 404: no such container
  98. :statuscode 500: server error
  99. Inspect a container
  100. *******************
  101. .. http:get:: /containers/(id)/json
  102. Return low-level information on the container ``id``
  103. **Example request**:
  104. .. sourcecode:: http
  105. GET /containers/4fa6e0f0c678/json HTTP/1.1
  106. **Example response**:
  107. .. sourcecode:: http
  108. HTTP/1.1 200 OK
  109. {
  110. "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
  111. "Created": "2013-05-07T14:51:42.041847+02:00",
  112. "Path": "date",
  113. "Args": [],
  114. "Config": {
  115. "Hostname": "4fa6e0f0c678",
  116. "User": "",
  117. "Memory": 0,
  118. "MemorySwap": 0,
  119. "AttachStdin": false,
  120. "AttachStdout": true,
  121. "AttachStderr": true,
  122. "PortSpecs": null,
  123. "Tty": false,
  124. "OpenStdin": false,
  125. "StdinOnce": false,
  126. "Env": null,
  127. "Cmd": [
  128. "date"
  129. ],
  130. "Dns": null,
  131. "Image": "base",
  132. "Volumes": {},
  133. "VolumesFrom": ""
  134. },
  135. "State": {
  136. "Running": false,
  137. "Pid": 0,
  138. "ExitCode": 0,
  139. "StartedAt": "2013-05-07T14:51:42.087658+02:01360",
  140. "Ghost": false
  141. },
  142. "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  143. "NetworkSettings": {
  144. "IpAddress": "",
  145. "IpPrefixLen": 0,
  146. "Gateway": "",
  147. "Bridge": "",
  148. "PortMapping": null
  149. },
  150. "SysInitPath": "/home/kitty/go/src/github.com/dotcloud/docker/bin/docker",
  151. "ResolvConfPath": "/etc/resolv.conf",
  152. "Volumes": {}
  153. }
  154. :statuscode 200: no error
  155. :statuscode 404: no such container
  156. :statuscode 500: server error
  157. Inspect changes on a container's filesystem
  158. *******************************************
  159. .. http:get:: /containers/(id)/changes
  160. Inspect changes on container ``id`` 's filesystem
  161. **Example request**:
  162. .. sourcecode:: http
  163. GET /containers/4fa6e0f0c678/changes HTTP/1.1
  164. **Example response**:
  165. .. sourcecode:: http
  166. HTTP/1.1 200 OK
  167. [
  168. {
  169. "Path":"/dev",
  170. "Kind":0
  171. },
  172. {
  173. "Path":"/dev/kmsg",
  174. "Kind":1
  175. },
  176. {
  177. "Path":"/test",
  178. "Kind":1
  179. }
  180. ]
  181. :statuscode 200: no error
  182. :statuscode 404: no such container
  183. :statuscode 500: server error
  184. Export a container
  185. ******************
  186. .. http:get:: /containers/(id)/export
  187. Export the contents of container ``id``
  188. **Example request**:
  189. .. sourcecode:: http
  190. GET /containers/4fa6e0f0c678/export HTTP/1.1
  191. **Example response**:
  192. .. sourcecode:: http
  193. HTTP/1.1 200 OK
  194. Content-Type: raw-stream-hijack
  195. {{ STREAM }}
  196. :statuscode 200: no error
  197. :statuscode 404: no such container
  198. :statuscode 500: server error
  199. Start a container
  200. *****************
  201. .. http:post:: /containers/(id)/start
  202. Start the container ``id``
  203. **Example request**:
  204. .. sourcecode:: http
  205. POST /containers/e90e34656806/start HTTP/1.1
  206. **Example response**:
  207. .. sourcecode:: http
  208. HTTP/1.1 200 OK
  209. :statuscode 200: no error
  210. :statuscode 404: no such container
  211. :statuscode 500: server error
  212. Stop a contaier
  213. ***************
  214. .. http:post:: /containers/(id)/stop
  215. Stop the container ``id``
  216. **Example request**:
  217. .. sourcecode:: http
  218. POST /containers/e90e34656806/stop?t=5 HTTP/1.1
  219. **Example response**:
  220. .. sourcecode:: http
  221. HTTP/1.1 200 OK
  222. :query t: number of seconds to wait before killing the container
  223. :statuscode 200: no error
  224. :statuscode 404: no such container
  225. :statuscode 500: server error
  226. Restart a container
  227. *******************
  228. .. http:post:: /containers/(id)/restart
  229. Restart the container ``id``
  230. **Example request**:
  231. .. sourcecode:: http
  232. POST /containers/e90e34656806/restart?t=5 HTTP/1.1
  233. **Example response**:
  234. .. sourcecode:: http
  235. HTTP/1.1 200 OK
  236. :query t: number of seconds to wait before killing the container
  237. :statuscode 200: no error
  238. :statuscode 404: no such container
  239. :statuscode 500: server error
  240. Kill a container
  241. ****************
  242. .. http:post:: /containers/(id)/kill
  243. Kill the container ``id``
  244. **Example request**:
  245. .. sourcecode:: http
  246. POST /containers/e90e34656806/kill HTTP/1.1
  247. **Example response**:
  248. .. sourcecode:: http
  249. HTTP/1.1 200 OK
  250. :statuscode 200: no error
  251. :statuscode 404: no such container
  252. :statuscode 500: server error
  253. Attach to a container
  254. *********************
  255. .. http:post:: /containers/(id)/attach
  256. Stop the container ``id``
  257. **Example request**:
  258. .. sourcecode:: http
  259. POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1
  260. **Example response**:
  261. .. sourcecode:: http
  262. HTTP/1.1 200 OK
  263. Content-Type: raw-stream-hijack
  264. {{ STREAM }}
  265. :query logs: 1 or 0, return logs. Default 0
  266. :query stream: 1 or 0, return stream. Default 0
  267. :query stdin: 1 or 0, if stream=1, attach to stdin. Default 0
  268. :query stdout: 1 or 0, if logs=1, return stdout log, if stream=1, attach to stdout. Default 0
  269. :query stderr: 1 or 0, if logs=1, return stderr log, if stream=1, attach to stderr. Default 0
  270. :statuscode 200: no error
  271. :statuscode 404: no such container
  272. :statuscode 500: server error
  273. Wait a container
  274. ****************
  275. .. http:post:: /containers/(id)/wait
  276. Block until container ``id`` stops, then returns the exit code
  277. **Example request**:
  278. .. sourcecode:: http
  279. POST /containers/16253994b7c4/wait HTTP/1.1
  280. **Example response**:
  281. .. sourcecode:: http
  282. HTTP/1.1 200 OK
  283. {"StatusCode":0}
  284. :statuscode 200: no error
  285. :statuscode 404: no such container
  286. :statuscode 500: server error
  287. Remove a container
  288. *******************
  289. .. http:delete:: /container/(id)
  290. Remove the container ``id`` from the filesystem
  291. **Example request**:
  292. .. sourcecode:: http
  293. DELETE /containers/16253994b7c4?v=1 HTTP/1.1
  294. **Example response**:
  295. .. sourcecode:: http
  296. HTTP/1.1 200 OK
  297. :query v: 1 or 0, Remove the volumes associated to the container. Default 0
  298. :statuscode 200: no error
  299. :statuscode 404: no such container
  300. :statuscode 500: server error
  301. 2.2 Images
  302. ----------
  303. List Images
  304. ***********
  305. .. http:get:: /images
  306. List images
  307. **Example request**:
  308. .. sourcecode:: http
  309. GET /images?all=0&only_ids=0 HTTP/1.1
  310. **Example response**:
  311. .. sourcecode:: http
  312. HTTP/1.1 200 OK
  313. [
  314. {
  315. "Repository":"base",
  316. "Tag":"ubuntu-12.10",
  317. "Id":"b750fe79269d",
  318. "Created":1364102658
  319. },
  320. {
  321. "Repository":"base",
  322. "Tag":"ubuntu-quantal",
  323. "Id":"b750fe79269d",
  324. "Created":1364102658
  325. }
  326. ]
  327. :query only_ids: 1 or 0, Only display numeric IDs. Default 0
  328. :query all: 1 or 0, Show all containers. Only running containers are shown by default
  329. :statuscode 200: no error
  330. :statuscode 500: server error
  331. Create an image
  332. ***************
  333. .. http:post:: /images
  334. Create an image, either by pull it from the registry or by importing it
  335. **Example request**:
  336. .. sourcecode:: http
  337. POST /images?fromImage=base HTTP/1.1
  338. **Example response**:
  339. .. sourcecode:: http
  340. HTTP/1.1 200 OK
  341. Content-Type: raw-stream-hijack
  342. {{ STREAM }}
  343. :query fromImage: name of the image to pull
  344. :query fromSrc: source to import, - means stdin
  345. :query repo: repository
  346. :query tag: tag
  347. :query registry: the registry to pull from
  348. :statuscode 200: no error
  349. :statuscode 500: server error
  350. Insert a file in a image
  351. ************************
  352. .. http:post:: /images/(name)/insert
  353. Insert a file from ``url`` in the image ``name`` at ``path``
  354. **Example request**:
  355. .. sourcecode:: http
  356. POST /images/test/insert?path=/usr&url=myurl HTTP/1.1
  357. **Example response**:
  358. .. sourcecode:: http
  359. HTTP/1.1 200 OK
  360. {{ STREAM }}
  361. :statuscode 200: no error
  362. :statuscode 500: server error
  363. Inspect an image
  364. ****************
  365. .. http:get:: /images/(name)/json
  366. Return low-level information on the image ``name``
  367. **Example request**:
  368. .. sourcecode:: http
  369. GET /images/base/json HTTP/1.1
  370. **Example response**:
  371. .. sourcecode:: http
  372. HTTP/1.1 200 OK
  373. {
  374. "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  375. "parent":"27cf784147099545",
  376. "created":"2013-03-23T22:24:18.818426-07:00",
  377. "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
  378. "container_config":
  379. {
  380. "Hostname":"",
  381. "User":"",
  382. "Memory":0,
  383. "MemorySwap":0,
  384. "AttachStdin":false,
  385. "AttachStdout":false,
  386. "AttachStderr":false,
  387. "PortSpecs":null,
  388. "Tty":true,
  389. "OpenStdin":true,
  390. "StdinOnce":false,
  391. "Env":null,
  392. "Cmd": ["/bin/bash"]
  393. ,"Dns":null,
  394. "Image":"base",
  395. "Volumes":null,
  396. "VolumesFrom":""
  397. }
  398. }
  399. :statuscode 200: no error
  400. :statuscode 404: no such image
  401. :statuscode 500: server error
  402. Get the history of an image
  403. ***************************
  404. .. http:get:: /images/(name)
  405. Return the history of the image ``name``
  406. **Example request**:
  407. .. sourcecode:: http
  408. GET /images/base/history HTTP/1.1
  409. **Example response**:
  410. .. sourcecode:: http
  411. HTTP/1.1 200 OK
  412. [
  413. {
  414. "Id":"b750fe79269d",
  415. "Created":1364102658,
  416. "CreatedBy":"/bin/bash"
  417. },
  418. {
  419. "Id":"27cf78414709",
  420. "Created":1364068391,
  421. "CreatedBy":""
  422. }
  423. ]
  424. :statuscode 200: no error
  425. :statuscode 404: no such image
  426. :statuscode 500: server error
  427. Push an image on the registry
  428. *****************************
  429. .. http:post:: /images/(name)/push
  430. Push the image ``name`` on the registry
  431. **Example request**:
  432. .. sourcecode:: http
  433. POST /images/test/push HTTP/1.1
  434. **Example response**:
  435. .. sourcecode:: http
  436. HTTP/1.1 200 OK
  437. Content-Type: raw-stream-hijack
  438. {{ STREAM }}
  439. :query registry: the registry you wan to push, optional
  440. :statuscode 200: no error
  441. :statuscode 404: no such image
  442. :statuscode 500: server error
  443. Tag an image into a repository
  444. ******************************
  445. .. http:post:: /images/(name)/tag
  446. Tag the image ``name`` into a repository
  447. **Example request**:
  448. .. sourcecode:: http
  449. POST /images/test/tag?repo=myrepo&force=0 HTTP/1.1
  450. **Example response**:
  451. .. sourcecode:: http
  452. HTTP/1.1 200 OK
  453. :query repo: The repository to tag in
  454. :query force: 1 or 0, default 0
  455. :statuscode 200: no error
  456. :statuscode 404: no such image
  457. :statuscode 500: server error
  458. Remove an image
  459. ***************
  460. .. http:delete:: /images/(name)
  461. Remove the image ``name`` from the filesystem
  462. **Example request**:
  463. .. sourcecode:: http
  464. DELETE /images/test HTTP/1.1
  465. **Example response**:
  466. .. sourcecode:: http
  467. HTTP/1.1 200 OK
  468. :statuscode 200: no error
  469. :statuscode 404: no such image
  470. :statuscode 500: server error
  471. Search images
  472. *************
  473. .. http:get:: /images/search
  474. Search for an image in the docker index
  475. **Example request**:
  476. .. sourcecode:: http
  477. GET /images/search?term=sshd HTTP/1.1
  478. **Example response**:
  479. .. sourcecode:: http
  480. [
  481. {
  482. "Name":"cespare/sshd",
  483. "Description":""
  484. },
  485. {
  486. "Name":"johnfuller/sshd",
  487. "Description":""
  488. },
  489. {
  490. "Name":"dhrp/mongodb-sshd",
  491. "Description":""
  492. }
  493. ]
  494. :query term: term to search
  495. :statuscode 200: no error
  496. :statuscode 500: server error
  497. 2.3 Misc
  498. --------
  499. Build an image from Dockerfile via stdin
  500. ****************************************
  501. .. http:post:: /build
  502. Build an image from Dockerfile via stdin
  503. **Example request**:
  504. .. sourcecode:: http
  505. POST /build HTTP/1.1
  506. {{ STREAM }}
  507. **Example response**:
  508. .. sourcecode:: http
  509. HTTP/1.1 200 OK
  510. {{ STREAM }}
  511. :statuscode 200: no error
  512. :statuscode 500: server error
  513. Get default username and email
  514. ******************************
  515. .. http:get:: /auth
  516. Get the default username and email
  517. **Example request**:
  518. .. sourcecode:: http
  519. GET /auth HTTP/1.1
  520. **Example response**:
  521. .. sourcecode:: http
  522. HTTP/1.1 200 OK
  523. {
  524. "username":"hannibal",
  525. "email":"hannibal@a-team.com"
  526. }
  527. :statuscode 200: no error
  528. :statuscode 500: server error
  529. Set auth configuration
  530. **********************
  531. .. http:post:: /auth
  532. Get the default username and email
  533. **Example request**:
  534. .. sourcecode:: http
  535. POST /auth HTTP/1.1
  536. {
  537. "username":"hannibal",
  538. "password:"xxxx",
  539. "email":"hannibal@a-team.com"
  540. }
  541. **Example response**:
  542. .. sourcecode:: http
  543. HTTP/1.1 200 OK
  544. :statuscode 200: no error
  545. :statuscode 500: server error
  546. Display system-wide information
  547. *******************************
  548. .. http:get:: /info
  549. Display system-wide information
  550. **Example request**:
  551. .. sourcecode:: http
  552. GET /info HTTP/1.1
  553. **Example response**:
  554. .. sourcecode:: http
  555. HTTP/1.1 200 OK
  556. {
  557. "Containers":11,
  558. "Version":"0.2.2",
  559. "Images":16,
  560. "Debug":false
  561. }
  562. :statuscode 200: no error
  563. :statuscode 500: server error
  564. Show the docker version information
  565. ***********************************
  566. .. http:get:: /version
  567. Show the docker version information
  568. **Example request**:
  569. .. sourcecode:: http
  570. GET /version HTTP/1.1
  571. **Example response**:
  572. .. sourcecode:: http
  573. HTTP/1.1 200 OK
  574. {
  575. "Version":"0.2.2",
  576. "GitCommit":"5a2a5cc+CHANGES",
  577. "MemoryLimit":true,
  578. "SwapLimit":false
  579. }
  580. :statuscode 200: no error
  581. :statuscode 500: server error
  582. Create a new image from a container's changes
  583. *********************************************
  584. .. http:post:: /commit
  585. Create a new image from a container's changes
  586. **Example request**:
  587. .. sourcecode:: http
  588. POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1
  589. **Example response**:
  590. .. sourcecode:: http
  591. HTTP/1.1 200 OK
  592. Content-Type: raw-stream-hijack
  593. {{ STREAM }}
  594. :query container: source container
  595. :query repo: repository
  596. :query tag: tag
  597. :query m: commit message
  598. :query author: author (eg. "John Hannibal Smith <hannibal@a-team.com>")
  599. :query run: config automatically applied when the image is run. (ex: {"Cmd": ["cat", "/world"], "PortSpecs":["22"]})
  600. :statuscode 200: no error
  601. :statuscode 404: no such container
  602. :statuscode 500: server error
  603. 3. Going further
  604. ================
  605. 3.1 Inside 'docker run'
  606. -----------------------
  607. Here are the steps of 'docker run' :
  608. * Create the container
  609. * If the status code is 404, it means the image doesn't exists:
  610. * Try to pull it
  611. * Then retry to create the container
  612. * Start the container
  613. * If you are not in detached mode:
  614. * Attach to the container, using logs=1 (to have stdout and stderr from the container's start) and stream=1
  615. * If in detached mode or only stdin is attached:
  616. * Display the container's id
  617. 3.2 Hijacking
  618. -------------
  619. In this first version of the API, some of the endpoints, like /attach, /pull or /push uses hijacking to transport stdin,
  620. stdout and stderr on the same socket. This might change in the future.