docker_remote_api_v1.9.rst 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. :title: Remote API v1.9
  2. :description: API Documentation for Docker
  3. :keywords: API, Docker, rcli, REST, documentation
  4. :orphan:
  5. ======================
  6. Docker Remote API v1.9
  7. ======================
  8. 1. Brief introduction
  9. =====================
  10. - The Remote API has replaced rcli
  11. - The daemon listens on ``unix:///var/run/docker.sock``, but you can
  12. :ref:`bind_docker`.
  13. - The API tends to be REST, but for some complex commands, like
  14. ``attach`` or ``pull``, the HTTP connection is hijacked to transport
  15. ``stdout, stdin`` and ``stderr``
  16. 2. Endpoints
  17. ============
  18. 2.1 Containers
  19. --------------
  20. List containers
  21. ***************
  22. .. http:get:: /containers/json
  23. List containers
  24. **Example request**:
  25. .. sourcecode:: http
  26. GET /containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1
  27. **Example response**:
  28. .. sourcecode:: http
  29. HTTP/1.1 200 OK
  30. Content-Type: application/json
  31. [
  32. {
  33. "Id": "8dfafdbc3a40",
  34. "Image": "base:latest",
  35. "Command": "echo 1",
  36. "Created": 1367854155,
  37. "Status": "Exit 0",
  38. "Ports":[{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}],
  39. "SizeRw":12288,
  40. "SizeRootFs":0
  41. },
  42. {
  43. "Id": "9cd87474be90",
  44. "Image": "base:latest",
  45. "Command": "echo 222222",
  46. "Created": 1367854155,
  47. "Status": "Exit 0",
  48. "Ports":[],
  49. "SizeRw":12288,
  50. "SizeRootFs":0
  51. },
  52. {
  53. "Id": "3176a2479c92",
  54. "Image": "base:latest",
  55. "Command": "echo 3333333333333333",
  56. "Created": 1367854154,
  57. "Status": "Exit 0",
  58. "Ports":[],
  59. "SizeRw":12288,
  60. "SizeRootFs":0
  61. },
  62. {
  63. "Id": "4cb07b47f9fb",
  64. "Image": "base:latest",
  65. "Command": "echo 444444444444444444444444444444444",
  66. "Created": 1367854152,
  67. "Status": "Exit 0",
  68. "Ports":[],
  69. "SizeRw":12288,
  70. "SizeRootFs":0
  71. }
  72. ]
  73. :query all: 1/True/true or 0/False/false, Show all containers. Only running containers are shown by default
  74. :query limit: Show ``limit`` last created containers, include non-running ones.
  75. :query since: Show only containers created since Id, include non-running ones.
  76. :query before: Show only containers created before Id, include non-running ones.
  77. :query size: 1/True/true or 0/False/false, Show the containers sizes
  78. :statuscode 200: no error
  79. :statuscode 400: bad parameter
  80. :statuscode 500: server error
  81. Create a container
  82. ******************
  83. .. http:post:: /containers/create
  84. Create a container
  85. **Example request**:
  86. .. sourcecode:: http
  87. POST /containers/create HTTP/1.1
  88. Content-Type: application/json
  89. {
  90. "Hostname":"",
  91. "User":"",
  92. "Memory":0,
  93. "MemorySwap":0,
  94. "CpuShares":0,
  95. "AttachStdin":false,
  96. "AttachStdout":true,
  97. "AttachStderr":true,
  98. "PortSpecs":null,
  99. "Tty":false,
  100. "OpenStdin":false,
  101. "StdinOnce":false,
  102. "Env":null,
  103. "Cmd":[
  104. "date"
  105. ],
  106. "Dns":null,
  107. "Image":"base",
  108. "Volumes":{
  109. "/tmp": {}
  110. },
  111. "VolumesFrom":"",
  112. "WorkingDir":"",
  113. "ExposedPorts":{
  114. "22/tcp": {}
  115. }
  116. }
  117. **Example response**:
  118. .. sourcecode:: http
  119. HTTP/1.1 201 OK
  120. Content-Type: application/json
  121. {
  122. "Id":"e90e34656806"
  123. "Warnings":[]
  124. }
  125. :jsonparam Hostname: Container host name
  126. :jsonparam User: Username or UID
  127. :jsonparam Memory: Memory Limit in bytes
  128. :jsonparam CpuShares: CPU shares (relative weight)
  129. :jsonparam AttachStdin: 1/True/true or 0/False/false, attach to standard input. Default false
  130. :jsonparam AttachStdout: 1/True/true or 0/False/false, attach to standard output. Default false
  131. :jsonparam AttachStderr: 1/True/true or 0/False/false, attach to standard error. Default false
  132. :jsonparam Tty: 1/True/true or 0/False/false, allocate a pseudo-tty. Default false
  133. :jsonparam OpenStdin: 1/True/true or 0/False/false, keep stdin open even if not attached. Default false
  134. :query name: Assign the specified name to the container. Must match ``/?[a-zA-Z0-9_-]+``.
  135. :statuscode 201: no error
  136. :statuscode 404: no such container
  137. :statuscode 406: impossible to attach (container not running)
  138. :statuscode 500: server error
  139. Inspect a container
  140. *******************
  141. .. http:get:: /containers/(id)/json
  142. Return low-level information on the container ``id``
  143. **Example request**:
  144. .. sourcecode:: http
  145. GET /containers/4fa6e0f0c678/json HTTP/1.1
  146. **Example response**:
  147. .. sourcecode:: http
  148. HTTP/1.1 200 OK
  149. Content-Type: application/json
  150. {
  151. "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
  152. "Created": "2013-05-07T14:51:42.041847+02:00",
  153. "Path": "date",
  154. "Args": [],
  155. "Config": {
  156. "Hostname": "4fa6e0f0c678",
  157. "User": "",
  158. "Memory": 0,
  159. "MemorySwap": 0,
  160. "AttachStdin": false,
  161. "AttachStdout": true,
  162. "AttachStderr": true,
  163. "PortSpecs": null,
  164. "Tty": false,
  165. "OpenStdin": false,
  166. "StdinOnce": false,
  167. "Env": null,
  168. "Cmd": [
  169. "date"
  170. ],
  171. "Dns": null,
  172. "Image": "base",
  173. "Volumes": {},
  174. "VolumesFrom": "",
  175. "WorkingDir":""
  176. },
  177. "State": {
  178. "Running": false,
  179. "Pid": 0,
  180. "ExitCode": 0,
  181. "StartedAt": "2013-05-07T14:51:42.087658+02:01360",
  182. "Ghost": false
  183. },
  184. "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  185. "NetworkSettings": {
  186. "IpAddress": "",
  187. "IpPrefixLen": 0,
  188. "Gateway": "",
  189. "Bridge": "",
  190. "PortMapping": null
  191. },
  192. "SysInitPath": "/home/kitty/go/src/github.com/dotcloud/docker/bin/docker",
  193. "ResolvConfPath": "/etc/resolv.conf",
  194. "Volumes": {},
  195. "HostConfig": {
  196. "Binds": null,
  197. "ContainerIDFile": "",
  198. "LxcConf": [],
  199. "Privileged": false,
  200. "PortBindings": {
  201. "80/tcp": [
  202. {
  203. "HostIp": "0.0.0.0",
  204. "HostPort": "49153"
  205. }
  206. ]
  207. },
  208. "Links": null,
  209. "PublishAllPorts": false
  210. }
  211. }
  212. :statuscode 200: no error
  213. :statuscode 404: no such container
  214. :statuscode 500: server error
  215. List processes running inside a container
  216. *****************************************
  217. .. http:get:: /containers/(id)/top
  218. List processes running inside the container ``id``
  219. **Example request**:
  220. .. sourcecode:: http
  221. GET /containers/4fa6e0f0c678/top HTTP/1.1
  222. **Example response**:
  223. .. sourcecode:: http
  224. HTTP/1.1 200 OK
  225. Content-Type: application/json
  226. {
  227. "Titles":[
  228. "USER",
  229. "PID",
  230. "%CPU",
  231. "%MEM",
  232. "VSZ",
  233. "RSS",
  234. "TTY",
  235. "STAT",
  236. "START",
  237. "TIME",
  238. "COMMAND"
  239. ],
  240. "Processes":[
  241. ["root","20147","0.0","0.1","18060","1864","pts/4","S","10:06","0:00","bash"],
  242. ["root","20271","0.0","0.0","4312","352","pts/4","S+","10:07","0:00","sleep","10"]
  243. ]
  244. }
  245. :query ps_args: ps arguments to use (eg. aux)
  246. :statuscode 200: no error
  247. :statuscode 404: no such container
  248. :statuscode 500: server error
  249. Inspect changes on a container's filesystem
  250. *******************************************
  251. .. http:get:: /containers/(id)/changes
  252. Inspect changes on container ``id`` 's filesystem
  253. **Example request**:
  254. .. sourcecode:: http
  255. GET /containers/4fa6e0f0c678/changes HTTP/1.1
  256. **Example response**:
  257. .. sourcecode:: http
  258. HTTP/1.1 200 OK
  259. Content-Type: application/json
  260. [
  261. {
  262. "Path":"/dev",
  263. "Kind":0
  264. },
  265. {
  266. "Path":"/dev/kmsg",
  267. "Kind":1
  268. },
  269. {
  270. "Path":"/test",
  271. "Kind":1
  272. }
  273. ]
  274. :statuscode 200: no error
  275. :statuscode 404: no such container
  276. :statuscode 500: server error
  277. Export a container
  278. ******************
  279. .. http:get:: /containers/(id)/export
  280. Export the contents of container ``id``
  281. **Example request**:
  282. .. sourcecode:: http
  283. GET /containers/4fa6e0f0c678/export HTTP/1.1
  284. **Example response**:
  285. .. sourcecode:: http
  286. HTTP/1.1 200 OK
  287. Content-Type: application/octet-stream
  288. {{ STREAM }}
  289. :statuscode 200: no error
  290. :statuscode 404: no such container
  291. :statuscode 500: server error
  292. Start a container
  293. *****************
  294. .. http:post:: /containers/(id)/start
  295. Start the container ``id``
  296. **Example request**:
  297. .. sourcecode:: http
  298. POST /containers/(id)/start HTTP/1.1
  299. Content-Type: application/json
  300. {
  301. "Binds":["/tmp:/tmp"],
  302. "LxcConf":{"lxc.utsname":"docker"},
  303. "PortBindings":{ "22/tcp": [{ "HostPort": "11022" }] },
  304. "PublishAllPorts":false,
  305. "Privileged":false
  306. }
  307. **Example response**:
  308. .. sourcecode:: http
  309. HTTP/1.1 204 No Content
  310. Content-Type: text/plain
  311. :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.
  312. :jsonparam LxcConf: Map of custom lxc options
  313. :jsonparam PortBindings: Expose ports from the container, optionally publishing them via the HostPort flag
  314. :jsonparam PublishAllPorts: 1/True/true or 0/False/false, publish all exposed ports to the host interfaces. Default false
  315. :jsonparam Privileged: 1/True/true or 0/False/false, give extended privileges to this container. Default false
  316. :statuscode 204: no error
  317. :statuscode 404: no such container
  318. :statuscode 500: server error
  319. Stop a container
  320. ****************
  321. .. http:post:: /containers/(id)/stop
  322. Stop the container ``id``
  323. **Example request**:
  324. .. sourcecode:: http
  325. POST /containers/e90e34656806/stop?t=5 HTTP/1.1
  326. **Example response**:
  327. .. sourcecode:: http
  328. HTTP/1.1 204 OK
  329. :query t: number of seconds to wait before killing the container
  330. :statuscode 204: no error
  331. :statuscode 404: no such container
  332. :statuscode 500: server error
  333. Restart a container
  334. *******************
  335. .. http:post:: /containers/(id)/restart
  336. Restart the container ``id``
  337. **Example request**:
  338. .. sourcecode:: http
  339. POST /containers/e90e34656806/restart?t=5 HTTP/1.1
  340. **Example response**:
  341. .. sourcecode:: http
  342. HTTP/1.1 204 OK
  343. :query t: number of seconds to wait before killing the container
  344. :statuscode 204: no error
  345. :statuscode 404: no such container
  346. :statuscode 500: server error
  347. Kill a container
  348. ****************
  349. .. http:post:: /containers/(id)/kill
  350. Kill the container ``id``
  351. **Example request**:
  352. .. sourcecode:: http
  353. POST /containers/e90e34656806/kill HTTP/1.1
  354. **Example response**:
  355. .. sourcecode:: http
  356. HTTP/1.1 204 OK
  357. :statuscode 204: no error
  358. :statuscode 404: no such container
  359. :statuscode 500: server error
  360. Attach to a container
  361. *********************
  362. .. http:post:: /containers/(id)/attach
  363. Attach to the container ``id``
  364. **Example request**:
  365. .. sourcecode:: http
  366. POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1
  367. **Example response**:
  368. .. sourcecode:: http
  369. HTTP/1.1 200 OK
  370. Content-Type: application/vnd.docker.raw-stream
  371. {{ STREAM }}
  372. :query logs: 1/True/true or 0/False/false, return logs. Default false
  373. :query stream: 1/True/true or 0/False/false, return stream. Default false
  374. :query stdin: 1/True/true or 0/False/false, if stream=true, attach to stdin. Default false
  375. :query stdout: 1/True/true or 0/False/false, if logs=true, return stdout log, if stream=true, attach to stdout. Default false
  376. :query stderr: 1/True/true or 0/False/false, if logs=true, return stderr log, if stream=true, attach to stderr. Default false
  377. :statuscode 200: no error
  378. :statuscode 400: bad parameter
  379. :statuscode 404: no such container
  380. :statuscode 500: server error
  381. **Stream details**:
  382. When using the TTY setting is enabled in
  383. :http:post:`/containers/create`, the stream is the raw data
  384. from the process PTY and client's stdin. When the TTY is
  385. disabled, then the stream is multiplexed to separate stdout
  386. and stderr.
  387. The format is a **Header** and a **Payload** (frame).
  388. **HEADER**
  389. The header will contain the information on which stream write
  390. the stream (stdout or stderr). It also contain the size of
  391. the associated frame encoded on the last 4 bytes (uint32).
  392. It is encoded on the first 8 bytes like this::
  393. header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
  394. ``STREAM_TYPE`` can be:
  395. - 0: stdin (will be writen on stdout)
  396. - 1: stdout
  397. - 2: stderr
  398. ``SIZE1, SIZE2, SIZE3, SIZE4`` are the 4 bytes of the uint32 size encoded as big endian.
  399. **PAYLOAD**
  400. The payload is the raw stream.
  401. **IMPLEMENTATION**
  402. The simplest way to implement the Attach protocol is the following:
  403. 1) Read 8 bytes
  404. 2) chose stdout or stderr depending on the first byte
  405. 3) Extract the frame size from the last 4 byets
  406. 4) Read the extracted size and output it on the correct output
  407. 5) Goto 1)
  408. Wait a container
  409. ****************
  410. .. http:post:: /containers/(id)/wait
  411. Block until container ``id`` stops, then returns the exit code
  412. **Example request**:
  413. .. sourcecode:: http
  414. POST /containers/16253994b7c4/wait HTTP/1.1
  415. **Example response**:
  416. .. sourcecode:: http
  417. HTTP/1.1 200 OK
  418. Content-Type: application/json
  419. {"StatusCode":0}
  420. :statuscode 200: no error
  421. :statuscode 404: no such container
  422. :statuscode 500: server error
  423. Remove a container
  424. *******************
  425. .. http:delete:: /containers/(id)
  426. Remove the container ``id`` from the filesystem
  427. **Example request**:
  428. .. sourcecode:: http
  429. DELETE /containers/16253994b7c4?v=1 HTTP/1.1
  430. **Example response**:
  431. .. sourcecode:: http
  432. HTTP/1.1 204 OK
  433. :query v: 1/True/true or 0/False/false, Remove the volumes associated to the container. Default false
  434. :statuscode 204: no error
  435. :statuscode 400: bad parameter
  436. :statuscode 404: no such container
  437. :statuscode 500: server error
  438. Copy files or folders from a container
  439. **************************************
  440. .. http:post:: /containers/(id)/copy
  441. Copy files or folders of container ``id``
  442. **Example request**:
  443. .. sourcecode:: http
  444. POST /containers/4fa6e0f0c678/copy HTTP/1.1
  445. Content-Type: application/json
  446. {
  447. "Resource":"test.txt"
  448. }
  449. **Example response**:
  450. .. sourcecode:: http
  451. HTTP/1.1 200 OK
  452. Content-Type: application/octet-stream
  453. {{ STREAM }}
  454. :statuscode 200: no error
  455. :statuscode 404: no such container
  456. :statuscode 500: server error
  457. 2.2 Images
  458. ----------
  459. List Images
  460. ***********
  461. .. http:get:: /images/json
  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. "RepoTags": [
  472. "ubuntu:12.04",
  473. "ubuntu:precise",
  474. "ubuntu:latest"
  475. ],
  476. "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
  477. "Created": 1365714795,
  478. "Size": 131506275,
  479. "VirtualSize": 131506275
  480. },
  481. {
  482. "RepoTags": [
  483. "ubuntu:12.10",
  484. "ubuntu:quantal"
  485. ],
  486. "ParentId": "27cf784147099545",
  487. "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  488. "Created": 1364102658,
  489. "Size": 24653,
  490. "VirtualSize": 180116135
  491. }
  492. ]
  493. Create an image
  494. ***************
  495. .. http:post:: /images/create
  496. Create an image, either by pull it from the registry or by importing it
  497. **Example request**:
  498. .. sourcecode:: http
  499. POST /images/create?fromImage=base HTTP/1.1
  500. **Example response**:
  501. .. sourcecode:: http
  502. HTTP/1.1 200 OK
  503. Content-Type: application/json
  504. {"status":"Pulling..."}
  505. {"status":"Pulling", "progress":"1 B/ 100 B", "progressDetail":{"current":1, "total":100}}
  506. {"error":"Invalid..."}
  507. ...
  508. When using this endpoint to pull an image from the registry,
  509. the ``X-Registry-Auth`` header can be used to include a
  510. base64-encoded AuthConfig object.
  511. :query fromImage: name of the image to pull
  512. :query fromSrc: source to import, - means stdin
  513. :query repo: repository
  514. :query tag: tag
  515. :query registry: the registry to pull from
  516. :reqheader X-Registry-Auth: base64-encoded AuthConfig object
  517. :statuscode 200: no error
  518. :statuscode 500: server error
  519. Insert a file in an image
  520. *************************
  521. .. http:post:: /images/(name)/insert
  522. Insert a file from ``url`` in the image ``name`` at ``path``
  523. **Example request**:
  524. .. sourcecode:: http
  525. POST /images/test/insert?path=/usr&url=myurl HTTP/1.1
  526. **Example response**:
  527. .. sourcecode:: http
  528. HTTP/1.1 200 OK
  529. Content-Type: application/json
  530. {"status":"Inserting..."}
  531. {"status":"Inserting", "progress":"1/? (n/a)", "progressDetail":{"current":1}}
  532. {"error":"Invalid..."}
  533. ...
  534. :statuscode 200: no error
  535. :statuscode 500: server error
  536. Inspect an image
  537. ****************
  538. .. http:get:: /images/(name)/json
  539. Return low-level information on the image ``name``
  540. **Example request**:
  541. .. sourcecode:: http
  542. GET /images/base/json HTTP/1.1
  543. **Example response**:
  544. .. sourcecode:: http
  545. HTTP/1.1 200 OK
  546. Content-Type: application/json
  547. {
  548. "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
  549. "parent":"27cf784147099545",
  550. "created":"2013-03-23T22:24:18.818426-07:00",
  551. "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
  552. "container_config":
  553. {
  554. "Hostname":"",
  555. "User":"",
  556. "Memory":0,
  557. "MemorySwap":0,
  558. "AttachStdin":false,
  559. "AttachStdout":false,
  560. "AttachStderr":false,
  561. "PortSpecs":null,
  562. "Tty":true,
  563. "OpenStdin":true,
  564. "StdinOnce":false,
  565. "Env":null,
  566. "Cmd": ["/bin/bash"]
  567. ,"Dns":null,
  568. "Image":"base",
  569. "Volumes":null,
  570. "VolumesFrom":"",
  571. "WorkingDir":""
  572. },
  573. "Size": 6824592
  574. }
  575. :statuscode 200: no error
  576. :statuscode 404: no such image
  577. :statuscode 500: server error
  578. Get the history of an image
  579. ***************************
  580. .. http:get:: /images/(name)/history
  581. Return the history of the image ``name``
  582. **Example request**:
  583. .. sourcecode:: http
  584. GET /images/base/history HTTP/1.1
  585. **Example response**:
  586. .. sourcecode:: http
  587. HTTP/1.1 200 OK
  588. Content-Type: application/json
  589. [
  590. {
  591. "Id":"b750fe79269d",
  592. "Created":1364102658,
  593. "CreatedBy":"/bin/bash"
  594. },
  595. {
  596. "Id":"27cf78414709",
  597. "Created":1364068391,
  598. "CreatedBy":""
  599. }
  600. ]
  601. :statuscode 200: no error
  602. :statuscode 404: no such image
  603. :statuscode 500: server error
  604. Push an image on the registry
  605. *****************************
  606. .. http:post:: /images/(name)/push
  607. Push the image ``name`` on the registry
  608. **Example request**:
  609. .. sourcecode:: http
  610. POST /images/test/push HTTP/1.1
  611. **Example response**:
  612. .. sourcecode:: http
  613. HTTP/1.1 200 OK
  614. Content-Type: application/json
  615. {"status":"Pushing..."}
  616. {"status":"Pushing", "progress":"1/? (n/a)", "progressDetail":{"current":1}}}
  617. {"error":"Invalid..."}
  618. ...
  619. :query registry: the registry you wan to push, optional
  620. :reqheader X-Registry-Auth: include a base64-encoded AuthConfig object.
  621. :statuscode 200: no error
  622. :statuscode 404: no such image
  623. :statuscode 500: server error
  624. Tag an image into a repository
  625. ******************************
  626. .. http:post:: /images/(name)/tag
  627. Tag the image ``name`` into a repository
  628. **Example request**:
  629. .. sourcecode:: http
  630. POST /images/test/tag?repo=myrepo&force=0 HTTP/1.1
  631. **Example response**:
  632. .. sourcecode:: http
  633. HTTP/1.1 201 OK
  634. :query repo: The repository to tag in
  635. :query force: 1/True/true or 0/False/false, default false
  636. :statuscode 201: no error
  637. :statuscode 400: bad parameter
  638. :statuscode 404: no such image
  639. :statuscode 409: conflict
  640. :statuscode 500: server error
  641. Remove an image
  642. ***************
  643. .. http:delete:: /images/(name)
  644. Remove the image ``name`` from the filesystem
  645. **Example request**:
  646. .. sourcecode:: http
  647. DELETE /images/test HTTP/1.1
  648. **Example response**:
  649. .. sourcecode:: http
  650. HTTP/1.1 200 OK
  651. Content-type: application/json
  652. [
  653. {"Untagged":"3e2f21a89f"},
  654. {"Deleted":"3e2f21a89f"},
  655. {"Deleted":"53b4f83ac9"}
  656. ]
  657. :statuscode 200: no error
  658. :statuscode 404: no such image
  659. :statuscode 409: conflict
  660. :statuscode 500: server error
  661. Search images
  662. *************
  663. .. http:get:: /images/search
  664. Search for an image in the docker index.
  665. .. note::
  666. The response keys have changed from API v1.6 to reflect the JSON
  667. sent by the registry server to the docker daemon's request.
  668. **Example request**:
  669. .. sourcecode:: http
  670. GET /images/search?term=sshd HTTP/1.1
  671. **Example response**:
  672. .. sourcecode:: http
  673. HTTP/1.1 200 OK
  674. Content-Type: application/json
  675. [
  676. {
  677. "description": "",
  678. "is_official": false,
  679. "is_trusted": false,
  680. "name": "wma55/u1210sshd",
  681. "star_count": 0
  682. },
  683. {
  684. "description": "",
  685. "is_official": false,
  686. "is_trusted": false,
  687. "name": "jdswinbank/sshd",
  688. "star_count": 0
  689. },
  690. {
  691. "description": "",
  692. "is_official": false,
  693. "is_trusted": false,
  694. "name": "vgauthier/sshd",
  695. "star_count": 0
  696. }
  697. ...
  698. ]
  699. :query term: term to search
  700. :statuscode 200: no error
  701. :statuscode 500: server error
  702. 2.3 Misc
  703. --------
  704. Build an image from Dockerfile
  705. ******************************
  706. .. http:post:: /build
  707. Build an image from Dockerfile using a POST body.
  708. **Example request**:
  709. .. sourcecode:: http
  710. POST /build HTTP/1.1
  711. {{ STREAM }}
  712. **Example response**:
  713. .. sourcecode:: http
  714. HTTP/1.1 200 OK
  715. Content-Type: application/json
  716. {"stream":"Step 1..."}
  717. {"stream":"..."}
  718. {"error":"Error...", "errorDetail":{"code": 123, "message": "Error..."}}
  719. The stream must be a tar archive compressed with one of the
  720. following algorithms: identity (no compression), gzip, bzip2,
  721. xz.
  722. The archive must include a file called ``Dockerfile`` at its
  723. root. It may include any number of other files, which will be
  724. accessible in the build context (See the :ref:`ADD build command
  725. <dockerbuilder>`).
  726. :query t: repository name (and optionally a tag) to be applied to the resulting image in case of success
  727. :query q: suppress verbose build output
  728. :query nocache: do not use the cache when building the image
  729. :query rm: Remove intermediate containers after a successful build
  730. :reqheader Content-type: should be set to ``"application/tar"``.
  731. :reqheader X-Registry-Config: base64-encoded ConfigFile 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