docker_remote_api_v1.8.rst 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. :title: Remote API v1.8
  2. :description: API Documentation for Docker
  3. :keywords: API, Docker, rcli, REST, documentation
  4. :orphan:
  5. ======================
  6. Docker Remote API v1.8
  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. "CpuShares":0,
  96. "AttachStdin":false,
  97. "AttachStdout":true,
  98. "AttachStderr":true,
  99. "PortSpecs":null,
  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. "/tmp": {}
  111. },
  112. "VolumesFrom":"",
  113. "WorkingDir":"",
  114. "ExposedPorts":{
  115. "22/tcp": {}
  116. }
  117. }
  118. **Example response**:
  119. .. sourcecode:: http
  120. HTTP/1.1 201 OK
  121. Content-Type: application/json
  122. {
  123. "Id":"e90e34656806"
  124. "Warnings":[]
  125. }
  126. :jsonparam Hostname: Container host name
  127. :jsonparam User: Username or UID
  128. :jsonparam Memory: Memory Limit in bytes
  129. :jsonparam CpuShares: CPU shares (relative weight)
  130. :jsonparam AttachStdin: 1/True/true or 0/False/false, attach to standard input. Default false
  131. :jsonparam AttachStdout: 1/True/true or 0/False/false, attach to standard output. Default false
  132. :jsonparam AttachStderr: 1/True/true or 0/False/false, attach to standard error. Default false
  133. :jsonparam Tty: 1/True/true or 0/False/false, allocate a pseudo-tty. Default false
  134. :jsonparam OpenStdin: 1/True/true or 0/False/false, keep stdin open even if not attached. Default false
  135. :query name: Assign the specified name to the container. Must match ``/?[a-zA-Z0-9_-]+``.
  136. :statuscode 201: no error
  137. :statuscode 404: no such container
  138. :statuscode 406: impossible to attach (container not running)
  139. :statuscode 500: server error
  140. Inspect a container
  141. *******************
  142. .. http:get:: /containers/(id)/json
  143. Return low-level information on the container ``id``
  144. **Example request**:
  145. .. sourcecode:: http
  146. GET /containers/4fa6e0f0c678/json HTTP/1.1
  147. **Example response**:
  148. .. sourcecode:: http
  149. HTTP/1.1 200 OK
  150. Content-Type: application/json
  151. {
  152. "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
  153. "Created": "2013-05-07T14:51:42.041847+02:00",
  154. "Path": "date",
  155. "Args": [],
  156. "Config": {
  157. "Hostname": "4fa6e0f0c678",
  158. "User": "",
  159. "Memory": 0,
  160. "MemorySwap": 0,
  161. "AttachStdin": false,
  162. "AttachStdout": true,
  163. "AttachStderr": true,
  164. "PortSpecs": null,
  165. "Tty": false,
  166. "OpenStdin": false,
  167. "StdinOnce": false,
  168. "Env": null,
  169. "Cmd": [
  170. "date"
  171. ],
  172. "Dns": null,
  173. "Image": "base",
  174. "Volumes": {},
  175. "VolumesFrom": "",
  176. "WorkingDir":""
  177. },
  178. "State": {
  179. "Running": false,
  180. "Pid": 0,
  181. "ExitCode": 0,
  182. "StartedAt": "2013-05-07T14:51:42.087658+02:01360",
  183. "Ghost": false
  184. },
  185. "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  186. "NetworkSettings": {
  187. "IpAddress": "",
  188. "IpPrefixLen": 0,
  189. "Gateway": "",
  190. "Bridge": "",
  191. "PortMapping": null
  192. },
  193. "SysInitPath": "/home/kitty/go/src/github.com/dotcloud/docker/bin/docker",
  194. "ResolvConfPath": "/etc/resolv.conf",
  195. "Volumes": {},
  196. "HostConfig": {
  197. "Binds": null,
  198. "ContainerIDFile": "",
  199. "LxcConf": [],
  200. "Privileged": false,
  201. "PortBindings": {
  202. "80/tcp": [
  203. {
  204. "HostIp": "0.0.0.0",
  205. "HostPort": "49153"
  206. }
  207. ]
  208. },
  209. "Links": null,
  210. "PublishAllPorts": false
  211. }
  212. }
  213. :statuscode 200: no error
  214. :statuscode 404: no such container
  215. :statuscode 500: server error
  216. List processes running inside a container
  217. *****************************************
  218. .. http:get:: /containers/(id)/top
  219. List processes running inside the container ``id``
  220. **Example request**:
  221. .. sourcecode:: http
  222. GET /containers/4fa6e0f0c678/top HTTP/1.1
  223. **Example response**:
  224. .. sourcecode:: http
  225. HTTP/1.1 200 OK
  226. Content-Type: application/json
  227. {
  228. "Titles":[
  229. "USER",
  230. "PID",
  231. "%CPU",
  232. "%MEM",
  233. "VSZ",
  234. "RSS",
  235. "TTY",
  236. "STAT",
  237. "START",
  238. "TIME",
  239. "COMMAND"
  240. ],
  241. "Processes":[
  242. ["root","20147","0.0","0.1","18060","1864","pts/4","S","10:06","0:00","bash"],
  243. ["root","20271","0.0","0.0","4312","352","pts/4","S+","10:07","0:00","sleep","10"]
  244. ]
  245. }
  246. :query ps_args: ps arguments to use (eg. aux)
  247. :statuscode 200: no error
  248. :statuscode 404: no such container
  249. :statuscode 500: server error
  250. Inspect changes on a container's filesystem
  251. *******************************************
  252. .. http:get:: /containers/(id)/changes
  253. Inspect changes on container ``id`` 's filesystem
  254. **Example request**:
  255. .. sourcecode:: http
  256. GET /containers/4fa6e0f0c678/changes HTTP/1.1
  257. **Example response**:
  258. .. sourcecode:: http
  259. HTTP/1.1 200 OK
  260. Content-Type: application/json
  261. [
  262. {
  263. "Path":"/dev",
  264. "Kind":0
  265. },
  266. {
  267. "Path":"/dev/kmsg",
  268. "Kind":1
  269. },
  270. {
  271. "Path":"/test",
  272. "Kind":1
  273. }
  274. ]
  275. :statuscode 200: no error
  276. :statuscode 404: no such container
  277. :statuscode 500: server error
  278. Export a container
  279. ******************
  280. .. http:get:: /containers/(id)/export
  281. Export the contents of container ``id``
  282. **Example request**:
  283. .. sourcecode:: http
  284. GET /containers/4fa6e0f0c678/export HTTP/1.1
  285. **Example response**:
  286. .. sourcecode:: http
  287. HTTP/1.1 200 OK
  288. Content-Type: application/octet-stream
  289. {{ STREAM }}
  290. :statuscode 200: no error
  291. :statuscode 404: no such container
  292. :statuscode 500: server error
  293. Start a container
  294. *****************
  295. .. http:post:: /containers/(id)/start
  296. Start the container ``id``
  297. **Example request**:
  298. .. sourcecode:: http
  299. POST /containers/(id)/start HTTP/1.1
  300. Content-Type: application/json
  301. {
  302. "Binds":["/tmp:/tmp"],
  303. "LxcConf":{"lxc.utsname":"docker"},
  304. "PortBindings":{ "22/tcp": [{ "HostPort": "11022" }] },
  305. "PublishAllPorts":false,
  306. "Privileged":false
  307. }
  308. **Example response**:
  309. .. sourcecode:: http
  310. HTTP/1.1 204 No Content
  311. Content-Type: text/plain
  312. :jsonparam Binds: Create a bind mount to a directory or file with [host-path]:[container-path]:[rw|ro]. If a directory "container-path" is missing, then docker creates a new volume.
  313. :jsonparam LxcConf: Map of custom lxc options
  314. :jsonparam PortBindings: Expose ports from the container, optionally publishing them via the HostPort flag
  315. :jsonparam PublishAllPorts: 1/True/true or 0/False/false, publish all exposed ports to the host interfaces. Default false
  316. :jsonparam Privileged: 1/True/true or 0/False/false, give extended privileges to this container. Default false
  317. :statuscode 204: no error
  318. :statuscode 404: no such container
  319. :statuscode 500: server error
  320. Stop a container
  321. ****************
  322. .. http:post:: /containers/(id)/stop
  323. Stop the container ``id``
  324. **Example request**:
  325. .. sourcecode:: http
  326. POST /containers/e90e34656806/stop?t=5 HTTP/1.1
  327. **Example response**:
  328. .. sourcecode:: http
  329. HTTP/1.1 204 OK
  330. :query t: number of seconds to wait before killing the container
  331. :statuscode 204: no error
  332. :statuscode 404: no such container
  333. :statuscode 500: server error
  334. Restart a container
  335. *******************
  336. .. http:post:: /containers/(id)/restart
  337. Restart the container ``id``
  338. **Example request**:
  339. .. sourcecode:: http
  340. POST /containers/e90e34656806/restart?t=5 HTTP/1.1
  341. **Example response**:
  342. .. sourcecode:: http
  343. HTTP/1.1 204 OK
  344. :query t: number of seconds to wait before killing the container
  345. :statuscode 204: no error
  346. :statuscode 404: no such container
  347. :statuscode 500: server error
  348. Kill a container
  349. ****************
  350. .. http:post:: /containers/(id)/kill
  351. Kill the container ``id``
  352. **Example request**:
  353. .. sourcecode:: http
  354. POST /containers/e90e34656806/kill HTTP/1.1
  355. **Example response**:
  356. .. sourcecode:: http
  357. HTTP/1.1 204 OK
  358. :statuscode 204: no error
  359. :statuscode 404: no such container
  360. :statuscode 500: server error
  361. Attach to a container
  362. *********************
  363. .. http:post:: /containers/(id)/attach
  364. Attach to the container ``id``
  365. **Example request**:
  366. .. sourcecode:: http
  367. POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1
  368. **Example response**:
  369. .. sourcecode:: http
  370. HTTP/1.1 200 OK
  371. Content-Type: application/vnd.docker.raw-stream
  372. {{ STREAM }}
  373. :query logs: 1/True/true or 0/False/false, return logs. Default false
  374. :query stream: 1/True/true or 0/False/false, return stream. Default false
  375. :query stdin: 1/True/true or 0/False/false, if stream=true, attach to stdin. Default false
  376. :query stdout: 1/True/true or 0/False/false, if logs=true, return stdout log, if stream=true, attach to stdout. Default false
  377. :query stderr: 1/True/true or 0/False/false, if logs=true, return stderr log, if stream=true, attach to stderr. Default false
  378. :statuscode 200: no error
  379. :statuscode 400: bad parameter
  380. :statuscode 404: no such container
  381. :statuscode 500: server error
  382. **Stream details**:
  383. When using the TTY setting is enabled in
  384. :http:post:`/containers/create`, the stream is the raw data
  385. from the process PTY and client's stdin. When the TTY is
  386. disabled, then the stream is multiplexed to separate stdout
  387. and stderr.
  388. The format is a **Header** and a **Payload** (frame).
  389. **HEADER**
  390. The header will contain the information on which stream write
  391. the stream (stdout or stderr). It also contain the size of
  392. the associated frame encoded on the last 4 bytes (uint32).
  393. It is encoded on the first 8 bytes like this::
  394. header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
  395. ``STREAM_TYPE`` can be:
  396. - 0: stdin (will be writen on stdout)
  397. - 1: stdout
  398. - 2: stderr
  399. ``SIZE1, SIZE2, SIZE3, SIZE4`` are the 4 bytes of the uint32 size encoded as big endian.
  400. **PAYLOAD**
  401. The payload is the raw stream.
  402. **IMPLEMENTATION**
  403. The simplest way to implement the Attach protocol is the following:
  404. 1) Read 8 bytes
  405. 2) chose stdout or stderr depending on the first byte
  406. 3) Extract the frame size from the last 4 byets
  407. 4) Read the extracted size and output it on the correct output
  408. 5) Goto 1)
  409. Wait a container
  410. ****************
  411. .. http:post:: /containers/(id)/wait
  412. Block until container ``id`` stops, then returns the exit code
  413. **Example request**:
  414. .. sourcecode:: http
  415. POST /containers/16253994b7c4/wait HTTP/1.1
  416. **Example response**:
  417. .. sourcecode:: http
  418. HTTP/1.1 200 OK
  419. Content-Type: application/json
  420. {"StatusCode":0}
  421. :statuscode 200: no error
  422. :statuscode 404: no such container
  423. :statuscode 500: server error
  424. Remove a container
  425. *******************
  426. .. http:delete:: /containers/(id)
  427. Remove the container ``id`` from the filesystem
  428. **Example request**:
  429. .. sourcecode:: http
  430. DELETE /containers/16253994b7c4?v=1 HTTP/1.1
  431. **Example response**:
  432. .. sourcecode:: http
  433. HTTP/1.1 204 OK
  434. :query v: 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false
  435. :statuscode 204: no error
  436. :statuscode 400: bad parameter
  437. :statuscode 404: no such container
  438. :statuscode 500: server error
  439. Copy files or folders from a container
  440. **************************************
  441. .. http:post:: /containers/(id)/copy
  442. Copy files or folders of container ``id``
  443. **Example request**:
  444. .. sourcecode:: http
  445. POST /containers/4fa6e0f0c678/copy HTTP/1.1
  446. Content-Type: application/json
  447. {
  448. "Resource":"test.txt"
  449. }
  450. **Example response**:
  451. .. sourcecode:: http
  452. HTTP/1.1 200 OK
  453. Content-Type: application/octet-stream
  454. {{ STREAM }}
  455. :statuscode 200: no error
  456. :statuscode 404: no such container
  457. :statuscode 500: server error
  458. 2.2 Images
  459. ----------
  460. List Images
  461. ***********
  462. .. http:get:: /images/json
  463. **Example request**:
  464. .. sourcecode:: http
  465. GET /images/json?all=0 HTTP/1.1
  466. **Example response**:
  467. .. sourcecode:: http
  468. HTTP/1.1 200 OK
  469. Content-Type: application/json
  470. [
  471. {
  472. "RepoTags": [
  473. "ubuntu:12.04",
  474. "ubuntu:precise",
  475. "ubuntu:latest"
  476. ],
  477. "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
  478. "Created": 1365714795,
  479. "Size": 131506275,
  480. "VirtualSize": 131506275
  481. },
  482. {
  483. "RepoTags": [
  484. "ubuntu:12.10",
  485. "ubuntu:quantal"
  486. ],
  487. "ParentId": "27cf784147099545",
  488. "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  489. "Created": 1364102658,
  490. "Size": 24653,
  491. "VirtualSize": 180116135
  492. }
  493. ]
  494. Create an image
  495. ***************
  496. .. http:post:: /images/create
  497. Create an image, either by pull it from the registry or by importing it
  498. **Example request**:
  499. .. sourcecode:: http
  500. POST /images/create?fromImage=base HTTP/1.1
  501. **Example response**:
  502. .. sourcecode:: http
  503. HTTP/1.1 200 OK
  504. Content-Type: application/json
  505. {"status":"Pulling..."}
  506. {"status":"Pulling", "progress":"1 B/ 100 B", "progressDetail":{"current":1, "total":100}}
  507. {"error":"Invalid..."}
  508. ...
  509. When using this endpoint to pull an image from the registry,
  510. the ``X-Registry-Auth`` header can be used to include a
  511. base64-encoded AuthConfig object.
  512. :query fromImage: name of the image to pull
  513. :query fromSrc: source to import, - means stdin
  514. :query repo: repository
  515. :query tag: tag
  516. :query registry: the registry to pull from
  517. :reqheader X-Registry-Auth: base64-encoded AuthConfig object
  518. :statuscode 200: no error
  519. :statuscode 500: server error
  520. Insert a file in an image
  521. *************************
  522. .. http:post:: /images/(name)/insert
  523. Insert a file from ``url`` in the image ``name`` at ``path``
  524. **Example request**:
  525. .. sourcecode:: http
  526. POST /images/test/insert?path=/usr&url=myurl HTTP/1.1
  527. **Example response**:
  528. .. sourcecode:: http
  529. HTTP/1.1 200 OK
  530. Content-Type: application/json
  531. {"status":"Inserting..."}
  532. {"status":"Inserting", "progress":"1/? (n/a)", "progressDetail":{"current":1}}
  533. {"error":"Invalid..."}
  534. ...
  535. :statuscode 200: no error
  536. :statuscode 500: server error
  537. Inspect an image
  538. ****************
  539. .. http:get:: /images/(name)/json
  540. Return low-level information on the image ``name``
  541. **Example request**:
  542. .. sourcecode:: http
  543. GET /images/base/json HTTP/1.1
  544. **Example response**:
  545. .. sourcecode:: http
  546. HTTP/1.1 200 OK
  547. Content-Type: application/json
  548. {
  549. "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  550. "parent":"27cf784147099545",
  551. "created":"2013-03-23T22:24:18.818426-07:00",
  552. "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
  553. "container_config":
  554. {
  555. "Hostname":"",
  556. "User":"",
  557. "Memory":0,
  558. "MemorySwap":0,
  559. "AttachStdin":false,
  560. "AttachStdout":false,
  561. "AttachStderr":false,
  562. "PortSpecs":null,
  563. "Tty":true,
  564. "OpenStdin":true,
  565. "StdinOnce":false,
  566. "Env":null,
  567. "Cmd": ["/bin/bash"]
  568. ,"Dns":null,
  569. "Image":"base",
  570. "Volumes":null,
  571. "VolumesFrom":"",
  572. "WorkingDir":""
  573. },
  574. "Size": 6824592
  575. }
  576. :statuscode 200: no error
  577. :statuscode 404: no such image
  578. :statuscode 500: server error
  579. Get the history of an image
  580. ***************************
  581. .. http:get:: /images/(name)/history
  582. Return the history of the image ``name``
  583. **Example request**:
  584. .. sourcecode:: http
  585. GET /images/base/history HTTP/1.1
  586. **Example response**:
  587. .. sourcecode:: http
  588. HTTP/1.1 200 OK
  589. Content-Type: application/json
  590. [
  591. {
  592. "Id":"b750fe79269d",
  593. "Created":1364102658,
  594. "CreatedBy":"/bin/bash"
  595. },
  596. {
  597. "Id":"27cf78414709",
  598. "Created":1364068391,
  599. "CreatedBy":""
  600. }
  601. ]
  602. :statuscode 200: no error
  603. :statuscode 404: no such image
  604. :statuscode 500: server error
  605. Push an image on the registry
  606. *****************************
  607. .. http:post:: /images/(name)/push
  608. Push the image ``name`` on the registry
  609. **Example request**:
  610. .. sourcecode:: http
  611. POST /images/test/push HTTP/1.1
  612. **Example response**:
  613. .. sourcecode:: http
  614. HTTP/1.1 200 OK
  615. Content-Type: application/json
  616. {"status":"Pushing..."}
  617. {"status":"Pushing", "progress":"1/? (n/a)", "progressDetail":{"current":1}}}
  618. {"error":"Invalid..."}
  619. ...
  620. :query registry: the registry you wan to push, optional
  621. :reqheader X-Registry-Auth: include a base64-encoded AuthConfig object.
  622. :statuscode 200: no error
  623. :statuscode 404: no such image
  624. :statuscode 500: server error
  625. Tag an image into a repository
  626. ******************************
  627. .. http:post:: /images/(name)/tag
  628. Tag the image ``name`` into a repository
  629. **Example request**:
  630. .. sourcecode:: http
  631. POST /images/test/tag?repo=myrepo&force=0 HTTP/1.1
  632. **Example response**:
  633. .. sourcecode:: http
  634. HTTP/1.1 201 OK
  635. :query repo: The repository to tag in
  636. :query force: 1/True/true or 0/False/false, default false
  637. :statuscode 201: no error
  638. :statuscode 400: bad parameter
  639. :statuscode 404: no such image
  640. :statuscode 409: conflict
  641. :statuscode 500: server error
  642. Remove an image
  643. ***************
  644. .. http:delete:: /images/(name)
  645. Remove the image ``name`` from the filesystem
  646. **Example request**:
  647. .. sourcecode:: http
  648. DELETE /images/test HTTP/1.1
  649. **Example response**:
  650. .. sourcecode:: http
  651. HTTP/1.1 200 OK
  652. Content-type: application/json
  653. [
  654. {"Untagged":"3e2f21a89f"},
  655. {"Deleted":"3e2f21a89f"},
  656. {"Deleted":"53b4f83ac9"}
  657. ]
  658. :statuscode 200: no error
  659. :statuscode 404: no such image
  660. :statuscode 409: conflict
  661. :statuscode 500: server error
  662. Search images
  663. *************
  664. .. http:get:: /images/search
  665. Search for an image in the docker index.
  666. .. note::
  667. The response keys have changed from API v1.6 to reflect the JSON
  668. sent by the registry server to the docker daemon's request.
  669. **Example request**:
  670. .. sourcecode:: http
  671. GET /images/search?term=sshd HTTP/1.1
  672. **Example response**:
  673. .. sourcecode:: http
  674. HTTP/1.1 200 OK
  675. Content-Type: application/json
  676. [
  677. {
  678. "description": "",
  679. "is_official": false,
  680. "is_trusted": false,
  681. "name": "wma55/u1210sshd",
  682. "star_count": 0
  683. },
  684. {
  685. "description": "",
  686. "is_official": false,
  687. "is_trusted": false,
  688. "name": "jdswinbank/sshd",
  689. "star_count": 0
  690. },
  691. {
  692. "description": "",
  693. "is_official": false,
  694. "is_trusted": false,
  695. "name": "vgauthier/sshd",
  696. "star_count": 0
  697. }
  698. ...
  699. ]
  700. :query term: term to search
  701. :statuscode 200: no error
  702. :statuscode 500: server error
  703. 2.3 Misc
  704. --------
  705. Build an image from Dockerfile via stdin
  706. ****************************************
  707. .. http:post:: /build
  708. Build an image from Dockerfile via stdin
  709. **Example request**:
  710. .. sourcecode:: http
  711. POST /build HTTP/1.1
  712. {{ STREAM }}
  713. **Example response**:
  714. .. sourcecode:: http
  715. HTTP/1.1 200 OK
  716. Content-Type: application/json
  717. {"stream":"Step 1..."}
  718. {"stream":"..."}
  719. {"error":"Error...", "errorDetail":{"code": 123, "message": "Error..."}}
  720. The stream must be a tar archive compressed with one of the
  721. following algorithms: identity (no compression), gzip, bzip2,
  722. xz.
  723. The archive must include a file called ``Dockerfile`` at its
  724. root. It may include any number of other files, which will be
  725. accessible in the build context (See the :ref:`ADD build command
  726. <dockerbuilder>`).
  727. :query t: repository name (and optionally a tag) to be applied to the resulting image in case of success
  728. :query q: suppress verbose build output
  729. :query nocache: do not use the cache when building the image
  730. :reqheader Content-type: should be set to ``"application/tar"``.
  731. :reqheader X-Registry-Auth: base64-encoded AuthConfig object
  732. :statuscode 200: no error
  733. :statuscode 500: server error
  734. Check auth configuration
  735. ************************
  736. .. http:post:: /auth
  737. Get the default username and email
  738. **Example request**:
  739. .. sourcecode:: http
  740. POST /auth HTTP/1.1
  741. Content-Type: application/json
  742. {
  743. "username":"hannibal",
  744. "password:"xxxx",
  745. "email":"hannibal@a-team.com",
  746. "serveraddress":"https://index.docker.io/v1/"
  747. }
  748. **Example response**:
  749. .. sourcecode:: http
  750. HTTP/1.1 200 OK
  751. :statuscode 200: no error
  752. :statuscode 204: no error
  753. :statuscode 500: server error
  754. Display system-wide information
  755. *******************************
  756. .. http:get:: /info
  757. Display system-wide information
  758. **Example request**:
  759. .. sourcecode:: http
  760. GET /info HTTP/1.1
  761. **Example response**:
  762. .. sourcecode:: http
  763. HTTP/1.1 200 OK
  764. Content-Type: application/json
  765. {
  766. "Containers":11,
  767. "Images":16,
  768. "Debug":false,
  769. "NFd": 11,
  770. "NGoroutines":21,
  771. "MemoryLimit":true,
  772. "SwapLimit":false,
  773. "IPv4Forwarding":true
  774. }
  775. :statuscode 200: no error
  776. :statuscode 500: server error
  777. Show the docker version information
  778. ***********************************
  779. .. http:get:: /version
  780. Show the docker version information
  781. **Example request**:
  782. .. sourcecode:: http
  783. GET /version HTTP/1.1
  784. **Example response**:
  785. .. sourcecode:: http
  786. HTTP/1.1 200 OK
  787. Content-Type: application/json
  788. {
  789. "Version":"0.2.2",
  790. "GitCommit":"5a2a5cc+CHANGES",
  791. "GoVersion":"go1.0.3"
  792. }
  793. :statuscode 200: no error
  794. :statuscode 500: server error
  795. Create a new image from a container's changes
  796. *********************************************
  797. .. http:post:: /commit
  798. Create a new image from a container's changes
  799. **Example request**:
  800. .. sourcecode:: http
  801. POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1
  802. **Example response**:
  803. .. sourcecode:: http
  804. HTTP/1.1 201 OK
  805. Content-Type: application/vnd.docker.raw-stream
  806. {"Id":"596069db4bf5"}
  807. :query container: source container
  808. :query repo: repository
  809. :query tag: tag
  810. :query m: commit message
  811. :query author: author (eg. "John Hannibal Smith <hannibal@a-team.com>")
  812. :query run: config automatically applied when the image is run. (ex: {"Cmd": ["cat", "/world"], "PortSpecs":["22"]})
  813. :statuscode 201: no error
  814. :statuscode 404: no such container
  815. :statuscode 500: server error
  816. Monitor Docker's events
  817. ***********************
  818. .. http:get:: /events
  819. Get events from docker, either in real time via streaming, or via polling (using `since`)
  820. **Example request**:
  821. .. sourcecode:: http
  822. GET /events?since=1374067924
  823. **Example response**:
  824. .. sourcecode:: http
  825. HTTP/1.1 200 OK
  826. Content-Type: application/json
  827. {"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
  828. {"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
  829. {"status":"stop","id":"dfdf82bd3881","from":"base:latest","time":1374067966}
  830. {"status":"destroy","id":"dfdf82bd3881","from":"base:latest","time":1374067970}
  831. :query since: timestamp used for polling
  832. :statuscode 200: no error
  833. :statuscode 500: server error
  834. Get a tarball containing all images and tags in a repository
  835. ************************************************************
  836. .. http:get:: /images/(name)/get
  837. Get a tarball containing all images and metadata for the repository specified by ``name``.
  838. **Example request**
  839. .. sourcecode:: http
  840. GET /images/ubuntu/get
  841. **Example response**:
  842. .. sourcecode:: http
  843. HTTP/1.1 200 OK
  844. Content-Type: application/x-tar
  845. Binary data stream
  846. :statuscode 200: no error
  847. :statuscode 500: server error
  848. Load a tarball with a set of images and tags into docker
  849. ********************************************************
  850. .. http:post:: /images/load
  851. Load a set of images and tags into the docker repository.
  852. **Example request**
  853. .. sourcecode:: http
  854. POST /images/load
  855. Tarball in body
  856. **Example response**:
  857. .. sourcecode:: http
  858. HTTP/1.1 200 OK
  859. :statuscode 200: no error
  860. :statuscode 500: server error
  861. 3. Going further
  862. ================
  863. 3.1 Inside 'docker run'
  864. -----------------------
  865. Here are the steps of 'docker run' :
  866. * Create the container
  867. * If the status code is 404, it means the image doesn't exists:
  868. * Try to pull it
  869. * Then retry to create the container
  870. * Start the container
  871. * If you are not in detached mode:
  872. * Attach to the container, using logs=1 (to have stdout and stderr from the container's start) and stream=1
  873. * If in detached mode or only stdin is attached:
  874. * Display the container's id
  875. 3.2 Hijacking
  876. -------------
  877. 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.
  878. 3.3 CORS Requests
  879. -----------------
  880. To enable cross origin requests to the remote api add the flag "-api-enable-cors" when running docker in daemon mode.
  881. .. code-block:: bash
  882. docker -d -H="192.168.1.9:4243" -api-enable-cors