api.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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?notrunc=1&all=1&quiet=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 2",
  36. "Created": 1367854155,
  37. "Status": "Exit 0"
  38. },
  39. {
  40. "Id": "3176a2479c92",
  41. "Image": "base:latest",
  42. "Command": "echo 3",
  43. "Created": 1367854154,
  44. "Status": "Exit 0"
  45. },
  46. {
  47. "Id": "4cb07b47f9fb",
  48. "Image": "base:latest",
  49. "Command": "echo 4",
  50. "Created": 1367854152,
  51. "Status": "Exit 0"
  52. }
  53. ]
  54. :query quiet: 1 or 0, Only display numeric IDs. Not quiet by default
  55. :query all: 1 or 0, Show all containers. Only running containers are shown by default
  56. :query notrunc: 1 or 0, Don't truncate output. Output is truncated by default
  57. :query n: limit number, Show n 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 400: no such container
  98. :statuscode 500: server error
  99. Inspect a container
  100. *******************
  101. .. http:get:: /containers/(id)
  102. Return low-level information on the container ``id``
  103. **Example request**:
  104. .. sourcecode:: http
  105. GET /containers/4fa6e0f0c678 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 400: 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. "C /dev",
  169. "A /dev/kmsg"
  170. ]
  171. :statuscode 200: no error
  172. :statuscode 400: no such container
  173. :statuscode 500: server error
  174. Export a container
  175. ******************
  176. .. http:get:: /containers/(id)/export
  177. Export the contents of container ``id``
  178. **Example request**:
  179. .. sourcecode:: http
  180. GET /containers/4fa6e0f0c678/export HTTP/1.1
  181. **Example response**:
  182. .. sourcecode:: http
  183. HTTP/1.1 200 OK
  184. Content-Type: raw-stream-hijack
  185. {{ STREAM }}
  186. :statuscode 200: no error
  187. :statuscode 400: no such container
  188. :statuscode 500: server error
  189. Map container's private ports
  190. *****************************
  191. .. http:get:: /containers/(id)/port
  192. Map a private port of container ``id``
  193. **Example request**:
  194. .. sourcecode:: http
  195. GET /containers/4fa6e0f0c678/port?port=80 HTTP/1.1
  196. **Example response**:
  197. .. sourcecode:: http
  198. HTTP/1.1 200 OK
  199. {"Port":"80"}
  200. :query port: the container private port you want to get
  201. :statuscode 200: no error
  202. :statuscode 400: no such container
  203. :statuscode 500: server error
  204. Start a container
  205. *****************
  206. .. http:post:: /containers/(id)/start
  207. Start the container ``id``
  208. **Example request**:
  209. .. sourcecode:: http
  210. POST /containers/e90e34656806/start HTTP/1.1
  211. **Example response**:
  212. .. sourcecode:: http
  213. HTTP/1.1 200 OK
  214. :statuscode 200: no error
  215. :statuscode 400: no such container
  216. :statuscode 500: server error
  217. Stop a contaier
  218. ***************
  219. .. http:post:: /containers/(id)/stop
  220. Stop the container ``id``
  221. **Example request**:
  222. .. sourcecode:: http
  223. POST /containers/e90e34656806/stop?t=5 HTTP/1.1
  224. **Example response**:
  225. .. sourcecode:: http
  226. HTTP/1.1 200 OK
  227. :query t: number of seconds to wait before killing the container
  228. :statuscode 200: no error
  229. :statuscode 400: no such container
  230. :statuscode 500: server error
  231. Restart a container
  232. *******************
  233. .. http:post:: /containers/(id)/restart
  234. Restart the container ``id``
  235. **Example request**:
  236. .. sourcecode:: http
  237. POST /containers/e90e34656806/restart?t=5 HTTP/1.1
  238. **Example response**:
  239. .. sourcecode:: http
  240. HTTP/1.1 200 OK
  241. :query t: number of seconds to wait before killing the container
  242. :statuscode 200: no error
  243. :statuscode 400: no such container
  244. :statuscode 500: server error
  245. Kill a container
  246. ****************
  247. .. http:post:: /containers/(id)/kill
  248. Kill the container ``id``
  249. **Example request**:
  250. .. sourcecode:: http
  251. POST /containers/e90e34656806/kill HTTP/1.1
  252. **Example response**:
  253. .. sourcecode:: http
  254. HTTP/1.1 200 OK
  255. :statuscode 200: no error
  256. :statuscode 400: no such container
  257. :statuscode 500: server error
  258. Attach to a container
  259. *********************
  260. .. http:post:: /containers/(id)/attach
  261. Stop the container ``id``
  262. **Example request**:
  263. .. sourcecode:: http
  264. POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1
  265. **Example response**:
  266. .. sourcecode:: http
  267. HTTP/1.1 200 OK
  268. Content-Type: raw-stream-hijack
  269. {{ STREAM }}
  270. :query logs: 1 or 0, return logs. Default 0
  271. :query stream: 1 or 0, return stream. Default 0
  272. :query stdin: 1 or 0, if stream=1, attach to stdin. Default 0
  273. :query stdout: 1 or 0, if logs=1, return stdout log, if stream=1, attach to stdout. Default 0
  274. :query stderr: 1 or 0, if logs=1, return stderr log, if stream=1, attach to stderr. Default 0
  275. :statuscode 200: no error
  276. :statuscode 400: no such container
  277. :statuscode 500: server error
  278. Wait a container
  279. ****************
  280. .. http:post:: /containers/(id)/wait
  281. Block until container ``id`` stops, then returns the exit code
  282. **Example request**:
  283. .. sourcecode:: http
  284. POST /containers/16253994b7c4/wait HTTP/1.1
  285. **Example response**:
  286. .. sourcecode:: http
  287. HTTP/1.1 200 OK
  288. {"StatusCode":0}
  289. :statuscode 200: no error
  290. :statuscode 400: no such container
  291. :statuscode 500: server error
  292. Remove a container
  293. *******************
  294. .. http:delete:: /container/(id)
  295. Remove the container ``id`` from the filesystem
  296. **Example request**:
  297. .. sourcecode:: http
  298. DELETE /containers/16253994b7c4?v=1 HTTP/1.1
  299. **Example response**:
  300. .. sourcecode:: http
  301. HTTP/1.1 200 OK
  302. :query v: 1 or 0, Remove the volumes associated to the container. Default 0
  303. :statuscode 200: no error
  304. :statuscode 400: no such container
  305. :statuscode 500: server error
  306. 2.2 Images
  307. ----------
  308. List Images
  309. ***********
  310. .. http:get:: /images
  311. List images
  312. **Example request**:
  313. .. sourcecode:: http
  314. GET /images?all=0&quiet=0 HTTP/1.1
  315. **Example response**:
  316. .. sourcecode:: http
  317. HTTP/1.1 200 OK
  318. [
  319. {
  320. "Repository":"base",
  321. "Tag":"ubuntu-12.10",
  322. "Id":"b750fe79269d",
  323. "Created":1364102658
  324. },
  325. {
  326. "Repository":"base",
  327. "Tag":"ubuntu-quantal",
  328. "Id":"b750fe79269d",
  329. "Created":1364102658
  330. }
  331. ]
  332. :query quiet: 1 or 0, Only display numeric IDs. Not quiet by default
  333. :query all: 1 or 0, Show all containers. Only running containers are shown by default
  334. :statuscode 200: no error
  335. :statuscode 500: server error
  336. Create an image
  337. ***************
  338. .. http:post:: /images
  339. Create an image, either by pull it from the registry or by importing it
  340. **Example request**:
  341. .. sourcecode:: http
  342. POST /images?fromImage=base HTTP/1.1
  343. **Example response**:
  344. .. sourcecode:: http
  345. HTTP/1.1 200 OK
  346. Content-Type: raw-stream-hijack
  347. {{ STREAM }}
  348. :query fromImage: name of the image to pull
  349. :query fromSrc: source to import, - means stdin
  350. :query repo: repository
  351. :query tag: tag
  352. :statuscode 200: no error
  353. :statuscode 500: server error
  354. Inspect an image
  355. ****************
  356. .. http:get:: /images/(name)
  357. Return low-level information on the image ``name``
  358. **Example request**:
  359. .. sourcecode:: http
  360. GET /images/base HTTP/1.1
  361. **Example response**:
  362. .. sourcecode:: http
  363. HTTP/1.1 200 OK
  364. {
  365. "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  366. "parent":"27cf784147099545",
  367. "created":"2013-03-23T22:24:18.818426-07:00",
  368. "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
  369. "container_config":
  370. {
  371. "Hostname":"",
  372. "User":"",
  373. "Memory":0,
  374. "MemorySwap":0,
  375. "AttachStdin":false,
  376. "AttachStdout":false,
  377. "AttachStderr":false,
  378. "PortSpecs":null,
  379. "Tty":true,
  380. "OpenStdin":true,
  381. "StdinOnce":false,
  382. "Env":null,
  383. "Cmd": ["/bin/bash"]
  384. ,"Dns":null,
  385. "Image":"base",
  386. "Volumes":null,
  387. "VolumesFrom":""
  388. }
  389. }
  390. :statuscode 200: no error
  391. :statuscode 404: no such image
  392. :statuscode 500: server error
  393. Get the history of an image
  394. ***************************
  395. .. http:get:: /images/(name)
  396. Return the history of the image ``name``
  397. **Example request**:
  398. .. sourcecode:: http
  399. GET /images/base/history HTTP/1.1
  400. **Example response**:
  401. .. sourcecode:: http
  402. HTTP/1.1 200 OK
  403. [
  404. {
  405. "Id":"b750fe79269d",
  406. "Created":1364102658,
  407. "CreatedBy":"/bin/bash"
  408. },
  409. {
  410. "Id":"27cf78414709",
  411. "Created":1364068391,
  412. "CreatedBy":""
  413. }
  414. ]
  415. :statuscode 200: no error
  416. :statuscode 404: no such image
  417. :statuscode 500: server error
  418. Push an image on the registry
  419. *****************************
  420. .. http:post:: /images/(name)/push
  421. Push the image ``name`` on the registry
  422. **Example request**:
  423. .. sourcecode:: http
  424. POST /images/test/push HTTP/1.1
  425. **Example response**:
  426. .. sourcecode:: http
  427. HTTP/1.1 200 OK
  428. Content-Type: raw-stream-hijack
  429. {{ STREAM }}
  430. :statuscode 200: no error
  431. :statuscode 404: no such image
  432. :statuscode 500: server error
  433. Tag an image into a repository
  434. ******************************
  435. .. http:post:: /images/(name)/tag
  436. Tag the image ``name`` into a repository
  437. **Example request**:
  438. .. sourcecode:: http
  439. POST /images/test/tag?repo=myrepo&force=0 HTTP/1.1
  440. **Example response**:
  441. .. sourcecode:: http
  442. HTTP/1.1 200 OK
  443. :query repo: The repository to tag in
  444. :query force: 1 or 0, default 0
  445. :statuscode 200: no error
  446. :statuscode 404: no such image
  447. :statuscode 500: server error
  448. Remove an image
  449. ***************
  450. .. http:delete:: /images/(name)
  451. Remove the image ``name`` from the filesystem
  452. **Example request**:
  453. .. sourcecode:: http
  454. DELETE /images/test HTTP/1.1
  455. **Example response**:
  456. .. sourcecode:: http
  457. HTTP/1.1 200 OK
  458. :statuscode 200: no error
  459. :statuscode 404: no such image
  460. :statuscode 500: server error
  461. 2.3 Misc
  462. --------
  463. Get default username and email
  464. ******************************
  465. .. http:get:: /auth
  466. Get the default username and email
  467. **Example request**:
  468. .. sourcecode:: http
  469. GET /auth HTTP/1.1
  470. **Example response**:
  471. .. sourcecode:: http
  472. HTTP/1.1 200 OK
  473. {
  474. "username":"hannibal",
  475. "email":"hannibal@a-team.com"
  476. }
  477. :statuscode 200: no error
  478. :statuscode 500: server error
  479. Set auth configuration
  480. **********************
  481. .. http:post:: /auth
  482. Get the default username and email
  483. **Example request**:
  484. .. sourcecode:: http
  485. POST /auth HTTP/1.1
  486. {
  487. "username":"hannibal",
  488. "password:"xxxx",
  489. "email":"hannibal@a-team.com"
  490. }
  491. **Example response**:
  492. .. sourcecode:: http
  493. HTTP/1.1 200 OK
  494. :statuscode 200: no error
  495. :statuscode 500: server error
  496. Display system-wide information
  497. *******************************
  498. .. http:get:: /info
  499. Display system-wide information
  500. **Example request**:
  501. .. sourcecode:: http
  502. GET /info HTTP/1.1
  503. **Example response**:
  504. .. sourcecode:: http
  505. HTTP/1.1 200 OK
  506. {
  507. "Containers":11,
  508. "Version":"0.2.2",
  509. "Images":16,
  510. "Debug":false
  511. }
  512. :statuscode 200: no error
  513. :statuscode 500: server error
  514. Show the docker version information
  515. ***********************************
  516. .. http:get:: /version
  517. Show the docker version information
  518. **Example request**:
  519. .. sourcecode:: http
  520. GET /version HTTP/1.1
  521. **Example response**:
  522. .. sourcecode:: http
  523. HTTP/1.1 200 OK
  524. {
  525. "Version":"0.2.2",
  526. "GitCommit":"5a2a5cc+CHANGES",
  527. "MemoryLimit":true,
  528. "SwapLimit":false
  529. }
  530. :statuscode 200: no error
  531. :statuscode 500: server error
  532. Create a new image from a container's changes
  533. *********************************************
  534. .. http:post:: /commit
  535. Create a new image from a container's changes
  536. **Example request**:
  537. .. sourcecode:: http
  538. POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1
  539. **Example response**:
  540. .. sourcecode:: http
  541. HTTP/1.1 200 OK
  542. Content-Type: raw-stream-hijack
  543. {{ STREAM }}
  544. :query container: source container
  545. :query repo: repository
  546. :query tag: tag
  547. :query m: commit message
  548. :query author: author (eg. "John Hannibal Smith <hannibal@a-team.com>")
  549. :query run: config automatically applied when the image is run. (ex: {"Cmd": ["cat", "/world"], "PortSpecs":["22"]})
  550. :statuscode 200: no error
  551. :statuscode 404: no such container
  552. :statuscode 500: server error
  553. 3. Going further
  554. ================
  555. 3.1 Inside 'docker run'
  556. -----------------------
  557. Here are the steps of 'docker run' :
  558. * Create the container
  559. * If the status code is 404, it means the image doesn't exists:
  560. * Try to pull it
  561. * Then retry to create the container
  562. * Start the container
  563. * If you are not in detached mode:
  564. * Attach to the container, using logs=1 (to have stdout and stderr from the container's start) and stream=1
  565. * Call /wait to get the exit code and exit with it
  566. 3.2 Hijacking
  567. -------------
  568. In this first version of the API, some of the endpoints, like /attach, /pull or /push uses hijacking to transport stdin,
  569. stdout and stderr on the same socket. This might change in the future.