docker_remote_api_v1.6.rst 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. :title: Remote API v1.6
  2. :description: API Documentation for Docker
  3. :keywords: API, Docker, rcli, REST, documentation
  4. :orphan:
  5. ======================
  6. Docker Remote API v1.6
  7. ======================
  8. .. contents:: Table of Contents
  9. 1. Brief introduction
  10. =====================
  11. - The Remote API has replaced rcli
  12. - The daemon listens on ``unix:///var/run/docker.sock``, but you can
  13. :ref:`bind_docker`.
  14. - The API tends to be REST, but for some complex commands, like
  15. ``attach`` or ``pull``, the HTTP connection is hijacked to transport
  16. ``stdout, stdin`` and ``stderr``
  17. 2. Endpoints
  18. ============
  19. 2.1 Containers
  20. --------------
  21. List containers
  22. ***************
  23. .. http:get:: /containers/json
  24. List containers
  25. **Example request**:
  26. .. sourcecode:: http
  27. GET /containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1
  28. **Example response**:
  29. .. sourcecode:: http
  30. HTTP/1.1 200 OK
  31. Content-Type: application/json
  32. [
  33. {
  34. "Id": "8dfafdbc3a40",
  35. "Image": "base:latest",
  36. "Command": "echo 1",
  37. "Created": 1367854155,
  38. "Status": "Exit 0",
  39. "Ports":[{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}],
  40. "SizeRw":12288,
  41. "SizeRootFs":0
  42. },
  43. {
  44. "Id": "9cd87474be90",
  45. "Image": "base:latest",
  46. "Command": "echo 222222",
  47. "Created": 1367854155,
  48. "Status": "Exit 0",
  49. "Ports":[],
  50. "SizeRw":12288,
  51. "SizeRootFs":0
  52. },
  53. {
  54. "Id": "3176a2479c92",
  55. "Image": "base:latest",
  56. "Command": "echo 3333333333333333",
  57. "Created": 1367854154,
  58. "Status": "Exit 0",
  59. "Ports":[],
  60. "SizeRw":12288,
  61. "SizeRootFs":0
  62. },
  63. {
  64. "Id": "4cb07b47f9fb",
  65. "Image": "base:latest",
  66. "Command": "echo 444444444444444444444444444444444",
  67. "Created": 1367854152,
  68. "Status": "Exit 0",
  69. "Ports":[],
  70. "SizeRw":12288,
  71. "SizeRootFs":0
  72. }
  73. ]
  74. :query all: 1/True/true or 0/False/false, Show all containers. Only running containers are shown by default
  75. :query limit: Show ``limit`` last created containers, include non-running ones.
  76. :query since: Show only containers created since Id, include non-running ones.
  77. :query before: Show only containers created before Id, include non-running ones.
  78. :query size: 1/True/true or 0/False/false, Show the containers sizes
  79. :statuscode 200: no error
  80. :statuscode 400: bad parameter
  81. :statuscode 500: server error
  82. Create a container
  83. ******************
  84. .. http:post:: /containers/create
  85. Create a container
  86. **Example request**:
  87. .. sourcecode:: http
  88. POST /containers/create HTTP/1.1
  89. Content-Type: application/json
  90. {
  91. "Hostname":"",
  92. "User":"",
  93. "Memory":0,
  94. "MemorySwap":0,
  95. "AttachStdin":false,
  96. "AttachStdout":true,
  97. "AttachStderr":true,
  98. "PortSpecs":null,
  99. "Privileged": false,
  100. "Tty":false,
  101. "OpenStdin":false,
  102. "StdinOnce":false,
  103. "Env":null,
  104. "Cmd":[
  105. "date"
  106. ],
  107. "Dns":null,
  108. "Image":"base",
  109. "Volumes":{},
  110. "VolumesFrom":"",
  111. "WorkingDir":""
  112. }
  113. **Example response**:
  114. .. sourcecode:: http
  115. HTTP/1.1 201 OK
  116. Content-Type: application/json
  117. {
  118. "Id":"e90e34656806"
  119. "Warnings":[]
  120. }
  121. :jsonparam config: the container's configuration
  122. :query name: container name to use
  123. :statuscode 201: no error
  124. :statuscode 404: no such container
  125. :statuscode 406: impossible to attach (container not running)
  126. :statuscode 500: server error
  127. **More Complex Example request, in 2 steps.**
  128. **First, use create to expose a Private Port, which can be bound back to a Public Port at startup**:
  129. .. sourcecode:: http
  130. POST /containers/create HTTP/1.1
  131. Content-Type: application/json
  132. {
  133. "Cmd":[
  134. "/usr/sbin/sshd","-D"
  135. ],
  136. "Image":"image-with-sshd",
  137. "ExposedPorts":{"22/tcp":{}}
  138. }
  139. **Example response**:
  140. .. sourcecode:: http
  141. HTTP/1.1 201 OK
  142. Content-Type: application/json
  143. {
  144. "Id":"e90e34656806"
  145. "Warnings":[]
  146. }
  147. ** Second, start (using the ID returned above) the image we just created, mapping the ssh port 22 to something on the host**:
  148. .. sourcecode:: http
  149. POST /containers/e90e34656806/start HTTP/1.1
  150. Content-Type: application/json
  151. {
  152. "PortBindings": { "22/tcp": [{ "HostPort": "11022" }]}
  153. }
  154. **Example response**:
  155. .. sourcecode:: http
  156. HTTP/1.1 204 No Content
  157. Content-Type: text/plain; charset=utf-8
  158. Content-Length: 0
  159. ** Now you can ssh into your new container on port 11022.**
  160. Inspect a container
  161. *******************
  162. .. http:get:: /containers/(id)/json
  163. Return low-level information on the container ``id``
  164. **Example request**:
  165. .. sourcecode:: http
  166. GET /containers/4fa6e0f0c678/json HTTP/1.1
  167. **Example response**:
  168. .. sourcecode:: http
  169. HTTP/1.1 200 OK
  170. Content-Type: application/json
  171. {
  172. "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
  173. "Created": "2013-05-07T14:51:42.041847+02:00",
  174. "Path": "date",
  175. "Args": [],
  176. "Config": {
  177. "Hostname": "4fa6e0f0c678",
  178. "User": "",
  179. "Memory": 0,
  180. "MemorySwap": 0,
  181. "AttachStdin": false,
  182. "AttachStdout": true,
  183. "AttachStderr": true,
  184. "PortSpecs": null,
  185. "Tty": false,
  186. "OpenStdin": false,
  187. "StdinOnce": false,
  188. "Env": null,
  189. "Cmd": [
  190. "date"
  191. ],
  192. "Dns": null,
  193. "Image": "base",
  194. "Volumes": {},
  195. "VolumesFrom": "",
  196. "WorkingDir":""
  197. },
  198. "State": {
  199. "Running": false,
  200. "Pid": 0,
  201. "ExitCode": 0,
  202. "StartedAt": "2013-05-07T14:51:42.087658+02:01360",
  203. "Ghost": false
  204. },
  205. "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  206. "NetworkSettings": {
  207. "IpAddress": "",
  208. "IpPrefixLen": 0,
  209. "Gateway": "",
  210. "Bridge": "",
  211. "PortMapping": null
  212. },
  213. "SysInitPath": "/home/kitty/go/src/github.com/dotcloud/docker/bin/docker",
  214. "ResolvConfPath": "/etc/resolv.conf",
  215. "Volumes": {}
  216. }
  217. :statuscode 200: no error
  218. :statuscode 404: no such container
  219. :statuscode 500: server error
  220. List processes running inside a container
  221. *****************************************
  222. .. http:get:: /containers/(id)/top
  223. List processes running inside the container ``id``
  224. **Example request**:
  225. .. sourcecode:: http
  226. GET /containers/4fa6e0f0c678/top HTTP/1.1
  227. **Example response**:
  228. .. sourcecode:: http
  229. HTTP/1.1 200 OK
  230. Content-Type: application/json
  231. {
  232. "Titles":[
  233. "USER",
  234. "PID",
  235. "%CPU",
  236. "%MEM",
  237. "VSZ",
  238. "RSS",
  239. "TTY",
  240. "STAT",
  241. "START",
  242. "TIME",
  243. "COMMAND"
  244. ],
  245. "Processes":[
  246. ["root","20147","0.0","0.1","18060","1864","pts/4","S","10:06","0:00","bash"],
  247. ["root","20271","0.0","0.0","4312","352","pts/4","S+","10:07","0:00","sleep","10"]
  248. ]
  249. }
  250. :query ps_args: ps arguments to use (eg. aux)
  251. :statuscode 200: no error
  252. :statuscode 404: no such container
  253. :statuscode 500: server error
  254. Inspect changes on a container's filesystem
  255. *******************************************
  256. .. http:get:: /containers/(id)/changes
  257. Inspect changes on container ``id`` 's filesystem
  258. **Example request**:
  259. .. sourcecode:: http
  260. GET /containers/4fa6e0f0c678/changes HTTP/1.1
  261. **Example response**:
  262. .. sourcecode:: http
  263. HTTP/1.1 200 OK
  264. Content-Type: application/json
  265. [
  266. {
  267. "Path":"/dev",
  268. "Kind":0
  269. },
  270. {
  271. "Path":"/dev/kmsg",
  272. "Kind":1
  273. },
  274. {
  275. "Path":"/test",
  276. "Kind":1
  277. }
  278. ]
  279. :statuscode 200: no error
  280. :statuscode 404: no such container
  281. :statuscode 500: server error
  282. Export a container
  283. ******************
  284. .. http:get:: /containers/(id)/export
  285. Export the contents of container ``id``
  286. **Example request**:
  287. .. sourcecode:: http
  288. GET /containers/4fa6e0f0c678/export HTTP/1.1
  289. **Example response**:
  290. .. sourcecode:: http
  291. HTTP/1.1 200 OK
  292. Content-Type: application/octet-stream
  293. {{ STREAM }}
  294. :statuscode 200: no error
  295. :statuscode 404: no such container
  296. :statuscode 500: server error
  297. Start a container
  298. *****************
  299. .. http:post:: /containers/(id)/start
  300. Start the container ``id``
  301. **Example request**:
  302. .. sourcecode:: http
  303. POST /containers/(id)/start HTTP/1.1
  304. Content-Type: application/json
  305. {
  306. "Binds":["/tmp:/tmp"],
  307. "LxcConf":{"lxc.utsname":"docker"}
  308. }
  309. **Example response**:
  310. .. sourcecode:: http
  311. HTTP/1.1 204 No Content
  312. Content-Type: text/plain
  313. :jsonparam hostConfig: the container's host configuration (optional)
  314. :statuscode 204: no error
  315. :statuscode 404: no such container
  316. :statuscode 500: server error
  317. Stop a container
  318. ****************
  319. .. http:post:: /containers/(id)/stop
  320. Stop the container ``id``
  321. **Example request**:
  322. .. sourcecode:: http
  323. POST /containers/e90e34656806/stop?t=5 HTTP/1.1
  324. **Example response**:
  325. .. sourcecode:: http
  326. HTTP/1.1 204 OK
  327. :query t: number of seconds to wait before killing the container
  328. :statuscode 204: no error
  329. :statuscode 404: no such container
  330. :statuscode 500: server error
  331. Restart a container
  332. *******************
  333. .. http:post:: /containers/(id)/restart
  334. Restart the container ``id``
  335. **Example request**:
  336. .. sourcecode:: http
  337. POST /containers/e90e34656806/restart?t=5 HTTP/1.1
  338. **Example response**:
  339. .. sourcecode:: http
  340. HTTP/1.1 204 OK
  341. :query t: number of seconds to wait before killing the container
  342. :statuscode 204: no error
  343. :statuscode 404: no such container
  344. :statuscode 500: server error
  345. Kill a container
  346. ****************
  347. .. http:post:: /containers/(id)/kill
  348. Kill the container ``id``
  349. **Example request**:
  350. .. sourcecode:: http
  351. POST /containers/e90e34656806/kill HTTP/1.1
  352. **Example response**:
  353. .. sourcecode:: http
  354. HTTP/1.1 204 OK
  355. :query signal: Signal to send to the container (integer). When not set, SIGKILL is assumed and the call will waits for the container to exit.
  356. :statuscode 204: no error
  357. :statuscode 404: no such container
  358. :statuscode 500: server error
  359. Attach to a container
  360. *********************
  361. .. http:post:: /containers/(id)/attach
  362. Attach to the container ``id``
  363. **Example request**:
  364. .. sourcecode:: http
  365. POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1
  366. **Example response**:
  367. .. sourcecode:: http
  368. HTTP/1.1 200 OK
  369. Content-Type: application/vnd.docker.raw-stream
  370. {{ STREAM }}
  371. :query logs: 1/True/true or 0/False/false, return logs. Default false
  372. :query stream: 1/True/true or 0/False/false, return stream. Default false
  373. :query stdin: 1/True/true or 0/False/false, if stream=true, attach to stdin. Default false
  374. :query stdout: 1/True/true or 0/False/false, if logs=true, return stdout log, if stream=true, attach to stdout. Default false
  375. :query stderr: 1/True/true or 0/False/false, if logs=true, return stderr log, if stream=true, attach to stderr. Default false
  376. :statuscode 200: no error
  377. :statuscode 400: bad parameter
  378. :statuscode 404: no such container
  379. :statuscode 500: server error
  380. **Stream details**:
  381. When using the TTY setting is enabled in
  382. :http:post:`/containers/create`, the stream is the raw data
  383. from the process PTY and client's stdin. When the TTY is
  384. disabled, then the stream is multiplexed to separate stdout
  385. and stderr.
  386. The format is a **Header** and a **Payload** (frame).
  387. **HEADER**
  388. The header will contain the information on which stream write
  389. the stream (stdout or stderr). It also contain the size of
  390. the associated frame encoded on the last 4 bytes (uint32).
  391. It is encoded on the first 8 bytes like this::
  392. header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
  393. ``STREAM_TYPE`` can be:
  394. - 0: stdin (will be writen on stdout)
  395. - 1: stdout
  396. - 2: stderr
  397. ``SIZE1, SIZE2, SIZE3, SIZE4`` are the 4 bytes of the uint32 size encoded as big endian.
  398. **PAYLOAD**
  399. The payload is the raw stream.
  400. **IMPLEMENTATION**
  401. The simplest way to implement the Attach protocol is the following:
  402. 1) Read 8 bytes
  403. 2) chose stdout or stderr depending on the first byte
  404. 3) Extract the frame size from the last 4 byets
  405. 4) Read the extracted size and output it on the correct output
  406. 5) Goto 1)
  407. Wait a container
  408. ****************
  409. .. http:post:: /containers/(id)/wait
  410. Block until container ``id`` stops, then returns the exit code
  411. **Example request**:
  412. .. sourcecode:: http
  413. POST /containers/16253994b7c4/wait HTTP/1.1
  414. **Example response**:
  415. .. sourcecode:: http
  416. HTTP/1.1 200 OK
  417. Content-Type: application/json
  418. {"StatusCode":0}
  419. :statuscode 200: no error
  420. :statuscode 404: no such container
  421. :statuscode 500: server error
  422. Remove a container
  423. *******************
  424. .. http:delete:: /containers/(id)
  425. Remove the container ``id`` from the filesystem
  426. **Example request**:
  427. .. sourcecode:: http
  428. DELETE /containers/16253994b7c4?v=1 HTTP/1.1
  429. **Example response**:
  430. .. sourcecode:: http
  431. HTTP/1.1 204 OK
  432. :query v: 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false
  433. :statuscode 204: no error
  434. :statuscode 400: bad parameter
  435. :statuscode 404: no such container
  436. :statuscode 500: server error
  437. Copy files or folders from a container
  438. **************************************
  439. .. http:post:: /containers/(id)/copy
  440. Copy files or folders of container ``id``
  441. **Example request**:
  442. .. sourcecode:: http
  443. POST /containers/4fa6e0f0c678/copy HTTP/1.1
  444. Content-Type: application/json
  445. {
  446. "Resource":"test.txt"
  447. }
  448. **Example response**:
  449. .. sourcecode:: http
  450. HTTP/1.1 200 OK
  451. Content-Type: application/octet-stream
  452. {{ STREAM }}
  453. :statuscode 200: no error
  454. :statuscode 404: no such container
  455. :statuscode 500: server error
  456. 2.2 Images
  457. ----------
  458. List Images
  459. ***********
  460. .. http:get:: /images/(format)
  461. List images ``format`` could be json or viz (json default)
  462. **Example request**:
  463. .. sourcecode:: http
  464. GET /images/json?all=0 HTTP/1.1
  465. **Example response**:
  466. .. sourcecode:: http
  467. HTTP/1.1 200 OK
  468. Content-Type: application/json
  469. [
  470. {
  471. "Repository":"base",
  472. "Tag":"ubuntu-12.10",
  473. "Id":"b750fe79269d",
  474. "Created":1364102658,
  475. "Size":24653,
  476. "VirtualSize":180116135
  477. },
  478. {
  479. "Repository":"base",
  480. "Tag":"ubuntu-quantal",
  481. "Id":"b750fe79269d",
  482. "Created":1364102658,
  483. "Size":24653,
  484. "VirtualSize":180116135
  485. }
  486. ]
  487. **Example request**:
  488. .. sourcecode:: http
  489. GET /images/viz HTTP/1.1
  490. **Example response**:
  491. .. sourcecode:: http
  492. HTTP/1.1 200 OK
  493. Content-Type: text/plain
  494. digraph docker {
  495. "d82cbacda43a" -> "074be284591f"
  496. "1496068ca813" -> "08306dc45919"
  497. "08306dc45919" -> "0e7893146ac2"
  498. "b750fe79269d" -> "1496068ca813"
  499. base -> "27cf78414709" [style=invis]
  500. "f71189fff3de" -> "9a33b36209ed"
  501. "27cf78414709" -> "b750fe79269d"
  502. "0e7893146ac2" -> "d6434d954665"
  503. "d6434d954665" -> "d82cbacda43a"
  504. base -> "e9aa60c60128" [style=invis]
  505. "074be284591f" -> "f71189fff3de"
  506. "b750fe79269d" [label="b750fe79269d\nbase",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
  507. "e9aa60c60128" [label="e9aa60c60128\nbase2",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
  508. "9a33b36209ed" [label="9a33b36209ed\ntest",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
  509. base [style=invisible]
  510. }
  511. :query all: 1/True/true or 0/False/false, Show all containers. Only running containers are shown by default
  512. :statuscode 200: no error
  513. :statuscode 400: bad parameter
  514. :statuscode 500: server error
  515. Create an image
  516. ***************
  517. .. http:post:: /images/create
  518. Create an image, either by pull it from the registry or by importing it
  519. **Example request**:
  520. .. sourcecode:: http
  521. POST /images/create?fromImage=base HTTP/1.1
  522. **Example response**:
  523. .. sourcecode:: http
  524. HTTP/1.1 200 OK
  525. Content-Type: application/json
  526. {"status":"Pulling..."}
  527. {"status":"Pulling", "progress":"1/? (n/a)"}
  528. {"error":"Invalid..."}
  529. ...
  530. When using this endpoint to pull an image from the registry,
  531. the ``X-Registry-Auth`` header can be used to include a
  532. base64-encoded AuthConfig object.
  533. :query fromImage: name of the image to pull
  534. :query fromSrc: source to import, - means stdin
  535. :query repo: repository
  536. :query tag: tag
  537. :query registry: the registry to pull from
  538. :statuscode 200: no error
  539. :statuscode 500: server error
  540. Insert a file in an image
  541. *************************
  542. .. http:post:: /images/(name)/insert
  543. Insert a file from ``url`` in the image ``name`` at ``path``
  544. **Example request**:
  545. .. sourcecode:: http
  546. POST /images/test/insert?path=/usr&url=myurl HTTP/1.1
  547. **Example response**:
  548. .. sourcecode:: http
  549. HTTP/1.1 200 OK
  550. Content-Type: application/json
  551. {"status":"Inserting..."}
  552. {"status":"Inserting", "progress":"1/? (n/a)"}
  553. {"error":"Invalid..."}
  554. ...
  555. :statuscode 200: no error
  556. :statuscode 500: server error
  557. Inspect an image
  558. ****************
  559. .. http:get:: /images/(name)/json
  560. Return low-level information on the image ``name``
  561. **Example request**:
  562. .. sourcecode:: http
  563. GET /images/base/json HTTP/1.1
  564. **Example response**:
  565. .. sourcecode:: http
  566. HTTP/1.1 200 OK
  567. Content-Type: application/json
  568. {
  569. "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  570. "parent":"27cf784147099545",
  571. "created":"2013-03-23T22:24:18.818426-07:00",
  572. "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
  573. "container_config":
  574. {
  575. "Hostname":"",
  576. "User":"",
  577. "Memory":0,
  578. "MemorySwap":0,
  579. "AttachStdin":false,
  580. "AttachStdout":false,
  581. "AttachStderr":false,
  582. "PortSpecs":null,
  583. "Tty":true,
  584. "OpenStdin":true,
  585. "StdinOnce":false,
  586. "Env":null,
  587. "Cmd": ["/bin/bash"]
  588. ,"Dns":null,
  589. "Image":"base",
  590. "Volumes":null,
  591. "VolumesFrom":"",
  592. "WorkingDir":""
  593. },
  594. "Size": 6824592
  595. }
  596. :statuscode 200: no error
  597. :statuscode 404: no such image
  598. :statuscode 500: server error
  599. Get the history of an image
  600. ***************************
  601. .. http:get:: /images/(name)/history
  602. Return the history of the image ``name``
  603. **Example request**:
  604. .. sourcecode:: http
  605. GET /images/base/history HTTP/1.1
  606. **Example response**:
  607. .. sourcecode:: http
  608. HTTP/1.1 200 OK
  609. Content-Type: application/json
  610. [
  611. {
  612. "Id":"b750fe79269d",
  613. "Created":1364102658,
  614. "CreatedBy":"/bin/bash"
  615. },
  616. {
  617. "Id":"27cf78414709",
  618. "Created":1364068391,
  619. "CreatedBy":""
  620. }
  621. ]
  622. :statuscode 200: no error
  623. :statuscode 404: no such image
  624. :statuscode 500: server error
  625. Push an image on the registry
  626. *****************************
  627. .. http:post:: /images/(name)/push
  628. Push the image ``name`` on the registry
  629. **Example request**:
  630. .. sourcecode:: http
  631. POST /images/test/push HTTP/1.1
  632. **Example response**:
  633. .. sourcecode:: http
  634. HTTP/1.1 200 OK
  635. Content-Type: application/json
  636. {"status":"Pushing..."}
  637. {"status":"Pushing", "progress":"1/? (n/a)"}
  638. {"error":"Invalid..."}
  639. ...
  640. The ``X-Registry-Auth`` header can be used to include a
  641. base64-encoded AuthConfig object.
  642. :query registry: the registry you wan to push, optional
  643. :statuscode 200: no error
  644. :statuscode 404: no such image
  645. :statuscode 500: server error
  646. Tag an image into a repository
  647. ******************************
  648. .. http:post:: /images/(name)/tag
  649. Tag the image ``name`` into a repository
  650. **Example request**:
  651. .. sourcecode:: http
  652. POST /images/test/tag?repo=myrepo&force=0 HTTP/1.1
  653. **Example response**:
  654. .. sourcecode:: http
  655. HTTP/1.1 200 OK
  656. :query repo: The repository to tag in
  657. :query force: 1/True/true or 0/False/false, default false
  658. :statuscode 200: no error
  659. :statuscode 400: bad parameter
  660. :statuscode 404: no such image
  661. :statuscode 409: conflict
  662. :statuscode 500: server error
  663. Remove an image
  664. ***************
  665. .. http:delete:: /images/(name)
  666. Remove the image ``name`` from the filesystem
  667. **Example request**:
  668. .. sourcecode:: http
  669. DELETE /images/test HTTP/1.1
  670. **Example response**:
  671. .. sourcecode:: http
  672. HTTP/1.1 200 OK
  673. Content-type: application/json
  674. [
  675. {"Untagged":"3e2f21a89f"},
  676. {"Deleted":"3e2f21a89f"},
  677. {"Deleted":"53b4f83ac9"}
  678. ]
  679. :statuscode 200: no error
  680. :statuscode 404: no such image
  681. :statuscode 409: conflict
  682. :statuscode 500: server error
  683. Search images
  684. *************
  685. .. http:get:: /images/search
  686. Search for an image in the docker index
  687. **Example request**:
  688. .. sourcecode:: http
  689. GET /images/search?term=sshd HTTP/1.1
  690. **Example response**:
  691. .. sourcecode:: http
  692. HTTP/1.1 200 OK
  693. Content-Type: application/json
  694. [
  695. {
  696. "Name":"cespare/sshd",
  697. "Description":""
  698. },
  699. {
  700. "Name":"johnfuller/sshd",
  701. "Description":""
  702. },
  703. {
  704. "Name":"dhrp/mongodb-sshd",
  705. "Description":""
  706. }
  707. ]
  708. :query term: term to search
  709. :statuscode 200: no error
  710. :statuscode 500: server error
  711. 2.3 Misc
  712. --------
  713. Build an image from Dockerfile via stdin
  714. ****************************************
  715. .. http:post:: /build
  716. Build an image from Dockerfile via stdin
  717. **Example request**:
  718. .. sourcecode:: http
  719. POST /build HTTP/1.1
  720. {{ STREAM }}
  721. **Example response**:
  722. .. sourcecode:: http
  723. HTTP/1.1 200 OK
  724. {{ STREAM }}
  725. The stream must be a tar archive compressed with one of the following algorithms:
  726. identity (no compression), gzip, bzip2, xz. The archive must include a file called
  727. `Dockerfile` at its root. It may include any number of other files, which will be
  728. accessible in the build context (See the ADD build command).
  729. The Content-type header should be set to "application/tar".
  730. :query t: repository name (and optionally a tag) to be applied to the resulting image in case of success
  731. :query q: suppress verbose build output
  732. :query nocache: do not use the cache when building the image
  733. :statuscode 200: no error
  734. :statuscode 500: server error
  735. Check auth configuration
  736. ************************
  737. .. http:post:: /auth
  738. Get the default username and email
  739. **Example request**:
  740. .. sourcecode:: http
  741. POST /auth HTTP/1.1
  742. Content-Type: application/json
  743. {
  744. "username":"hannibal",
  745. "password:"xxxx",
  746. "email":"hannibal@a-team.com",
  747. "serveraddress":"https://index.docker.io/v1/"
  748. }
  749. **Example response**:
  750. .. sourcecode:: http
  751. HTTP/1.1 200 OK
  752. :statuscode 200: no error
  753. :statuscode 204: no error
  754. :statuscode 500: server error
  755. Display system-wide information
  756. *******************************
  757. .. http:get:: /info
  758. Display system-wide information
  759. **Example request**:
  760. .. sourcecode:: http
  761. GET /info HTTP/1.1
  762. **Example response**:
  763. .. sourcecode:: http
  764. HTTP/1.1 200 OK
  765. Content-Type: application/json
  766. {
  767. "Containers":11,
  768. "Images":16,
  769. "Debug":false,
  770. "NFd": 11,
  771. "NGoroutines":21,
  772. "MemoryLimit":true,
  773. "SwapLimit":false,
  774. "IPv4Forwarding":true
  775. }
  776. :statuscode 200: no error
  777. :statuscode 500: server error
  778. Show the docker version information
  779. ***********************************
  780. .. http:get:: /version
  781. Show the docker version information
  782. **Example request**:
  783. .. sourcecode:: http
  784. GET /version HTTP/1.1
  785. **Example response**:
  786. .. sourcecode:: http
  787. HTTP/1.1 200 OK
  788. Content-Type: application/json
  789. {
  790. "Version":"0.2.2",
  791. "GitCommit":"5a2a5cc+CHANGES",
  792. "GoVersion":"go1.0.3"
  793. }
  794. :statuscode 200: no error
  795. :statuscode 500: server error
  796. Create a new image from a container's changes
  797. *********************************************
  798. .. http:post:: /commit
  799. Create a new image from a container's changes
  800. **Example request**:
  801. .. sourcecode:: http
  802. POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1
  803. Content-Type: application/json
  804. {
  805. "Cmd": ["cat", "/world"],
  806. "PortSpecs":["22"]
  807. }
  808. **Example response**:
  809. .. sourcecode:: http
  810. HTTP/1.1 201 OK
  811. Content-Type: application/vnd.docker.raw-stream
  812. {"Id":"596069db4bf5"}
  813. :query container: source container
  814. :query repo: repository
  815. :query tag: tag
  816. :query m: commit message
  817. :query author: author (eg. "John Hannibal Smith <hannibal@a-team.com>")
  818. :statuscode 201: no error
  819. :statuscode 404: no such container
  820. :statuscode 500: server error
  821. Monitor Docker's events
  822. ***********************
  823. .. http:get:: /events
  824. Get events from docker, either in real time via streaming, or via polling (using `since`)
  825. **Example request**:
  826. .. sourcecode:: http
  827. POST /events?since=1374067924
  828. **Example response**:
  829. .. sourcecode:: http
  830. HTTP/1.1 200 OK
  831. Content-Type: application/json
  832. {"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
  833. {"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
  834. {"status":"stop","id":"dfdf82bd3881","from":"base:latest","time":1374067966}
  835. {"status":"destroy","id":"dfdf82bd3881","from":"base:latest","time":1374067970}
  836. :query since: timestamp used for polling
  837. :statuscode 200: no error
  838. :statuscode 500: server error
  839. 3. Going further
  840. ================
  841. 3.1 Inside 'docker run'
  842. -----------------------
  843. Here are the steps of 'docker run' :
  844. * Create the container
  845. * If the status code is 404, it means the image doesn't exists:
  846. * Try to pull it
  847. * Then retry to create the container
  848. * Start the container
  849. * If you are not in detached mode:
  850. * Attach to the container, using logs=1 (to have stdout and stderr from the container's start) and stream=1
  851. * If in detached mode or only stdin is attached:
  852. * Display the container's id
  853. 3.2 Hijacking
  854. -------------
  855. In this version of the API, /attach, uses hijacking to transport stdin, stdout and stderr on the same socket. This might change in the future.
  856. 3.3 CORS Requests
  857. -----------------
  858. To enable cross origin requests to the remote api add the flag "-api-enable-cors" when running docker in daemon mode.
  859. .. code-block:: bash
  860. docker -d -H="192.168.1.9:4243" -api-enable-cors