@lakutata/docker 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +309 -0
  3. package/THIRD_PARTY_NOTICES.md +299 -0
  4. package/dist/cjs/client/BuildContext.d.ts +22 -0
  5. package/dist/cjs/client/BuildContext.js +76 -0
  6. package/dist/cjs/client/BuildKitProgress.d.ts +81 -0
  7. package/dist/cjs/client/BuildKitProgress.js +195 -0
  8. package/dist/cjs/client/DockerClient.d.ts +196 -0
  9. package/dist/cjs/client/DockerClient.js +312 -0
  10. package/dist/cjs/client/DockerConnection.d.ts +154 -0
  11. package/dist/cjs/client/DockerConnection.js +397 -0
  12. package/dist/cjs/client/DockerIgnore.d.ts +44 -0
  13. package/dist/cjs/client/DockerIgnore.js +186 -0
  14. package/dist/cjs/client/DockerRequestError.d.ts +17 -0
  15. package/dist/cjs/client/DockerRequestError.js +24 -0
  16. package/dist/cjs/client/DockerStreams.d.ts +35 -0
  17. package/dist/cjs/client/DockerStreams.js +117 -0
  18. package/dist/cjs/client/types/ContainerCreateResponse.d.ts +7 -0
  19. package/dist/cjs/client/types/ContainerCreateResponse.js +2 -0
  20. package/dist/cjs/client/types/ContainerStopQuery.d.ts +13 -0
  21. package/dist/cjs/client/types/ContainerStopQuery.js +2 -0
  22. package/dist/cjs/client/types/DeviceMapping.d.ts +8 -0
  23. package/dist/cjs/client/types/DeviceMapping.js +2 -0
  24. package/dist/cjs/client/types/IdResponse.d.ts +6 -0
  25. package/dist/cjs/client/types/IdResponse.js +2 -0
  26. package/dist/cjs/client/types/NetworkCreateResponse.d.ts +7 -0
  27. package/dist/cjs/client/types/NetworkCreateResponse.js +2 -0
  28. package/dist/cjs/client/types/PortBinding.d.ts +10 -0
  29. package/dist/cjs/client/types/PortBinding.js +2 -0
  30. package/dist/cjs/docker/ConnectionOptionsBuilder.d.ts +128 -0
  31. package/dist/cjs/docker/ConnectionOptionsBuilder.js +150 -0
  32. package/dist/cjs/docker/Docker.d.ts +301 -0
  33. package/dist/cjs/docker/Docker.js +703 -0
  34. package/dist/cjs/docker/exceptions/DockerConnectionException.d.ts +9 -0
  35. package/dist/cjs/docker/exceptions/DockerConnectionException.js +16 -0
  36. package/dist/cjs/docker/exceptions/DockerContainerNotFoundException.d.ts +9 -0
  37. package/dist/cjs/docker/exceptions/DockerContainerNotFoundException.js +16 -0
  38. package/dist/cjs/docker/exceptions/DockerImageBuildException.d.ts +9 -0
  39. package/dist/cjs/docker/exceptions/DockerImageBuildException.js +16 -0
  40. package/dist/cjs/docker/exceptions/DockerImageImportException.d.ts +9 -0
  41. package/dist/cjs/docker/exceptions/DockerImageImportException.js +16 -0
  42. package/dist/cjs/docker/exceptions/DockerImageNotFoundException.d.ts +10 -0
  43. package/dist/cjs/docker/exceptions/DockerImageNotFoundException.js +17 -0
  44. package/dist/cjs/docker/exceptions/DockerImagePullException.d.ts +9 -0
  45. package/dist/cjs/docker/exceptions/DockerImagePullException.js +16 -0
  46. package/dist/cjs/docker/exceptions/DockerImagePushException.d.ts +8 -0
  47. package/dist/cjs/docker/exceptions/DockerImagePushException.js +15 -0
  48. package/dist/cjs/docker/exceptions/DockerImageRepoTagNotFoundException.d.ts +8 -0
  49. package/dist/cjs/docker/exceptions/DockerImageRepoTagNotFoundException.js +15 -0
  50. package/dist/cjs/docker/exceptions/DockerNetworkNotFoundException.d.ts +9 -0
  51. package/dist/cjs/docker/exceptions/DockerNetworkNotFoundException.js +16 -0
  52. package/dist/cjs/docker/exceptions/DockerRequestException.d.ts +22 -0
  53. package/dist/cjs/docker/exceptions/DockerRequestException.js +24 -0
  54. package/dist/cjs/docker/interfaces/IDockerConnectionOptions.d.ts +75 -0
  55. package/dist/cjs/docker/interfaces/IDockerConnectionOptions.js +2 -0
  56. package/dist/cjs/docker/interfaces/IDockerHttpConnectionOptions.d.ts +16 -0
  57. package/dist/cjs/docker/interfaces/IDockerHttpConnectionOptions.js +2 -0
  58. package/dist/cjs/docker/interfaces/IDockerHttpsConnectionOptions.d.ts +16 -0
  59. package/dist/cjs/docker/interfaces/IDockerHttpsConnectionOptions.js +2 -0
  60. package/dist/cjs/docker/interfaces/IDockerKeyObject.d.ts +14 -0
  61. package/dist/cjs/docker/interfaces/IDockerKeyObject.js +2 -0
  62. package/dist/cjs/docker/interfaces/IDockerSSHConnectionOptions.d.ts +16 -0
  63. package/dist/cjs/docker/interfaces/IDockerSSHConnectionOptions.js +2 -0
  64. package/dist/cjs/docker/interfaces/IDockerSocketConnectionOptions.d.ts +7 -0
  65. package/dist/cjs/docker/interfaces/IDockerSocketConnectionOptions.js +2 -0
  66. package/dist/cjs/docker/lib/DockerContainer.d.ts +315 -0
  67. package/dist/cjs/docker/lib/DockerContainer.js +742 -0
  68. package/dist/cjs/docker/lib/DockerContainerTTY.d.ts +99 -0
  69. package/dist/cjs/docker/lib/DockerContainerTTY.js +157 -0
  70. package/dist/cjs/docker/lib/DockerImage.d.ts +153 -0
  71. package/dist/cjs/docker/lib/DockerImage.js +273 -0
  72. package/dist/cjs/docker/lib/EngineSettings.d.ts +41 -0
  73. package/dist/cjs/docker/lib/EngineSettings.js +86 -0
  74. package/dist/cjs/docker/lib/ParseBaseImages.d.ts +9 -0
  75. package/dist/cjs/docker/lib/ParseBaseImages.js +50 -0
  76. package/dist/cjs/docker/lib/ParseEnvToRecord.d.ts +14 -0
  77. package/dist/cjs/docker/lib/ParseEnvToRecord.js +25 -0
  78. package/dist/cjs/docker/lib/ParseRepositoryTag.d.ts +17 -0
  79. package/dist/cjs/docker/lib/ParseRepositoryTag.js +48 -0
  80. package/dist/cjs/docker/lib/RegistryAuth.d.ts +8 -0
  81. package/dist/cjs/docker/lib/RegistryAuth.js +15 -0
  82. package/dist/cjs/docker/options/DockerPruneOptions.d.ts +38 -0
  83. package/dist/cjs/docker/options/DockerPruneOptions.js +47 -0
  84. package/dist/cjs/docker/options/auth/DockerAuthOptions.d.ts +46 -0
  85. package/dist/cjs/docker/options/auth/DockerAuthOptions.js +59 -0
  86. package/dist/cjs/docker/options/container/ContainerCommitOptions.d.ts +28 -0
  87. package/dist/cjs/docker/options/container/ContainerCommitOptions.js +39 -0
  88. package/dist/cjs/docker/options/container/ContainerCreateTTYOptions.d.ts +32 -0
  89. package/dist/cjs/docker/options/container/ContainerCreateTTYOptions.js +43 -0
  90. package/dist/cjs/docker/options/container/ContainerExecOptions.d.ts +26 -0
  91. package/dist/cjs/docker/options/container/ContainerExecOptions.js +38 -0
  92. package/dist/cjs/docker/options/container/ContainerExportDirectoryOptions.d.ts +27 -0
  93. package/dist/cjs/docker/options/container/ContainerExportDirectoryOptions.js +39 -0
  94. package/dist/cjs/docker/options/container/ContainerKillOptions.d.ts +25 -0
  95. package/dist/cjs/docker/options/container/ContainerKillOptions.js +36 -0
  96. package/dist/cjs/docker/options/container/ContainerLogsOptions.d.ts +48 -0
  97. package/dist/cjs/docker/options/container/ContainerLogsOptions.js +56 -0
  98. package/dist/cjs/docker/options/container/ContainerRemoveOptions.d.ts +22 -0
  99. package/dist/cjs/docker/options/container/ContainerRemoveOptions.js +34 -0
  100. package/dist/cjs/docker/options/container/ContainerSettingOptions.d.ts +137 -0
  101. package/dist/cjs/docker/options/container/ContainerSettingOptions.js +136 -0
  102. package/dist/cjs/docker/options/container/ContainerStopOptions.d.ts +28 -0
  103. package/dist/cjs/docker/options/container/ContainerStopOptions.js +40 -0
  104. package/dist/cjs/docker/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
  105. package/dist/cjs/docker/options/container/ContainerTTYConsoleSizeOptions.js +40 -0
  106. package/dist/cjs/docker/options/image/ImageBuildOptions.d.ts +117 -0
  107. package/dist/cjs/docker/options/image/ImageBuildOptions.js +111 -0
  108. package/dist/cjs/docker/options/image/ImageExportOptions.d.ts +33 -0
  109. package/dist/cjs/docker/options/image/ImageExportOptions.js +44 -0
  110. package/dist/cjs/docker/options/image/ImageImportOptions.d.ts +28 -0
  111. package/dist/cjs/docker/options/image/ImageImportOptions.js +42 -0
  112. package/dist/cjs/docker/options/image/ImagePullOptions.d.ts +49 -0
  113. package/dist/cjs/docker/options/image/ImagePullOptions.js +63 -0
  114. package/dist/cjs/docker/options/image/ImagePushOptions.d.ts +41 -0
  115. package/dist/cjs/docker/options/image/ImagePushOptions.js +56 -0
  116. package/dist/cjs/docker/options/image/ImageRemoveOptions.d.ts +26 -0
  117. package/dist/cjs/docker/options/image/ImageRemoveOptions.js +38 -0
  118. package/dist/cjs/docker/options/image/ImageTagOptions.d.ts +25 -0
  119. package/dist/cjs/docker/options/image/ImageTagOptions.js +38 -0
  120. package/dist/cjs/docker/options/network/NetworkCreateOptions.d.ts +54 -0
  121. package/dist/cjs/docker/options/network/NetworkCreateOptions.js +63 -0
  122. package/dist/cjs/docker/types/ContainerBind.d.ts +19 -0
  123. package/dist/cjs/docker/types/ContainerBind.js +2 -0
  124. package/dist/cjs/docker/types/ContainerCapability.d.ts +286 -0
  125. package/dist/cjs/docker/types/ContainerCapability.js +290 -0
  126. package/dist/cjs/docker/types/ContainerConfig.d.ts +67 -0
  127. package/dist/cjs/docker/types/ContainerConfig.js +2 -0
  128. package/dist/cjs/docker/types/ContainerDevice.d.ts +19 -0
  129. package/dist/cjs/docker/types/ContainerDevice.js +2 -0
  130. package/dist/cjs/docker/types/ContainerExecResult.d.ts +20 -0
  131. package/dist/cjs/docker/types/ContainerExecResult.js +2 -0
  132. package/dist/cjs/docker/types/ContainerNetwork.d.ts +46 -0
  133. package/dist/cjs/docker/types/ContainerNetwork.js +2 -0
  134. package/dist/cjs/docker/types/ContainerPort.d.ts +25 -0
  135. package/dist/cjs/docker/types/ContainerPort.js +2 -0
  136. package/dist/cjs/docker/types/ContainerRestartPolicy.d.ts +11 -0
  137. package/dist/cjs/docker/types/ContainerRestartPolicy.js +2 -0
  138. package/dist/cjs/docker/types/ContainerState.d.ts +48 -0
  139. package/dist/cjs/docker/types/ContainerState.js +2 -0
  140. package/dist/cjs/docker/types/ContainerStats.d.ts +408 -0
  141. package/dist/cjs/docker/types/ContainerStats.js +2 -0
  142. package/dist/cjs/docker/types/DockerOutputCallback.d.ts +8 -0
  143. package/dist/cjs/docker/types/DockerOutputCallback.js +2 -0
  144. package/dist/cjs/docker/types/ImageConfig.d.ts +34 -0
  145. package/dist/cjs/docker/types/ImageConfig.js +2 -0
  146. package/dist/cjs/docker/types/ImageExposePort.d.ts +17 -0
  147. package/dist/cjs/docker/types/ImageExposePort.js +2 -0
  148. package/dist/cjs/docker/types/NetworkInfo.d.ts +59 -0
  149. package/dist/cjs/docker/types/NetworkInfo.js +2 -0
  150. package/dist/cjs/docker/types/RepositoryTag.d.ts +15 -0
  151. package/dist/cjs/docker/types/RepositoryTag.js +2 -0
  152. package/dist/cjs/exports/Docker.d.ts +73 -0
  153. package/dist/cjs/exports/Docker.js +92 -0
  154. package/dist/cjs/package.json +1 -0
  155. package/dist/esm/client/BuildContext.js +70 -0
  156. package/dist/esm/client/BuildKitProgress.js +190 -0
  157. package/dist/esm/client/DockerClient.js +307 -0
  158. package/dist/esm/client/DockerConnection.js +355 -0
  159. package/dist/esm/client/DockerIgnore.js +179 -0
  160. package/dist/esm/client/DockerRequestError.js +20 -0
  161. package/dist/esm/client/DockerStreams.js +111 -0
  162. package/dist/esm/client/types/ContainerCreateResponse.js +1 -0
  163. package/dist/esm/client/types/ContainerStopQuery.js +1 -0
  164. package/dist/esm/client/types/DeviceMapping.js +1 -0
  165. package/dist/esm/client/types/IdResponse.js +1 -0
  166. package/dist/esm/client/types/NetworkCreateResponse.js +1 -0
  167. package/dist/esm/client/types/PortBinding.js +1 -0
  168. package/dist/esm/docker/ConnectionOptionsBuilder.js +142 -0
  169. package/dist/esm/docker/Docker.js +697 -0
  170. package/dist/esm/docker/exceptions/DockerConnectionException.js +12 -0
  171. package/dist/esm/docker/exceptions/DockerContainerNotFoundException.js +12 -0
  172. package/dist/esm/docker/exceptions/DockerImageBuildException.js +12 -0
  173. package/dist/esm/docker/exceptions/DockerImageImportException.js +12 -0
  174. package/dist/esm/docker/exceptions/DockerImageNotFoundException.js +13 -0
  175. package/dist/esm/docker/exceptions/DockerImagePullException.js +12 -0
  176. package/dist/esm/docker/exceptions/DockerImagePushException.js +11 -0
  177. package/dist/esm/docker/exceptions/DockerImageRepoTagNotFoundException.js +11 -0
  178. package/dist/esm/docker/exceptions/DockerNetworkNotFoundException.js +12 -0
  179. package/dist/esm/docker/exceptions/DockerRequestException.js +20 -0
  180. package/dist/esm/docker/interfaces/IDockerConnectionOptions.js +1 -0
  181. package/dist/esm/docker/interfaces/IDockerHttpConnectionOptions.js +1 -0
  182. package/dist/esm/docker/interfaces/IDockerHttpsConnectionOptions.js +1 -0
  183. package/dist/esm/docker/interfaces/IDockerKeyObject.js +1 -0
  184. package/dist/esm/docker/interfaces/IDockerSSHConnectionOptions.js +1 -0
  185. package/dist/esm/docker/interfaces/IDockerSocketConnectionOptions.js +1 -0
  186. package/dist/esm/docker/lib/DockerContainer.js +739 -0
  187. package/dist/esm/docker/lib/DockerContainerTTY.js +154 -0
  188. package/dist/esm/docker/lib/DockerImage.js +270 -0
  189. package/dist/esm/docker/lib/EngineSettings.js +78 -0
  190. package/dist/esm/docker/lib/ParseBaseImages.js +47 -0
  191. package/dist/esm/docker/lib/ParseEnvToRecord.js +22 -0
  192. package/dist/esm/docker/lib/ParseRepositoryTag.js +45 -0
  193. package/dist/esm/docker/lib/RegistryAuth.js +12 -0
  194. package/dist/esm/docker/options/DockerPruneOptions.js +43 -0
  195. package/dist/esm/docker/options/auth/DockerAuthOptions.js +55 -0
  196. package/dist/esm/docker/options/container/ContainerCommitOptions.js +35 -0
  197. package/dist/esm/docker/options/container/ContainerCreateTTYOptions.js +39 -0
  198. package/dist/esm/docker/options/container/ContainerExecOptions.js +34 -0
  199. package/dist/esm/docker/options/container/ContainerExportDirectoryOptions.js +35 -0
  200. package/dist/esm/docker/options/container/ContainerKillOptions.js +32 -0
  201. package/dist/esm/docker/options/container/ContainerLogsOptions.js +52 -0
  202. package/dist/esm/docker/options/container/ContainerRemoveOptions.js +30 -0
  203. package/dist/esm/docker/options/container/ContainerSettingOptions.js +132 -0
  204. package/dist/esm/docker/options/container/ContainerStopOptions.js +36 -0
  205. package/dist/esm/docker/options/container/ContainerTTYConsoleSizeOptions.js +36 -0
  206. package/dist/esm/docker/options/image/ImageBuildOptions.js +107 -0
  207. package/dist/esm/docker/options/image/ImageExportOptions.js +40 -0
  208. package/dist/esm/docker/options/image/ImageImportOptions.js +38 -0
  209. package/dist/esm/docker/options/image/ImagePullOptions.js +59 -0
  210. package/dist/esm/docker/options/image/ImagePushOptions.js +52 -0
  211. package/dist/esm/docker/options/image/ImageRemoveOptions.js +34 -0
  212. package/dist/esm/docker/options/image/ImageTagOptions.js +34 -0
  213. package/dist/esm/docker/options/network/NetworkCreateOptions.js +59 -0
  214. package/dist/esm/docker/types/ContainerBind.js +1 -0
  215. package/dist/esm/docker/types/ContainerCapability.js +287 -0
  216. package/dist/esm/docker/types/ContainerConfig.js +1 -0
  217. package/dist/esm/docker/types/ContainerDevice.js +1 -0
  218. package/dist/esm/docker/types/ContainerExecResult.js +1 -0
  219. package/dist/esm/docker/types/ContainerNetwork.js +1 -0
  220. package/dist/esm/docker/types/ContainerPort.js +1 -0
  221. package/dist/esm/docker/types/ContainerRestartPolicy.js +1 -0
  222. package/dist/esm/docker/types/ContainerState.js +1 -0
  223. package/dist/esm/docker/types/ContainerStats.js +1 -0
  224. package/dist/esm/docker/types/DockerOutputCallback.js +1 -0
  225. package/dist/esm/docker/types/ImageConfig.js +1 -0
  226. package/dist/esm/docker/types/ImageExposePort.js +1 -0
  227. package/dist/esm/docker/types/NetworkInfo.js +1 -0
  228. package/dist/esm/docker/types/RepositoryTag.js +1 -0
  229. package/dist/esm/exports/Docker.js +73 -0
  230. package/dist/types/client/BuildContext.d.ts +22 -0
  231. package/dist/types/client/BuildKitProgress.d.ts +81 -0
  232. package/dist/types/client/DockerClient.d.ts +196 -0
  233. package/dist/types/client/DockerConnection.d.ts +154 -0
  234. package/dist/types/client/DockerIgnore.d.ts +44 -0
  235. package/dist/types/client/DockerRequestError.d.ts +17 -0
  236. package/dist/types/client/DockerStreams.d.ts +35 -0
  237. package/dist/types/client/types/ContainerCreateResponse.d.ts +7 -0
  238. package/dist/types/client/types/ContainerStopQuery.d.ts +13 -0
  239. package/dist/types/client/types/DeviceMapping.d.ts +8 -0
  240. package/dist/types/client/types/IdResponse.d.ts +6 -0
  241. package/dist/types/client/types/NetworkCreateResponse.d.ts +7 -0
  242. package/dist/types/client/types/PortBinding.d.ts +10 -0
  243. package/dist/types/docker/ConnectionOptionsBuilder.d.ts +128 -0
  244. package/dist/types/docker/Docker.d.ts +301 -0
  245. package/dist/types/docker/exceptions/DockerConnectionException.d.ts +9 -0
  246. package/dist/types/docker/exceptions/DockerContainerNotFoundException.d.ts +9 -0
  247. package/dist/types/docker/exceptions/DockerImageBuildException.d.ts +9 -0
  248. package/dist/types/docker/exceptions/DockerImageImportException.d.ts +9 -0
  249. package/dist/types/docker/exceptions/DockerImageNotFoundException.d.ts +10 -0
  250. package/dist/types/docker/exceptions/DockerImagePullException.d.ts +9 -0
  251. package/dist/types/docker/exceptions/DockerImagePushException.d.ts +8 -0
  252. package/dist/types/docker/exceptions/DockerImageRepoTagNotFoundException.d.ts +8 -0
  253. package/dist/types/docker/exceptions/DockerNetworkNotFoundException.d.ts +9 -0
  254. package/dist/types/docker/exceptions/DockerRequestException.d.ts +22 -0
  255. package/dist/types/docker/interfaces/IDockerConnectionOptions.d.ts +75 -0
  256. package/dist/types/docker/interfaces/IDockerHttpConnectionOptions.d.ts +16 -0
  257. package/dist/types/docker/interfaces/IDockerHttpsConnectionOptions.d.ts +16 -0
  258. package/dist/types/docker/interfaces/IDockerKeyObject.d.ts +14 -0
  259. package/dist/types/docker/interfaces/IDockerSSHConnectionOptions.d.ts +16 -0
  260. package/dist/types/docker/interfaces/IDockerSocketConnectionOptions.d.ts +7 -0
  261. package/dist/types/docker/lib/DockerContainer.d.ts +315 -0
  262. package/dist/types/docker/lib/DockerContainerTTY.d.ts +99 -0
  263. package/dist/types/docker/lib/DockerImage.d.ts +153 -0
  264. package/dist/types/docker/lib/EngineSettings.d.ts +41 -0
  265. package/dist/types/docker/lib/ParseBaseImages.d.ts +9 -0
  266. package/dist/types/docker/lib/ParseEnvToRecord.d.ts +14 -0
  267. package/dist/types/docker/lib/ParseRepositoryTag.d.ts +17 -0
  268. package/dist/types/docker/lib/RegistryAuth.d.ts +8 -0
  269. package/dist/types/docker/options/DockerPruneOptions.d.ts +38 -0
  270. package/dist/types/docker/options/auth/DockerAuthOptions.d.ts +46 -0
  271. package/dist/types/docker/options/container/ContainerCommitOptions.d.ts +28 -0
  272. package/dist/types/docker/options/container/ContainerCreateTTYOptions.d.ts +32 -0
  273. package/dist/types/docker/options/container/ContainerExecOptions.d.ts +26 -0
  274. package/dist/types/docker/options/container/ContainerExportDirectoryOptions.d.ts +27 -0
  275. package/dist/types/docker/options/container/ContainerKillOptions.d.ts +25 -0
  276. package/dist/types/docker/options/container/ContainerLogsOptions.d.ts +48 -0
  277. package/dist/types/docker/options/container/ContainerRemoveOptions.d.ts +22 -0
  278. package/dist/types/docker/options/container/ContainerSettingOptions.d.ts +137 -0
  279. package/dist/types/docker/options/container/ContainerStopOptions.d.ts +28 -0
  280. package/dist/types/docker/options/container/ContainerTTYConsoleSizeOptions.d.ts +26 -0
  281. package/dist/types/docker/options/image/ImageBuildOptions.d.ts +117 -0
  282. package/dist/types/docker/options/image/ImageExportOptions.d.ts +33 -0
  283. package/dist/types/docker/options/image/ImageImportOptions.d.ts +28 -0
  284. package/dist/types/docker/options/image/ImagePullOptions.d.ts +49 -0
  285. package/dist/types/docker/options/image/ImagePushOptions.d.ts +41 -0
  286. package/dist/types/docker/options/image/ImageRemoveOptions.d.ts +26 -0
  287. package/dist/types/docker/options/image/ImageTagOptions.d.ts +25 -0
  288. package/dist/types/docker/options/network/NetworkCreateOptions.d.ts +54 -0
  289. package/dist/types/docker/types/ContainerBind.d.ts +19 -0
  290. package/dist/types/docker/types/ContainerCapability.d.ts +286 -0
  291. package/dist/types/docker/types/ContainerConfig.d.ts +67 -0
  292. package/dist/types/docker/types/ContainerDevice.d.ts +19 -0
  293. package/dist/types/docker/types/ContainerExecResult.d.ts +20 -0
  294. package/dist/types/docker/types/ContainerNetwork.d.ts +46 -0
  295. package/dist/types/docker/types/ContainerPort.d.ts +25 -0
  296. package/dist/types/docker/types/ContainerRestartPolicy.d.ts +11 -0
  297. package/dist/types/docker/types/ContainerState.d.ts +48 -0
  298. package/dist/types/docker/types/ContainerStats.d.ts +408 -0
  299. package/dist/types/docker/types/DockerOutputCallback.d.ts +8 -0
  300. package/dist/types/docker/types/ImageConfig.d.ts +34 -0
  301. package/dist/types/docker/types/ImageExposePort.d.ts +17 -0
  302. package/dist/types/docker/types/NetworkInfo.d.ts +59 -0
  303. package/dist/types/docker/types/RepositoryTag.d.ts +15 -0
  304. package/dist/types/exports/Docker.d.ts +73 -0
  305. package/package.json +57 -0
@@ -0,0 +1,697 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Component, DTO } from '@lakutata/core';
11
+ import { Singleton, Configurable } from '@lakutata/core/decorator/di';
12
+ import { DockerImage } from './lib/DockerImage.js';
13
+ import { DockerContainer } from './lib/DockerContainer.js';
14
+ import { DockerConnectionException } from './exceptions/DockerConnectionException.js';
15
+ import { DockerImageNotFoundException } from './exceptions/DockerImageNotFoundException.js';
16
+ import { ImagePullOptions } from './options/image/ImagePullOptions.js';
17
+ import { Accept } from '@lakutata/core/decorator/dto';
18
+ import { DockerImagePullException } from './exceptions/DockerImagePullException.js';
19
+ import { isAbortError } from '@lakutata/utils';
20
+ import { ImageBuildOptions } from './options/image/ImageBuildOptions.js';
21
+ import { DockerImageBuildException } from './exceptions/DockerImageBuildException.js';
22
+ import { ImageImportOptions } from './options/image/ImageImportOptions.js';
23
+ import { DockerImageImportException } from './exceptions/DockerImageImportException.js';
24
+ import { extract as tarExtract } from 'tar-stream';
25
+ import { createReadStream } from 'node:fs';
26
+ import { PassThrough } from 'node:stream';
27
+ import { NetworkCreateOptions } from './options/network/NetworkCreateOptions.js';
28
+ import { Time } from '@lakutata/utils/Time';
29
+ import { ContainerSettingOptions } from './options/container/ContainerSettingOptions.js';
30
+ import { DockerContainerTTY } from './lib/DockerContainerTTY.js';
31
+ import { DockerPruneOptions } from './options/DockerPruneOptions.js';
32
+ import { DockerAuthOptions } from './options/auth/DockerAuthOptions.js';
33
+ import { readFile } from 'node:fs/promises';
34
+ import path from 'node:path';
35
+ import { DockerClient } from '../client/DockerClient.js';
36
+ import { packBuildContext } from '../client/BuildContext.js';
37
+ import { BuildKitProgress, decodeBuildKitStatus } from '../client/BuildKitProgress.js';
38
+ import { followProgress } from '../client/DockerStreams.js';
39
+ import { parseBaseImages } from './lib/ParseBaseImages.js';
40
+ import { DockerContainerNotFoundException } from './exceptions/DockerContainerNotFoundException.js';
41
+ import { registryAuth } from './lib/RegistryAuth.js';
42
+ import { engineBinds, engineDevices, engineEndpoints, enginePortBindings, engineRestartPolicy } from './lib/EngineSettings.js';
43
+ /**
44
+ * The Docker component: drives a Docker daemon over the Docker Engine API, to pull, build, import, export, tag and push
45
+ * images, to create, run and manage containers (exec, TTYs, logs, stats, commit, archives) and to manage networks.
46
+ * Register it in the `components` of an application (`{class: Docker}`, or the result of one of the
47
+ * `BuildDocker*ConnectionOptions` functions) and get it with `getObject()` or `@Inject`; it is a singleton.
48
+ *
49
+ * Without `socketPath` nor `host`, it connects to the Docker of the environment: `DOCKER_HOST` (with
50
+ * `DOCKER_TLS_VERIFY`, `DOCKER_CERT_PATH` and `DOCKER_CLIENT_TIMEOUT`), else the named pipe `//./pipe/docker_engine` on
51
+ * Windows, the socket of Docker Desktop (`~/.docker/run/docker.sock`) when it exists, or `/var/run/docker.sock`; the
52
+ * other options given (`timeout`, `headers`, `version`…) apply over the environment's. No Docker CLI is needed locally
53
+ * (the SSH connections need it on the remote host).
54
+ *
55
+ * When it is created, the component pings the daemon and negotiates the API version (the newest one supported by both,
56
+ * from 1.41 to 1.56): a daemon which cannot be reached fails its creation with {@link DockerConnectionException}.
57
+ * Afterwards, a daemon which cannot be reached rejects the calls with the network error of Node.js (`ECONNREFUSED`,
58
+ * `ENOENT`…). A request the daemon refuses rejects with the exception of what is missing
59
+ * ({@link DockerContainerNotFoundException}, {@link DockerImageNotFoundException},
60
+ * {@link DockerNetworkNotFoundException}), else with a {@link DockerRequestException}, whose `statusCode` is the HTTP
61
+ * status and whose message is the daemon's. The pulls, builds, imports and pushes wrap their failures in their own
62
+ * exceptions ({@link DockerImagePullException}…).
63
+ *
64
+ * When the component is destroyed (the application stopping), the pulls and builds in progress are aborted (they reject
65
+ * with their exception), the listings in progress resolve with an empty list, and its connections are closed.
66
+ * @example
67
+ * ```typescript
68
+ * import {Application} from 'lakutata'
69
+ * import {Docker, type DockerContainer, type DockerImage} from 'lakutata/com/docker'
70
+ *
71
+ * Application
72
+ * .run(() => ({
73
+ * id: 'docker.app',
74
+ * name: 'Docker',
75
+ * components: {
76
+ * //The Docker of the environment: DOCKER_HOST, else the local socket
77
+ * docker: {class: Docker}
78
+ * }
79
+ * }))
80
+ * .onLaunched(async (app: Application): Promise<void> => {
81
+ * const docker: Docker = await app.getObject('docker')
82
+ * const image: DockerImage = await docker.pullImage({repo: 'alpine', tag: '3.20'})
83
+ * //Created, then started
84
+ * const container: DockerContainer = await image.run({name: 'hello', cmd: ['sleep', '60']})
85
+ * console.log((await container.exec({cmd: ['echo', 'hello']})).stdout)
86
+ * await container.remove({force: true})
87
+ * })
88
+ * ```
89
+ */
90
+ let Docker = class Docker extends Component {
91
+ #client;
92
+ #abortController = new AbortController();
93
+ #internalNetworkNames = ['bridge', 'host', 'none'];
94
+ /**
95
+ * Connect to the daemon: ping it, then negotiate the API version.
96
+ * @throws {DockerConnectionException} When the daemon cannot be reached or does not answer, or when an SSH
97
+ * connection is configured without the package `ssh2`.
98
+ * @protected
99
+ */
100
+ async init() {
101
+ await Promise.all([
102
+ this.container.register(DockerImage),
103
+ this.container.register(DockerContainer),
104
+ this.container.register(DockerContainerTTY)
105
+ ]);
106
+ //Without a socket nor a host, the Docker of the environment (DOCKER_HOST, the socket of Docker Desktop or of the
107
+ //system, the named pipe of Windows), with the options given applied over it
108
+ this.#client = new DockerClient({
109
+ socketPath: this.socketPath,
110
+ host: this.host,
111
+ port: this.port,
112
+ username: this.username,
113
+ headers: this.headers,
114
+ ca: this.ca,
115
+ cert: this.cert,
116
+ key: this.key,
117
+ protocol: this.protocol,
118
+ timeout: this.timeout,
119
+ version: this.version,
120
+ sshAuthAgent: this.sshAuthAgent
121
+ });
122
+ try {
123
+ await this.#client.ping();
124
+ //The API version of the requests: the newest one supported by the daemon and this client
125
+ await this.#client.connection.negotiate();
126
+ }
127
+ catch (e) {
128
+ throw new DockerConnectionException(e.message ? e.message : 'Cannot connect to docker');
129
+ }
130
+ }
131
+ /**
132
+ * Abort the pulls, builds and listings in progress (the pulls and builds then reject), then close the connections
133
+ * to the daemon.
134
+ * @protected
135
+ */
136
+ async destroy() {
137
+ this.#abortController.abort();
138
+ this.#client?.close();
139
+ }
140
+ /** Docker Common Operations **/
141
+ /**
142
+ * Remove the daemon's unused resources, as `docker <kind> prune` does without options: the stopped containers, then
143
+ * the dangling images (untagged and unused), the unused networks and the unused anonymous volumes. Without
144
+ * options, the containers and the images are pruned; the networks and the volumes only when asked.
145
+ * @param options The kinds of resources pruned: `containers` and `images` default to `true`, `networks` and
146
+ * `volumes` to `false`.
147
+ * @throws {InvalidMethodAcceptException} When the options are invalid.
148
+ * @throws {DockerRequestException} When the daemon refuses a prune (one already running: HTTP 409).
149
+ */
150
+ async prune(options) {
151
+ if (!options)
152
+ return await this.prune({});
153
+ if (options.containers)
154
+ await this.#client.pruneContainers();
155
+ if (options.images)
156
+ await this.#client.pruneImages();
157
+ if (options.networks)
158
+ await this.#client.pruneNetworks();
159
+ if (options.volumes)
160
+ await this.#client.pruneVolumes();
161
+ }
162
+ /**
163
+ * Check credentials against a registry, as `docker login` does. The credentials are not kept: each pull, build or
164
+ * push which needs them is given its own `auth`.
165
+ * @param options The registry (`serverAddress`, a host name without protocol: `registry.example.com:5000`) and its
166
+ * credentials (a password, or a token).
167
+ * @throws {DockerRequestException} When the registry refuses the credentials or cannot be reached (the daemon's
168
+ * status: HTTP 401, 500).
169
+ */
170
+ async loginRepository(options) {
171
+ await this.#client.checkAuth(registryAuth(options));
172
+ }
173
+ /**
174
+ * Whether a registry accepts credentials ({@link Docker.loginRepository} without its error).
175
+ * @param options The registry (`serverAddress`, a host name without protocol) and its credentials.
176
+ * @returns `true` when they are accepted; `false` on any failure, the daemon unreachable included.
177
+ */
178
+ async checkRepositoryAuth(options) {
179
+ try {
180
+ await this.loginRepository(options);
181
+ return true;
182
+ }
183
+ catch (e) {
184
+ return false;
185
+ }
186
+ }
187
+ /** Docker Image Operations **/
188
+ /**
189
+ * List the daemon's images (as `docker images`, without the intermediate ones). Each image is inspected with a request
190
+ * of its own, so the call costs one request per image; an image removed during the listing is not listed.
191
+ * @returns The images, in the daemon's order.
192
+ */
193
+ async listImages() {
194
+ const rawImages = await this.#client.listImages();
195
+ const images = await Promise.all(rawImages.map(async (rawImage) => {
196
+ try {
197
+ return await this.#image(rawImage.Id);
198
+ }
199
+ catch (e) {
200
+ //Removed since it was listed
201
+ if (e instanceof DockerImageNotFoundException)
202
+ return undefined;
203
+ throw e;
204
+ }
205
+ }));
206
+ return images.filter((image) => !!image);
207
+ }
208
+ /**
209
+ * The object of an image, inspected
210
+ * @param id
211
+ */
212
+ async #image(id) {
213
+ return await this.container.get(DockerImage, {
214
+ id: id,
215
+ getClient: () => this.#client,
216
+ getDocker: () => this
217
+ });
218
+ }
219
+ /**
220
+ * Pull an image from its registry, as `docker pull`, and wait for its end.
221
+ * @param options The repository (`alpine`, `registry.example.com:5000/team/app`), the tag (`'latest'` by default),
222
+ * the platform (`linux/arm64`, the daemon's by default), the registry credentials, and a callback receiving each
223
+ * progress message.
224
+ * @returns The image pulled, found as `repo:tag` the way the daemon names it (`docker.io/library/alpine` is
225
+ * `alpine`).
226
+ * @throws {DockerImagePullException} When the pull fails: the image or the registry not found, refused credentials,
227
+ * the daemon unreachable, or the component destroyed during the pull (its message then says it was aborted).
228
+ */
229
+ async pullImage(options) {
230
+ const auth = registryAuth(options.auth);
231
+ const tag = options.tag ? options.tag : 'latest';
232
+ try {
233
+ const readableStream = await this.#client.pullImage({ fromImage: options.repo, tag: tag, platform: options.platform }, auth, this.#abortController.signal);
234
+ let pullError;
235
+ await followProgress(readableStream, (outputObject) => {
236
+ if (options.outputCallback)
237
+ options.outputCallback(outputObject);
238
+ if (outputObject.error && !pullError)
239
+ pullError = outputObject.error;
240
+ });
241
+ if (pullError)
242
+ throw new Error(pullError);
243
+ //A tag or a digest
244
+ return await this.getImage(tag.includes(':') ? `${options.repo}@${tag}` : `${options.repo}:${tag}`);
245
+ }
246
+ catch (e) {
247
+ if (isAbortError(e))
248
+ throw new DockerImagePullException('The pull of {0} was aborted: the Docker component was destroyed', [options.repo]);
249
+ throw new DockerImagePullException(e.message);
250
+ }
251
+ }
252
+ /**
253
+ * Build an image with BuildKit, as `docker build`, and wait for its end. The build context is made of the `files`
254
+ * of the `workdir` (relative paths; a directory with its content), without the ones its `.dockerignore` excludes,
255
+ * and always with the Dockerfile. The progress is given to the output callback as the lines of
256
+ * `docker build --progress=plain` (`{id: 'moby.buildkit.trace', stream: '#2 [1/2] FROM alpine'}`).
257
+ *
258
+ * With `auth`, the base images of the Dockerfile (its `FROM` lines) are pulled first with these credentials, as
259
+ * BuildKit is not given them.
260
+ * @param options The context (`workdir`, `files`), the Dockerfile, the name of the image (`repoTag`; a generated
261
+ * `unnamed_img_…` name by default), the platform, the target stage, the build arguments, the registry credentials
262
+ * and the output callback.
263
+ * @returns The image built.
264
+ * @throws {DockerImageBuildException} When the build fails: a step failing, the Dockerfile or a file of the context
265
+ * missing, a base image which cannot be pulled, the daemon unreachable, or the component destroyed during the build
266
+ * (its message then says it was aborted).
267
+ */
268
+ async buildImage(options) {
269
+ const dockerfile = options.dockerfile ? options.dockerfile : 'Dockerfile';
270
+ const auth = registryAuth(options.auth);
271
+ try {
272
+ //The base images of a private registry are pulled with the credentials (BuildKit is not given them)
273
+ if (auth) {
274
+ const content = await readFile(path.resolve(options.workdir, dockerfile), { encoding: 'utf-8' });
275
+ for (const baseImage of parseBaseImages(content, options.buildargs)) {
276
+ const [repo, tag] = [baseImage.replace(/:([^:/@]+)$/, ''), /:([^:/@]+)$/.exec(baseImage)?.[1]];
277
+ await this.pullImage({ repo: repo, tag: tag, platform: options.platform, auth: options.auth, outputCallback: options.outputCallback });
278
+ }
279
+ }
280
+ const context = packBuildContext({ directory: options.workdir, entries: options.files, always: [dockerfile] });
281
+ const registryConfig = auth ? { [auth.serveraddress ?? 'https://index.docker.io/v1/']: auth } : undefined;
282
+ const readableStream = await this.#client.buildImage(context, {
283
+ dockerfile: dockerfile,
284
+ t: options.repoTag ? options.repoTag : `unnamed_img_${Date.now().toString(16)}${Math.floor(Math.random() * 255).toString(16).padStart(2, '0')}`,
285
+ remote: options.remote,
286
+ q: options.quiet || options.quite,
287
+ nocache: options.nocache,
288
+ rm: options.rm,
289
+ forcerm: options.forcerm,
290
+ platform: options.platform,
291
+ target: options.target,
292
+ shmsize: options.shmsize,
293
+ buildargs: options.buildargs,
294
+ version: '2'
295
+ }, registryConfig, this.#abortController.signal);
296
+ const progress = new BuildKitProgress();
297
+ let imageId;
298
+ let buildError;
299
+ await followProgress(readableStream, (outputObject) => {
300
+ if (outputObject.error && !buildError)
301
+ buildError = outputObject.error;
302
+ if (outputObject.id === 'moby.buildkit.trace' && typeof outputObject.aux === 'string') {
303
+ for (const line of progress.lines(decodeBuildKitStatus(outputObject.aux)))
304
+ options.outputCallback?.({ id: outputObject.id, stream: line });
305
+ return;
306
+ }
307
+ if (outputObject.aux && typeof outputObject.aux === 'object' && outputObject.aux.ID)
308
+ imageId = outputObject.aux.ID;
309
+ options.outputCallback?.(outputObject);
310
+ });
311
+ if (buildError)
312
+ throw new DockerImageBuildException(buildError);
313
+ if (!imageId)
314
+ throw new DockerImageBuildException('Build image failed');
315
+ return await this.getImage(imageId);
316
+ }
317
+ catch (e) {
318
+ if (isAbortError(e))
319
+ throw new DockerImageBuildException('The build was aborted: the Docker component was destroyed');
320
+ if (e instanceof DockerImageBuildException)
321
+ throw e;
322
+ throw new DockerImageBuildException(e.message);
323
+ }
324
+ }
325
+ /**
326
+ * Load an image from a tar archive written by `docker save` (or {@link DockerImage.export}), as `docker load`. The
327
+ * tags saved in the archive are restored.
328
+ * @param options The archive (`source`, a file path or a readable stream) and `quiet` (`false` by default).
329
+ * @returns The image loaded.
330
+ * @throws {DockerImageImportException} When the daemon rejects the archive, or when the loaded image is unknown.
331
+ * @throws {Error} The error of the source when it cannot be read (`ENOENT` for a missing file), or the network
332
+ * error when the archive cannot be sent.
333
+ * @throws {DockerRequestException} When the daemon refuses the request.
334
+ */
335
+ async importImage(options) {
336
+ const imageSourceReadableStream = typeof options.source === 'string' ? createReadStream(options.source) : options.source;
337
+ const tarExtractPassThrough = new PassThrough();
338
+ const loadImagePassThrough = new PassThrough();
339
+ //An error of the source (a file which cannot be opened) fails the request sending it, then the call
340
+ let sourceError;
341
+ loadImagePassThrough.on('error', () => undefined);
342
+ imageSourceReadableStream.once('error', (error) => {
343
+ sourceError = error;
344
+ tarExtractPassThrough.destroy();
345
+ loadImagePassThrough.destroy(error);
346
+ });
347
+ imageSourceReadableStream.pipe(tarExtractPassThrough);
348
+ imageSourceReadableStream.pipe(loadImagePassThrough);
349
+ const tarExtractor = tarExtract();
350
+ //The manifest only completes the daemon's answer: an archive it cannot read is reported by the daemon
351
+ tarExtractor.on('error', () => undefined);
352
+ let manifestImageId;
353
+ tarExtractor
354
+ //The types of tar-stream are its own (3.2): the stream of the entry is the one of streamx
355
+ .on('entry', (header, stream, next) => {
356
+ if (header.name === 'manifest.json') {
357
+ const chunks = [];
358
+ stream.on('data', (chunk) => chunks.push(chunk));
359
+ stream.once('end', () => {
360
+ try {
361
+ const manifestObject = JSON.parse(Buffer.concat(chunks).toString())[0];
362
+ manifestImageId = manifestObject.Config.toString().replace('blobs/', '').replace('.json', '').replace('/', ':');
363
+ }
364
+ catch {
365
+ //Not a manifest of docker save
366
+ }
367
+ });
368
+ }
369
+ stream.on('end', () => next());
370
+ stream.resume();
371
+ });
372
+ tarExtractPassThrough.pipe(tarExtractor);
373
+ let importError;
374
+ let loadedImage;
375
+ try {
376
+ const readableStream = await this.#client.loadImage(loadImagePassThrough, { quiet: options.quiet });
377
+ await followProgress(readableStream, (outputObject) => {
378
+ if (outputObject.error && !importError)
379
+ importError = outputObject.error;
380
+ //"Loaded image ID: sha256:…" or "Loaded image: repo:tag"
381
+ const loaded = /Loaded image(?: ID)?: (\S+)/.exec(outputObject.stream ?? '');
382
+ if (loaded && !loadedImage)
383
+ loadedImage = loaded[1];
384
+ });
385
+ }
386
+ catch (e) {
387
+ throw sourceError ?? e;
388
+ }
389
+ if (sourceError)
390
+ throw sourceError;
391
+ if (importError)
392
+ throw new DockerImageImportException(importError);
393
+ const image = loadedImage ?? manifestImageId;
394
+ if (!image)
395
+ throw new DockerImageImportException('The imported image is unknown');
396
+ return await this.getImage(image);
397
+ }
398
+ /**
399
+ * Get an image by its ID or its name, resolved by the daemon as `docker image inspect` does: the full ID
400
+ * (`sha256:…`), a unique prefix of it (`d9e853e8`), a tag (`alpine:3.20`), a name without its tag for `:latest`
401
+ * (`alpine`), a name with its registry (`docker.io/library/alpine:3.20`) or a digest (`alpine@sha256:…`).
402
+ * @param repoTagOrId The ID, the short ID, the name or the digest of the image.
403
+ * @returns The image.
404
+ * @throws {DockerImageNotFoundException} When the daemon finds no image with this ID or name.
405
+ */
406
+ async getImage(repoTagOrId) {
407
+ const inspectInfo = await this.#client.inspectImage(repoTagOrId);
408
+ return await this.#image(inspectInfo.Id);
409
+ }
410
+ /** Docker Container Operations **/
411
+ /**
412
+ * List the daemon's containers, the stopped ones included (as `docker ps -a`). Each container is inspected, with its
413
+ * image (see {@link Docker.getContainer}); a container removed during the listing is not listed.
414
+ * @returns The containers; an empty list when the component is destroyed during the call.
415
+ */
416
+ async listContainers() {
417
+ try {
418
+ const rawContainers = await this.#client.listContainers({ all: true }, this.#abortController.signal);
419
+ const containers = await Promise.all(rawContainers.map(async (containerInfo) => {
420
+ try {
421
+ return await this.getContainer(containerInfo.Id);
422
+ }
423
+ catch (e) {
424
+ //Removed since it was listed
425
+ if (e instanceof DockerContainerNotFoundException)
426
+ return undefined;
427
+ throw e;
428
+ }
429
+ }));
430
+ return containers.filter((container) => !!container);
431
+ }
432
+ catch (e) {
433
+ if (!isAbortError(e))
434
+ throw e;
435
+ return [];
436
+ }
437
+ }
438
+ /**
439
+ * Get a container by its ID, short ID or name, inspected with its image (`image` is `undefined` when its image no
440
+ * longer exists, removed with force). The object is a snapshot: its properties are refreshed by its own operations
441
+ * (`start()`, `stop()`…), not by the changes made by others.
442
+ * @param id The ID, a unique prefix of it, or the name of the container.
443
+ * @returns The container.
444
+ * @throws {DockerContainerNotFoundException} When the daemon has no such container.
445
+ */
446
+ async getContainer(id) {
447
+ return await this.getObject(DockerContainer, {
448
+ getClient: () => this.#client,
449
+ getDocker: () => this,
450
+ id: id
451
+ });
452
+ }
453
+ async createContainer(imageId, platformOrOptions, settingOptions) {
454
+ //The platform is optional: the one of the image by default
455
+ const platform = typeof platformOrOptions === 'string' ? platformOrOptions : undefined;
456
+ const options = typeof platformOrOptions === 'string' ? settingOptions ?? {} : platformOrOptions;
457
+ const containerEnvRecord = options.env ? options.env : {};
458
+ const rawContainer = await this.#client.createContainer({
459
+ Image: imageId,
460
+ Hostname: options.hostname,
461
+ Tty: options.tty,
462
+ Env: Object.keys(containerEnvRecord).map(envKey => `${envKey}=${containerEnvRecord[envKey]}`),
463
+ Cmd: options.cmd,
464
+ Entrypoint: options.entrypoint,
465
+ HostConfig: {
466
+ Memory: options.memoryLimit,
467
+ CpusetCpus: options.cpuSet ? options.cpuSet.join(',') : undefined,
468
+ Privileged: options.privileged,
469
+ RestartPolicy: options.restartPolicy ? engineRestartPolicy(options.restartPolicy) : undefined,
470
+ OomKillDisable: options.OOMKillDisable,
471
+ PortBindings: enginePortBindings(options.ports ?? []),
472
+ Binds: engineBinds(options.binds ?? []),
473
+ Devices: engineDevices(options.devices ?? []),
474
+ CapAdd: options.capabilities,
475
+ Cgroup: options.cgroup,
476
+ CgroupParent: options.cgroupParent,
477
+ PidMode: options.pidMode
478
+ },
479
+ NetworkingConfig: {
480
+ EndpointsConfig: engineEndpoints(options.networks ?? [])
481
+ }
482
+ }, { name: options.name, platform: platform });
483
+ return await this.getContainer(rawContainer.Id);
484
+ }
485
+ /** Docker Network Operations **/
486
+ /**
487
+ * Create a network, as `docker network create`.
488
+ * @param options The name, the driver (`'bridge'` by default, `'ipvlan'`, `'macvlan'`), its options, the subnets
489
+ * (`NetworkIPAMConfigs`; chosen by the daemon when empty or absent), `internal` and `enableIPv6`.
490
+ * @returns The network created.
491
+ * @throws {DockerRequestException} When the daemon refuses the network: the name already used (HTTP 409), a subnet
492
+ * overlapping another network's (HTTP 400).
493
+ */
494
+ async createNetwork(options) {
495
+ const network = await this.#client.createNetwork({
496
+ Name: options.name,
497
+ Driver: options.driver,
498
+ Internal: options.internal,
499
+ Options: options.options,
500
+ IPAM: {
501
+ Driver: 'default',
502
+ Options: {},
503
+ Config: (options.NetworkIPAMConfigs ?? []).map((config) => ({
504
+ Subnet: config.subnet,
505
+ IPRange: config.range,
506
+ Gateway: config.gateway
507
+ }))
508
+ },
509
+ EnableIPv6: options.enableIPv6
510
+ });
511
+ return await this.getNetwork(network.Id);
512
+ }
513
+ /**
514
+ * Remove a network, as `docker network rm`.
515
+ * @param id The ID, a unique prefix of it, or the name of the network.
516
+ * @throws {DockerNetworkNotFoundException} When the daemon has no such network.
517
+ * @throws {DockerRequestException} When the network has containers connected (HTTP 409), or is reserved (`bridge`,
518
+ * `host`, `none`: HTTP 403).
519
+ */
520
+ async removeNetwork(id) {
521
+ const network = await this.getNetwork(id);
522
+ await this.#client.removeNetwork(network.id);
523
+ }
524
+ /**
525
+ * List the daemon's networks, the reserved ones (`bridge`, `host`, `none`) included.
526
+ * @returns The networks; an empty list when the component is destroyed during the call.
527
+ */
528
+ async listNetworks() {
529
+ try {
530
+ const rawNetworks = await this.#client.listNetworks(undefined, this.#abortController.signal);
531
+ return rawNetworks.map((rawNetwork) => this.#networkInfo(rawNetwork));
532
+ }
533
+ catch (e) {
534
+ if (!isAbortError(e))
535
+ throw e;
536
+ return [];
537
+ }
538
+ }
539
+ /**
540
+ * Get a network by its ID, a unique prefix of it, or its name, as `docker network inspect`.
541
+ * @param id The ID, a unique prefix of it, or the name of the network.
542
+ * @returns The network.
543
+ * @throws {DockerNetworkNotFoundException} When the daemon has no such network.
544
+ */
545
+ async getNetwork(id) {
546
+ return this.#networkInfo(await this.#client.inspectNetwork(id));
547
+ }
548
+ /**
549
+ * The information of a network, from the daemon's
550
+ * @param rawNetwork
551
+ */
552
+ #networkInfo(rawNetwork) {
553
+ return {
554
+ id: rawNetwork.Id,
555
+ name: rawNetwork.Name,
556
+ driver: rawNetwork.Driver,
557
+ reserved: this.#internalNetworkNames.includes(rawNetwork.Name),
558
+ internal: rawNetwork.Internal,
559
+ enableIPv6: rawNetwork.EnableIPv6,
560
+ IPAMConfigs: rawNetwork.IPAM?.Config
561
+ ? rawNetwork.IPAM.Config.map((item) => ({
562
+ subnet: item.Subnet,
563
+ range: item.IPRange,
564
+ gateway: item.Gateway
565
+ }))
566
+ : [],
567
+ createdAt: new Time(rawNetwork.Created)
568
+ };
569
+ }
570
+ };
571
+ __decorate([
572
+ Configurable(DTO.String().optional()),
573
+ __metadata("design:type", Object)
574
+ ], Docker.prototype, "socketPath", void 0);
575
+ __decorate([
576
+ Configurable(DTO.String().optional()),
577
+ __metadata("design:type", Object)
578
+ ], Docker.prototype, "host", void 0);
579
+ __decorate([
580
+ Configurable(DTO.Alternatives(DTO.Number().port(), DTO.String()).optional()),
581
+ __metadata("design:type", Object)
582
+ ], Docker.prototype, "port", void 0);
583
+ __decorate([
584
+ Configurable(DTO.String().optional()),
585
+ __metadata("design:type", Object)
586
+ ], Docker.prototype, "username", void 0);
587
+ __decorate([
588
+ Configurable(DTO.Object().pattern(DTO.String(), DTO.String()).optional()),
589
+ __metadata("design:type", Object)
590
+ ], Docker.prototype, "headers", void 0);
591
+ __decorate([
592
+ Configurable(DTO.Alternatives(DTO.String(), DTO.Array(DTO.String()), DTO.Binary(), DTO.Array(DTO.Binary())).optional()),
593
+ __metadata("design:type", Object)
594
+ ], Docker.prototype, "ca", void 0);
595
+ __decorate([
596
+ Configurable(DTO.Alternatives(DTO.String(), DTO.Array(DTO.String()), DTO.Binary(), DTO.Array(DTO.Binary())).optional()),
597
+ __metadata("design:type", Object)
598
+ ], Docker.prototype, "cert", void 0);
599
+ __decorate([
600
+ Configurable(DTO.Alternatives(DTO.String(), DTO.Array(DTO.String()), DTO.Binary(), DTO.Array(DTO.Binary()), DTO.Array(DTO.Object({
601
+ pem: DTO.Alternatives(DTO.String(), DTO.Binary()).required(),
602
+ passphrase: DTO.String().optional()
603
+ }))).optional()),
604
+ __metadata("design:type", Object)
605
+ ], Docker.prototype, "key", void 0);
606
+ __decorate([
607
+ Configurable(DTO.String().valid('https', 'http', 'ssh').optional()),
608
+ __metadata("design:type", Object)
609
+ ], Docker.prototype, "protocol", void 0);
610
+ __decorate([
611
+ Configurable(DTO.Number().optional()),
612
+ __metadata("design:type", Object)
613
+ ], Docker.prototype, "timeout", void 0);
614
+ __decorate([
615
+ Configurable(DTO.String().optional()),
616
+ __metadata("design:type", Object)
617
+ ], Docker.prototype, "version", void 0);
618
+ __decorate([
619
+ Configurable(DTO.String().optional()),
620
+ __metadata("design:type", Object)
621
+ ], Docker.prototype, "sshAuthAgent", void 0);
622
+ __decorate([
623
+ Accept(DockerPruneOptions.optional()),
624
+ __metadata("design:type", Function),
625
+ __metadata("design:paramtypes", [DockerPruneOptions]),
626
+ __metadata("design:returntype", Promise)
627
+ ], Docker.prototype, "prune", null);
628
+ __decorate([
629
+ Accept(DockerAuthOptions.required()),
630
+ __metadata("design:type", Function),
631
+ __metadata("design:paramtypes", [DockerAuthOptions]),
632
+ __metadata("design:returntype", Promise)
633
+ ], Docker.prototype, "loginRepository", null);
634
+ __decorate([
635
+ Accept(DockerAuthOptions.required()),
636
+ __metadata("design:type", Function),
637
+ __metadata("design:paramtypes", [DockerAuthOptions]),
638
+ __metadata("design:returntype", Promise)
639
+ ], Docker.prototype, "checkRepositoryAuth", null);
640
+ __decorate([
641
+ Accept(ImagePullOptions.required()),
642
+ __metadata("design:type", Function),
643
+ __metadata("design:paramtypes", [ImagePullOptions]),
644
+ __metadata("design:returntype", Promise)
645
+ ], Docker.prototype, "pullImage", null);
646
+ __decorate([
647
+ Accept(ImageBuildOptions.required()),
648
+ __metadata("design:type", Function),
649
+ __metadata("design:paramtypes", [ImageBuildOptions]),
650
+ __metadata("design:returntype", Promise)
651
+ ], Docker.prototype, "buildImage", null);
652
+ __decorate([
653
+ Accept(ImageImportOptions.required()),
654
+ __metadata("design:type", Function),
655
+ __metadata("design:paramtypes", [ImageImportOptions]),
656
+ __metadata("design:returntype", Promise)
657
+ ], Docker.prototype, "importImage", null);
658
+ __decorate([
659
+ Accept(DTO.String().required()),
660
+ __metadata("design:type", Function),
661
+ __metadata("design:paramtypes", [String]),
662
+ __metadata("design:returntype", Promise)
663
+ ], Docker.prototype, "getImage", null);
664
+ __decorate([
665
+ Accept(DTO.String().required()),
666
+ __metadata("design:type", Function),
667
+ __metadata("design:paramtypes", [String]),
668
+ __metadata("design:returntype", Promise)
669
+ ], Docker.prototype, "getContainer", null);
670
+ __decorate([
671
+ Accept(DTO.String().required(), DTO.Alternatives(DTO.String(), ContainerSettingOptions.required()).required(), ContainerSettingOptions.optional()),
672
+ __metadata("design:type", Function),
673
+ __metadata("design:paramtypes", [String, Object, ContainerSettingOptions]),
674
+ __metadata("design:returntype", Promise)
675
+ ], Docker.prototype, "createContainer", null);
676
+ __decorate([
677
+ Accept(NetworkCreateOptions.required()),
678
+ __metadata("design:type", Function),
679
+ __metadata("design:paramtypes", [NetworkCreateOptions]),
680
+ __metadata("design:returntype", Promise)
681
+ ], Docker.prototype, "createNetwork", null);
682
+ __decorate([
683
+ Accept(DTO.String().required()),
684
+ __metadata("design:type", Function),
685
+ __metadata("design:paramtypes", [String]),
686
+ __metadata("design:returntype", Promise)
687
+ ], Docker.prototype, "removeNetwork", null);
688
+ __decorate([
689
+ Accept(DTO.String().required()),
690
+ __metadata("design:type", Function),
691
+ __metadata("design:paramtypes", [String]),
692
+ __metadata("design:returntype", Promise)
693
+ ], Docker.prototype, "getNetwork", null);
694
+ Docker = __decorate([
695
+ Singleton()
696
+ ], Docker);
697
+ export { Docker };