api.rst 18 KB

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