api.rst 17 KB

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