@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,739 @@
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 { Provider, DTO } from '@lakutata/core';
11
+ import { Transient, Configurable } from '@lakutata/core/decorator/di';
12
+ import { DockerStreamDecoder, readMultiplexed } from '../../client/DockerStreams.js';
13
+ import { isAbortError, As, uniqueArray } from '@lakutata/utils';
14
+ import { randomBytes } from 'node:crypto';
15
+ import { setTimeout as sleep } from 'node:timers/promises';
16
+ import { Time } from '@lakutata/utils/Time';
17
+ import { Accept } from '@lakutata/core/decorator/dto';
18
+ import { ContainerStopOptions } from '../options/container/ContainerStopOptions.js';
19
+ import { ContainerRemoveOptions } from '../options/container/ContainerRemoveOptions.js';
20
+ import { ContainerSettingOptions } from '../options/container/ContainerSettingOptions.js';
21
+ import { ContainerKillOptions } from '../options/container/ContainerKillOptions.js';
22
+ import { parseEnvToRecord } from './ParseEnvToRecord.js';
23
+ import { ContainerCommitOptions } from '../options/container/ContainerCommitOptions.js';
24
+ import { parseRepositoryTag } from './ParseRepositoryTag.js';
25
+ import { DockerContainerTTY } from './DockerContainerTTY.js';
26
+ import { ContainerCreateTTYOptions } from '../options/container/ContainerCreateTTYOptions.js';
27
+ import { ContainerLogsOptions } from '../options/container/ContainerLogsOptions.js';
28
+ import { ContainerExecOptions } from '../options/container/ContainerExecOptions.js';
29
+ import { ContainerExportDirectoryOptions } from '../options/container/ContainerExportDirectoryOptions.js';
30
+ import { pipeline } from 'stream/promises';
31
+ import { createWriteStream } from 'node:fs';
32
+ import { DockerImageNotFoundException } from '../exceptions/DockerImageNotFoundException.js';
33
+ import { DockerContainerNotFoundException } from '../exceptions/DockerContainerNotFoundException.js';
34
+ import { engineBinds, engineDevices, engineEndpoints, enginePortBindings, engineRestartPolicy, parseRestartPolicy } from './EngineSettings.js';
35
+ /**
36
+ * A container of the Docker daemon, with its settings and its state as inspected, and its operations: start, stop,
37
+ * restart, pause, kill, remove, update, commit, exec, TTYs, logs, stats and the export of its files. It is not created
38
+ * with `new`: {@link Docker.getContainer}, {@link Docker.listContainers}, {@link Docker.createContainer} and
39
+ * {@link DockerImage.run} return it.
40
+ *
41
+ * Its properties are a snapshot, taken when it is obtained and refreshed by its own operations (`start()`, `stop()`,
42
+ * `restart()`, `pause()`, `unpause()`, `kill()`, `update()`): the changes made by others (the container exiting,
43
+ * `docker stop`) are seen by getting it again. Its operations reject with {@link DockerContainerNotFoundException} when
44
+ * the container was removed, with {@link DockerRequestException} when the daemon refuses them otherwise (not running:
45
+ * HTTP 409), and with the network error of Node.js when the daemon cannot be reached.
46
+ * @example
47
+ * ```typescript
48
+ * import {type Docker, type DockerContainer, type DockerImage} from 'lakutata/com/docker'
49
+ *
50
+ * declare const docker: Docker
51
+ *
52
+ * const image: DockerImage = await docker.getImage('alpine:3.20')
53
+ * const container: DockerContainer = await docker.createContainer(image.id, {
54
+ * name: 'worker',
55
+ * cmd: ['sh', '-c', 'echo started; sleep 3600'],
56
+ * env: {MODE: 'production'},
57
+ * ports: [{port: 8080, type: 'tcp', hostPorts: [18080]}],
58
+ * binds: [{hostPath: '/srv/data', containerPath: '/data', rw: true}],
59
+ * restartPolicy: 'unless-stopped'
60
+ * })
61
+ * await container.start()
62
+ * console.log(container.state.status, container.ports)
63
+ * //The exit code, stdout and stderr
64
+ * const {exitCode, stdout} = await container.exec({cmd: ['ls', '/data']})
65
+ * console.log(exitCode, stdout)
66
+ * await container.stop({timeout: 10})
67
+ * await container.remove()
68
+ * ```
69
+ */
70
+ let DockerContainer = class DockerContainer extends Provider {
71
+ #abortController = new AbortController();
72
+ /**
73
+ * Inspect the container.
74
+ * @throws {DockerContainerNotFoundException} When the container does not exist.
75
+ * @protected
76
+ */
77
+ async init() {
78
+ await this.syncContainerInfo();
79
+ }
80
+ /**
81
+ * Abort the requests in progress of the object (the container itself is left as it is).
82
+ * @protected
83
+ */
84
+ async destroy() {
85
+ this.#abortController.abort();
86
+ }
87
+ /**
88
+ * Refresh the properties from the daemon's inspection of the container, and its image (`undefined` when it no longer
89
+ * exists).
90
+ * @throws {DockerContainerNotFoundException} When the container does not exist.
91
+ * @protected
92
+ */
93
+ async syncContainerInfo() {
94
+ try {
95
+ const inspectInfo = await this.getClient().inspectContainer(this.id, this.#abortController.signal);
96
+ //Got by its name or a short ID: its full ID
97
+ this.id = inspectInfo.Id;
98
+ this.createdAt = new Time(inspectInfo.Created);
99
+ this.name = inspectInfo.Name.substring(1);
100
+ this.hostname = inspectInfo.Config.Hostname;
101
+ try {
102
+ this.image = await this.getDocker().getImage(inspectInfo.Image);
103
+ }
104
+ catch (e) {
105
+ //Its image removed with force: the container is read without it
106
+ if (!(e instanceof DockerImageNotFoundException))
107
+ throw e;
108
+ this.image = undefined;
109
+ }
110
+ this.restartCount = inspectInfo.RestartCount;
111
+ this.state = {
112
+ status: As(inspectInfo.State.Status),
113
+ running: inspectInfo.State.Running,
114
+ paused: inspectInfo.State.Paused,
115
+ restarting: inspectInfo.State.Restarting,
116
+ OOMKilled: inspectInfo.State.OOMKilled,
117
+ dead: inspectInfo.State.Dead,
118
+ pid: inspectInfo.State.Pid,
119
+ exitCode: inspectInfo.State.ExitCode,
120
+ startedAt: this.#time(inspectInfo.State.StartedAt),
121
+ finishedAt: this.#time(inspectInfo.State.FinishedAt)
122
+ };
123
+ const networkSettings = inspectInfo.NetworkSettings ? inspectInfo.NetworkSettings.Networks ? inspectInfo.NetworkSettings.Networks : {} : {};
124
+ this.tty = inspectInfo.Config.Tty;
125
+ this.OOMKillDisable = !!inspectInfo.HostConfig.OomKillDisable;
126
+ this.networks = Object.keys(networkSettings).map((networkSettingName) => ({
127
+ networkName: networkSettingName,
128
+ networkId: networkSettings[networkSettingName].NetworkID,
129
+ endpointId: networkSettings[networkSettingName].EndpointID,
130
+ mac: networkSettings[networkSettingName].MacAddress,
131
+ ip: networkSettings[networkSettingName].IPAddress,
132
+ gateway: networkSettings[networkSettingName].Gateway,
133
+ ipPrefixLen: networkSettings[networkSettingName].IPPrefixLen,
134
+ ipv6: networkSettings[networkSettingName].GlobalIPv6Address,
135
+ ipv6Gateway: networkSettings[networkSettingName].IPv6Gateway,
136
+ ipv6PrefixLen: networkSettings[networkSettingName].GlobalIPv6PrefixLen
137
+ }));
138
+ const containerIpAddresses = [];
139
+ this.networks.forEach((network) => {
140
+ if (network.ip)
141
+ containerIpAddresses.push(network.ip);
142
+ if (network.ipv6)
143
+ containerIpAddresses.push(`[${network.ipv6}]`);
144
+ });
145
+ const ports = [];
146
+ const portMap = new Map();
147
+ this.image?.config.ports?.forEach((exposePortInfo) => {
148
+ containerIpAddresses.forEach((containerIpAddress) => {
149
+ const types = [];
150
+ if (exposePortInfo.tcp)
151
+ types.push('tcp');
152
+ if (exposePortInfo.udp)
153
+ types.push('udp');
154
+ types.forEach(type => {
155
+ const portMapKey = `${containerIpAddress}_${exposePortInfo.port}_${type}`;
156
+ if (!portMap.has(portMapKey))
157
+ portMap.set(portMapKey, []);
158
+ });
159
+ });
160
+ });
161
+ if (inspectInfo.NetworkSettings.Ports) {
162
+ Object.keys(inspectInfo.NetworkSettings.Ports).forEach((portWithType) => {
163
+ const portInfo = portWithType.split('/');
164
+ const port = parseInt(portInfo[0]);
165
+ const type = As(portInfo[1].toLowerCase());
166
+ inspectInfo.NetworkSettings.Ports[portWithType]?.forEach((hostBinding) => {
167
+ containerIpAddresses.forEach((containerIpAddress) => {
168
+ const portMapKey = `${containerIpAddress}_${port}_${type}`;
169
+ if (!portMap.has(portMapKey))
170
+ portMap.set(portMapKey, []);
171
+ //A host port is bound on the IPv4 and the IPv6 addresses of the host: listed once
172
+ const hostPorts = portMap.get(portMapKey);
173
+ const hostPort = parseInt(hostBinding.HostPort);
174
+ if (!hostPorts.includes(hostPort))
175
+ hostPorts.push(hostPort);
176
+ });
177
+ });
178
+ });
179
+ }
180
+ portMap.forEach((hostPorts, portMapKey) => {
181
+ const infos = portMapKey.split('_');
182
+ const containerIpAddress = infos[0];
183
+ const port = parseInt(infos[1]);
184
+ const type = As(infos[2]);
185
+ ports.push({
186
+ host: containerIpAddress,
187
+ port: port,
188
+ type: type,
189
+ hostPorts: hostPorts
190
+ });
191
+ });
192
+ this.ports = ports;
193
+ const binds = [];
194
+ for (const mount of inspectInfo.Mounts ?? []) {
195
+ if (mount.Type === 'bind') {
196
+ binds.push({
197
+ hostPath: mount.Source,
198
+ containerPath: mount.Destination,
199
+ rw: mount.RW
200
+ });
201
+ }
202
+ }
203
+ this.binds = binds;
204
+ this.devices = inspectInfo.HostConfig.Devices ? As(inspectInfo.HostConfig.Devices).map(device => ({
205
+ hostPath: device.PathOnHost,
206
+ containerPath: device.PathInContainer,
207
+ cgroupPermissions: device.CgroupPermissions
208
+ })) : [];
209
+ this.memoryLimit = inspectInfo.HostConfig.Memory ? inspectInfo.HostConfig.Memory : 0;
210
+ this.privileged = !!inspectInfo.HostConfig.Privileged;
211
+ this.restartPolicy = parseRestartPolicy(inspectInfo.HostConfig.RestartPolicy);
212
+ this.cgroup = inspectInfo.HostConfig.Cgroup;
213
+ this.cgroupParent = inspectInfo.HostConfig.CgroupParent;
214
+ this.pidMode = inspectInfo.HostConfig.PidMode;
215
+ const cpuSetString = inspectInfo.HostConfig.CpusetCpus ? inspectInfo.HostConfig.CpusetCpus : '';
216
+ const cpuSetArray = cpuSetString.split(',');
217
+ const cpuIndexesArray = cpuSetArray.map((cpuSetItem) => {
218
+ if (cpuSetItem.includes('-')) {
219
+ const [min, max] = cpuSetItem.split('-');
220
+ const cpuIndexes = [];
221
+ if (!min || !max)
222
+ return cpuIndexes;
223
+ for (let i = parseInt(min); i <= parseInt(max); i++)
224
+ cpuIndexes.push(i);
225
+ return cpuIndexes;
226
+ }
227
+ else {
228
+ return [parseInt(cpuSetItem)];
229
+ }
230
+ });
231
+ let cpuSet = [];
232
+ cpuIndexesArray.forEach((cpuIndexes) => {
233
+ cpuSet = [...cpuIndexes, ...cpuSet];
234
+ });
235
+ this.cpuSet = uniqueArray(cpuSet).sort((a, b) => a - b).filter(value => typeof value === 'number' && !isNaN(value));
236
+ this.env = parseEnvToRecord(inspectInfo.Config.Env);
237
+ this.capabilities = inspectInfo.HostConfig.CapAdd ? inspectInfo.HostConfig.CapAdd : [];
238
+ }
239
+ catch (e) {
240
+ if (!isAbortError(e))
241
+ throw e;
242
+ }
243
+ }
244
+ /**
245
+ * The time of a date of the state: null for Docker's zero date (never)
246
+ * @param date
247
+ */
248
+ #time(date) {
249
+ if (!date || date.startsWith('0001-01-01'))
250
+ return null;
251
+ return new Time(date);
252
+ }
253
+ /**
254
+ * Start the container, as `docker start`, then refresh its properties. A container already running is left as it is
255
+ * (as the Docker CLI does).
256
+ * @throws {DockerContainerNotFoundException} When the container was removed.
257
+ * @throws {DockerRequestException} When it fails to start (HTTP 500: a command not found, a port already used).
258
+ */
259
+ async start() {
260
+ try {
261
+ await this.getClient().startContainer(this.id, this.#abortController.signal);
262
+ await this.syncContainerInfo();
263
+ }
264
+ catch (e) {
265
+ if (!isAbortError(e))
266
+ throw e;
267
+ }
268
+ }
269
+ /**
270
+ * Stop the container, as `docker stop`: send its stop signal, wait for it to exit, kill it after the timeout; then
271
+ * refresh its properties.
272
+ * @param options The signal sent (the container's stop signal, `SIGTERM` by default) and the timeout before the kill,
273
+ * in seconds (the container's, 10 by default). A container already stopped is left as it is (as the Docker CLI does).
274
+ * @throws {DockerContainerNotFoundException} When the container was removed.
275
+ */
276
+ async stop(options) {
277
+ if (!options)
278
+ return await this.stop({});
279
+ try {
280
+ await this.getClient().stopContainer(this.id, { signal: options.signal, t: options.timeout }, this.#abortController.signal);
281
+ await this.syncContainerInfo();
282
+ }
283
+ catch (e) {
284
+ if (!isAbortError(e))
285
+ throw e;
286
+ }
287
+ }
288
+ /**
289
+ * Suspend the processes of the container, as `docker pause`, then refresh its properties.
290
+ * @throws {DockerContainerNotFoundException} When the container was removed.
291
+ * @throws {DockerRequestException} When it is not running or already paused (HTTP 409).
292
+ */
293
+ async pause() {
294
+ await this.getClient().pauseContainer(this.id);
295
+ await this.syncContainerInfo();
296
+ }
297
+ /**
298
+ * Resume the processes of a paused container, as `docker unpause`, then refresh its properties.
299
+ * @throws {DockerContainerNotFoundException} When the container was removed.
300
+ * @throws {DockerRequestException} When it is not paused (HTTP 409).
301
+ */
302
+ async unpause() {
303
+ await this.getClient().unpauseContainer(this.id);
304
+ await this.syncContainerInfo();
305
+ }
306
+ /**
307
+ * Restart the container, as `docker restart`: stop it as {@link DockerContainer.stop} does (when it runs), then start
308
+ * it; then refresh its properties.
309
+ * @param options The signal sent (the container's stop signal, `SIGTERM` by default) and the timeout before the kill,
310
+ * in seconds (the container's, 10 by default).
311
+ * @throws {DockerContainerNotFoundException} When the container was removed.
312
+ * @throws {DockerRequestException} When it fails to start (HTTP 500).
313
+ */
314
+ async restart(options) {
315
+ if (!options)
316
+ return await this.restart({});
317
+ try {
318
+ await this.getClient().restartContainer(this.id, { signal: options.signal, t: options.timeout }, this.#abortController.signal);
319
+ await this.syncContainerInfo();
320
+ }
321
+ catch (e) {
322
+ if (!isAbortError(e))
323
+ throw e;
324
+ }
325
+ }
326
+ /**
327
+ * Remove the container, as `docker rm -v`: its anonymous volumes are removed with it. The object is not refreshed:
328
+ * its other operations then fail with {@link DockerContainerNotFoundException}.
329
+ * @param options `force` kills a running container first (`false` by default).
330
+ * @throws {DockerContainerNotFoundException} When the container was already removed.
331
+ * @throws {DockerRequestException} When it is running and `force` is not set (HTTP 409).
332
+ */
333
+ async remove(options) {
334
+ if (!options)
335
+ return await this.remove({});
336
+ await this.getClient().removeContainer(this.id, { force: !!options.force, v: true });
337
+ }
338
+ /**
339
+ * Change the settings of the container, keeping the others. The memory limit, the CPUs and the restart policy are
340
+ * changed live, as `docker update` does, and the name by renaming it, the container running on. The other
341
+ * settings (and removing the memory limit or the CPU set, which Docker cannot do live) recreate the container: a new
342
+ * one is created from the old one's whole configuration (its image, command, entrypoint, environment, mounts,
343
+ * networks and their static addresses, the addresses Docker assigned being assigned again), with the settings
344
+ * changed, under a temporary name. Once created (and, when the old one was running, the old one stopped and the new
345
+ * one started), the old one is removed without its volumes and the new one takes its name (and its anonymous
346
+ * volumes, mounted again). The object follows the new container: its `id` changes.
347
+ * @remarks The old container is kept when the creation or the start of the new one fails (invalid settings, the
348
+ * image removed, a network missing): the new one is removed, the old one started again when it was running, and the
349
+ * call rejects. Its files outside the volumes are not kept by a recreation (commit them first, see
350
+ * {@link DockerContainer.commit}). A container removed by Docker when it stops (`AutoRemove`) cannot be kept.
351
+ * @param options The settings changed: `memoryLimit`, `cpuSet` and `restartPolicy` live (the swap limit set to
352
+ * Docker's default with the memory), `name` by a renaming; `hostname`, `env` (replacing the container's variables;
353
+ * the image's are added again), `cmd`, `entrypoint`, `tty`, `privileged`, `ports`, `binds` (replacing the bind
354
+ * mounts, the volumes kept), `devices`, `networks` (replacing the networks), `capabilities`, `OOMKillDisable`,
355
+ * `cgroup`, `cgroupParent` and `pidMode` by a recreation. The settings absent are kept.
356
+ * @throws {InvalidMethodAcceptException} When the settings are invalid.
357
+ * @throws {DockerContainerNotFoundException} When the container was removed.
358
+ * @throws {DockerImageNotFoundException} When the container must be recreated and its image no longer exists.
359
+ * @throws {DockerNetworkNotFoundException} When a network of the settings is not found.
360
+ * @throws {DockerRequestException} When the daemon refuses the changes: a limit refused (HTTP 400), the name
361
+ * already used (HTTP 409), the new container failing to start (HTTP 500).
362
+ */
363
+ async update(options) {
364
+ const changes = As(Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)));
365
+ const inspectInfo = await this.getClient().inspectContainer(this.id);
366
+ const name = changes.name ?? inspectInfo.Name.substring(1);
367
+ //The resources Docker sets live (it cannot remove a limit live), and the restart policy
368
+ const resources = {};
369
+ let recreated = false;
370
+ for (const key of Object.keys(changes)) {
371
+ if (key === 'name')
372
+ continue;
373
+ //No limit to remove
374
+ if ((key === 'memoryLimit' && !changes.memoryLimit && !inspectInfo.HostConfig.Memory) || (key === 'cpuSet' && !changes.cpuSet.length && !inspectInfo.HostConfig.CpusetCpus))
375
+ continue;
376
+ if (key === 'memoryLimit' && changes.memoryLimit) {
377
+ resources.Memory = changes.memoryLimit;
378
+ //As much swap as memory, Docker's default, unless the swap is unlimited
379
+ if (inspectInfo.HostConfig.MemorySwap !== -1)
380
+ resources.MemorySwap = changes.memoryLimit * 2;
381
+ }
382
+ else if (key === 'cpuSet' && changes.cpuSet.length) {
383
+ resources.CpusetCpus = changes.cpuSet.join(',');
384
+ }
385
+ else if (key === 'restartPolicy') {
386
+ resources.RestartPolicy = engineRestartPolicy(changes.restartPolicy || 'no');
387
+ }
388
+ else {
389
+ recreated = true;
390
+ }
391
+ }
392
+ if (recreated) {
393
+ await this.#recreate(inspectInfo, changes, name);
394
+ }
395
+ else {
396
+ if (Object.keys(resources).length)
397
+ await this.getClient().updateContainer(this.id, resources);
398
+ if (name !== inspectInfo.Name.substring(1))
399
+ await this.getClient().renameContainer(this.id, name);
400
+ }
401
+ await this.syncContainerInfo();
402
+ }
403
+ /**
404
+ * Recreate the container from its configuration, with the settings changed: created under a temporary name, it
405
+ * replaces the old one once created
406
+ * @param inspectInfo The inspection of the container
407
+ * @param changes The settings changed
408
+ * @param name The name of the container
409
+ */
410
+ async #recreate(inspectInfo, changes, name) {
411
+ const config = { ...inspectInfo.Config };
412
+ const hostConfig = { ...inspectInfo.HostConfig };
413
+ //By its ID: the name it was created with may be another image's now
414
+ config.Image = inspectInfo.Image;
415
+ //The host name Docker gave (the short ID), or the one of the container whose network it shares, is not kept
416
+ if (config.Hostname === inspectInfo.Id.substring(0, 12) || /^container:/.test(hostConfig.NetworkMode ?? ''))
417
+ delete config.Hostname;
418
+ if (changes.hostname !== undefined)
419
+ config.Hostname = changes.hostname;
420
+ if (changes.tty !== undefined)
421
+ config.Tty = changes.tty;
422
+ if (changes.env)
423
+ config.Env = Object.keys(changes.env).map((envKey) => `${envKey}=${changes.env[envKey]}`);
424
+ if (changes.cmd)
425
+ config.Cmd = changes.cmd;
426
+ if (changes.entrypoint)
427
+ config.Entrypoint = changes.entrypoint;
428
+ if (changes.privileged !== undefined)
429
+ hostConfig.Privileged = changes.privileged;
430
+ if (changes.memoryLimit !== undefined) {
431
+ hostConfig.Memory = changes.memoryLimit;
432
+ //Docker's default swap, unless the swap is unlimited
433
+ if (hostConfig.MemorySwap !== -1)
434
+ hostConfig.MemorySwap = 0;
435
+ }
436
+ if (changes.cpuSet)
437
+ hostConfig.CpusetCpus = changes.cpuSet.join(',');
438
+ if (changes.restartPolicy !== undefined)
439
+ hostConfig.RestartPolicy = engineRestartPolicy(changes.restartPolicy || 'no');
440
+ if (changes.OOMKillDisable !== undefined)
441
+ hostConfig.OomKillDisable = changes.OOMKillDisable;
442
+ if (changes.capabilities)
443
+ hostConfig.CapAdd = changes.capabilities;
444
+ if (changes.cgroup !== undefined)
445
+ hostConfig.Cgroup = changes.cgroup;
446
+ if (changes.cgroupParent !== undefined)
447
+ hostConfig.CgroupParent = changes.cgroupParent;
448
+ if (changes.pidMode !== undefined)
449
+ hostConfig.PidMode = changes.pidMode;
450
+ if (changes.devices)
451
+ hostConfig.Devices = engineDevices(changes.devices);
452
+ if (changes.ports) {
453
+ hostConfig.PortBindings = enginePortBindings(changes.ports);
454
+ config.ExposedPorts = { ...config.ExposedPorts, ...Object.fromEntries(Object.keys(hostConfig.PortBindings).map((port) => [port, {}])) };
455
+ }
456
+ else {
457
+ //Each host port once
458
+ hostConfig.PortBindings = Object.fromEntries(Object.entries(hostConfig.PortBindings ?? {}).map(([port, bindings]) => [
459
+ port,
460
+ bindings ? bindings.filter((binding, index) => bindings.findIndex((other) => other.HostIp === binding.HostIp && other.HostPort === binding.HostPort) === index) : null
461
+ ]));
462
+ }
463
+ if (changes.binds) {
464
+ //The bind mounts replaced (their source is a host path), the volumes kept
465
+ hostConfig.Binds = [...(hostConfig.Binds ?? []).filter((bind) => !/^(\/|[a-zA-Z]:\\)/.test(bind)), ...engineBinds(changes.binds)];
466
+ hostConfig.Mounts = (hostConfig.Mounts ?? []).filter((mount) => mount.Type !== 'bind');
467
+ }
468
+ //The anonymous volumes mounted again by their names: the old container is removed without them
469
+ const mounted = [
470
+ ...(hostConfig.Binds ?? []).map((bind) => bind.split(':')[1]),
471
+ ...(hostConfig.Mounts ?? []).map((mount) => mount.Target)
472
+ ];
473
+ const anonymousVolumes = (inspectInfo.Mounts ?? []).filter((mount) => mount.Type === 'volume' && !mounted.includes(mount.Destination));
474
+ if (anonymousVolumes.length)
475
+ hostConfig.Mounts = [...(hostConfig.Mounts ?? []), ...anonymousVolumes.map((mount) => ({
476
+ Type: 'volume',
477
+ Source: mount.Name,
478
+ Target: mount.Destination,
479
+ ReadOnly: !mount.RW
480
+ }))];
481
+ let endpoints;
482
+ if (changes.networks) {
483
+ endpoints = engineEndpoints(changes.networks);
484
+ if (changes.networks.length && !/^(host|none|container:)/.test(hostConfig.NetworkMode ?? ''))
485
+ hostConfig.NetworkMode = changes.networks[0].networkName;
486
+ }
487
+ else {
488
+ //The networks kept as configured: their static addresses only (IPAMConfig), the others assigned again
489
+ const networks = inspectInfo.NetworkSettings?.Networks ?? {};
490
+ endpoints = Object.fromEntries(Object.entries(networks).map(([networkName, endpoint]) => [networkName, {
491
+ IPAMConfig: endpoint.IPAMConfig ?? undefined,
492
+ Links: endpoint.Links ?? undefined,
493
+ Aliases: endpoint.Aliases?.filter((alias) => alias !== inspectInfo.Id.substring(0, 12)) ?? undefined,
494
+ DriverOpts: endpoint.DriverOpts ?? undefined,
495
+ GwPriority: endpoint.GwPriority
496
+ }]));
497
+ }
498
+ //The platform of the image used: an image may have several
499
+ const platform = inspectInfo.ImageManifestDescriptor?.platform;
500
+ const created = await this.getClient().createContainer({
501
+ ...config,
502
+ HostConfig: hostConfig,
503
+ NetworkingConfig: { EndpointsConfig: endpoints }
504
+ }, {
505
+ name: `${name}-update-${randomBytes(4).toString('hex')}`,
506
+ platform: platform?.os && platform.architecture ? [platform.os, platform.architecture, platform.variant].filter(Boolean).join('/') : undefined
507
+ });
508
+ //Created: the old container is replaced once the new one runs (its ports and addresses freed by the old one), and
509
+ //is kept, started again, when the new one cannot start or the old one cannot be removed
510
+ const running = !!inspectInfo.State?.Running;
511
+ try {
512
+ if (running) {
513
+ await this.getClient().stopContainer(this.id);
514
+ await this.getClient().startContainer(created.Id);
515
+ }
516
+ await this.getClient().removeContainer(this.id, { force: true, v: false }).catch((error) => {
517
+ //Removed by itself once stopped (AutoRemove)
518
+ if (!(error instanceof DockerContainerNotFoundException))
519
+ throw error;
520
+ });
521
+ }
522
+ catch (e) {
523
+ await this.getClient().removeContainer(created.Id, { force: true, v: false }).catch(() => undefined);
524
+ if (running)
525
+ await this.getClient().startContainer(this.id).catch(() => undefined);
526
+ throw e;
527
+ }
528
+ this.id = created.Id;
529
+ await this.getClient().renameContainer(this.id, name);
530
+ }
531
+ /**
532
+ * Create an image from the container's current files, as `docker commit`.
533
+ * @param options The name of the image (`repoTag`, `repo:tag`; none by default) and whether the container is paused
534
+ * while it is committed (`pauseBeforeCommitting`, `true` by default).
535
+ * @returns The image created.
536
+ * @throws {DockerContainerNotFoundException} When the container was removed.
537
+ */
538
+ async commit(options) {
539
+ if (!options)
540
+ return await this.commit({});
541
+ let repo = undefined;
542
+ let tag = undefined;
543
+ if (options.repoTag) {
544
+ const parseResult = parseRepositoryTag(options.repoTag);
545
+ repo = parseResult.repo;
546
+ tag = parseResult.tag;
547
+ }
548
+ const commitResult = await this.getClient().commitContainer(this.id, {
549
+ repo: repo,
550
+ tag: tag,
551
+ pause: options.pauseBeforeCommitting !== undefined ? options.pauseBeforeCommitting : true
552
+ });
553
+ return await this.getDocker().getImage(commitResult.Id);
554
+ }
555
+ /**
556
+ * Start an interactive command with a TTY in the running container, as `docker exec -it`. The command runs until it
557
+ * exits (or its stream is closed): see {@link DockerContainerTTY}.
558
+ * @param options The command (`['/bin/sh']` by default; the program and its arguments, run as they are, or a command
559
+ * line, run by `/bin/sh -c`) and the initial console size.
560
+ * @returns The TTY, its command started.
561
+ * @throws {DockerContainerNotFoundException} When the container was removed.
562
+ * @throws {DockerRequestException} When the container is not running (HTTP 409).
563
+ */
564
+ async createTTY(options) {
565
+ return await this.getObject(DockerContainerTTY, {
566
+ getClient: this.getClient,
567
+ containerId: this.id,
568
+ cmd: typeof options?.cmd === 'string' ? ['/bin/sh', '-c', options.cmd] : options?.cmd ?? ['/bin/sh'],
569
+ initialConsoleSize: options?.consoleSize
570
+ });
571
+ }
572
+ /**
573
+ * Read the logs of the container's main process, as `docker logs`: stdout and stderr in one stream, in their order
574
+ * (split from Docker's multiplexed format unless the container has a TTY).
575
+ * @remarks The logs are followed by default: the stream does not end while the container runs. Pass `follow: false`
576
+ * for the logs written so far.
577
+ * @param options `follow` (`true` by default), `since` and `until` (UNIX timestamps in seconds; `0`, no bound, by
578
+ * default), `timestamps` (`false` by default) and `tail` (a number of lines from the end; all by default).
579
+ * @returns The readable stream of the logs.
580
+ * @throws {DockerContainerNotFoundException} When the container was removed.
581
+ */
582
+ async logs(options) {
583
+ if (!options)
584
+ return await this.logs({});
585
+ const logs = await this.getClient().containerLogs(this.id, {
586
+ follow: !!options.follow,
587
+ stdout: true,
588
+ stderr: true,
589
+ since: options.since,
590
+ until: options.until,
591
+ timestamps: options.timestamps,
592
+ tail: options.tail
593
+ });
594
+ //The logs of a container without TTY are multiplexed: their contents are given, in their order
595
+ if (this.tty)
596
+ return logs;
597
+ const decoder = new DockerStreamDecoder();
598
+ logs.once('error', (error) => decoder.destroy(error));
599
+ return logs.pipe(decoder);
600
+ }
601
+ /**
602
+ * Read the resource usage of the container once, as `docker stats --no-stream`: CPU, memory, network, block I/O and
603
+ * processes, as the Engine API reports them.
604
+ * @returns The statistics.
605
+ * @throws {DockerContainerNotFoundException} When the container was removed.
606
+ */
607
+ async stats() {
608
+ return await this.getClient().containerStats(this.id);
609
+ }
610
+ /**
611
+ * Run a command in the running container, as `docker exec` (no TTY, no stdin), and wait for it to exit. As the
612
+ * containerd component's, a command exiting with a non-zero code resolves too: check its `exitCode`.
613
+ * @param options The command: a program and its arguments (`['ls', '-l']`), run as they are, or a command line
614
+ * (`'ls /data | wc -l'`), run by `/bin/sh -c`.
615
+ * @returns The exit code of the command, its stdout and its stderr (a program not found: exit code `127` or `126`,
616
+ * the error in the output).
617
+ * @throws {DockerContainerNotFoundException} When the container was removed.
618
+ * @throws {DockerRequestException} When the container is not running or paused (HTTP 409).
619
+ */
620
+ async exec(options) {
621
+ const exec = await this.getClient().createExec(this.id, {
622
+ Cmd: typeof options.cmd === 'string' ? ['/bin/sh', '-c', options.cmd] : options.cmd,
623
+ AttachStdout: true,
624
+ AttachStderr: true
625
+ });
626
+ //Without TTY, the output is multiplexed: stdout and stderr apart
627
+ const duplex = await this.getClient().startExec(exec.Id, { Detach: false, Tty: false });
628
+ const { stdout, stderr } = await readMultiplexed(duplex);
629
+ //The exit code is set once the process is reaped, which may follow the end of its output
630
+ let inspectInfo = await this.getClient().inspectExec(exec.Id);
631
+ for (let attempt = 0; (inspectInfo.Running || inspectInfo.ExitCode === null) && attempt < 200; attempt++) {
632
+ await sleep(10);
633
+ inspectInfo = await this.getClient().inspectExec(exec.Id);
634
+ }
635
+ return { exitCode: inspectInfo.ExitCode ?? 0, stdout: stdout, stderr: stderr };
636
+ }
637
+ /**
638
+ * Send a signal to the container's main process, as `docker kill` (`SIGKILL` by default), then refresh its properties.
639
+ * @param options The signal sent: a name (`'SIGHUP'`) or a number (`1`); `SIGKILL` by default.
640
+ * @throws {DockerContainerNotFoundException} When the container was removed.
641
+ * @throws {DockerRequestException} When the container is not running (HTTP 409), or the signal is unknown.
642
+ */
643
+ async kill(options) {
644
+ if (!options)
645
+ return await this.kill({});
646
+ await this.getClient().killContainer(this.id, { signal: options.signal === undefined ? undefined : String(options.signal) });
647
+ await this.syncContainerInfo();
648
+ }
649
+ /**
650
+ * Copy a file or a directory out of the container as a tar archive, as `docker cp container:path -`. The container
651
+ * may be stopped.
652
+ * @param options The path in the container, and the `destination` of the archive: a file path (created or
653
+ * overwritten) or a writable stream (ended after the archive).
654
+ * @throws {DockerContainerNotFoundException} When the container was removed.
655
+ * @throws {DockerRequestException} When the path is not found in the container (HTTP 404).
656
+ * @throws {Error} The error of the destination.
657
+ */
658
+ async exportDirectory(options) {
659
+ const readableStream = await this.getClient().getArchive(this.id, { path: options.path });
660
+ const writableStream = typeof options.destination === 'string' ? createWriteStream(options.destination) : options.destination;
661
+ await pipeline(readableStream, writableStream);
662
+ }
663
+ };
664
+ __decorate([
665
+ Configurable(DTO.Function()),
666
+ __metadata("design:type", Function)
667
+ ], DockerContainer.prototype, "getClient", void 0);
668
+ __decorate([
669
+ Configurable(DTO.Function()),
670
+ __metadata("design:type", Function)
671
+ ], DockerContainer.prototype, "getDocker", void 0);
672
+ __decorate([
673
+ Configurable(DTO.String()),
674
+ __metadata("design:type", String)
675
+ ], DockerContainer.prototype, "id", void 0);
676
+ __decorate([
677
+ Accept(ContainerStopOptions.optional()),
678
+ __metadata("design:type", Function),
679
+ __metadata("design:paramtypes", [ContainerStopOptions]),
680
+ __metadata("design:returntype", Promise)
681
+ ], DockerContainer.prototype, "stop", null);
682
+ __decorate([
683
+ Accept(ContainerStopOptions.optional()),
684
+ __metadata("design:type", Function),
685
+ __metadata("design:paramtypes", [ContainerStopOptions]),
686
+ __metadata("design:returntype", Promise)
687
+ ], DockerContainer.prototype, "restart", null);
688
+ __decorate([
689
+ Accept(ContainerRemoveOptions.optional()),
690
+ __metadata("design:type", Function),
691
+ __metadata("design:paramtypes", [ContainerRemoveOptions]),
692
+ __metadata("design:returntype", Promise)
693
+ ], DockerContainer.prototype, "remove", null);
694
+ __decorate([
695
+ Accept(ContainerSettingOptions.required()),
696
+ __metadata("design:type", Function),
697
+ __metadata("design:paramtypes", [ContainerSettingOptions]),
698
+ __metadata("design:returntype", Promise)
699
+ ], DockerContainer.prototype, "update", null);
700
+ __decorate([
701
+ Accept(ContainerCommitOptions.optional().default({})),
702
+ __metadata("design:type", Function),
703
+ __metadata("design:paramtypes", [ContainerCommitOptions]),
704
+ __metadata("design:returntype", Promise)
705
+ ], DockerContainer.prototype, "commit", null);
706
+ __decorate([
707
+ Accept(ContainerCreateTTYOptions.optional()),
708
+ __metadata("design:type", Function),
709
+ __metadata("design:paramtypes", [ContainerCreateTTYOptions]),
710
+ __metadata("design:returntype", Promise)
711
+ ], DockerContainer.prototype, "createTTY", null);
712
+ __decorate([
713
+ Accept(ContainerLogsOptions.optional()),
714
+ __metadata("design:type", Function),
715
+ __metadata("design:paramtypes", [ContainerLogsOptions]),
716
+ __metadata("design:returntype", Promise)
717
+ ], DockerContainer.prototype, "logs", null);
718
+ __decorate([
719
+ Accept(ContainerExecOptions.required()),
720
+ __metadata("design:type", Function),
721
+ __metadata("design:paramtypes", [ContainerExecOptions]),
722
+ __metadata("design:returntype", Promise)
723
+ ], DockerContainer.prototype, "exec", null);
724
+ __decorate([
725
+ Accept(ContainerKillOptions.optional()),
726
+ __metadata("design:type", Function),
727
+ __metadata("design:paramtypes", [ContainerKillOptions]),
728
+ __metadata("design:returntype", Promise)
729
+ ], DockerContainer.prototype, "kill", null);
730
+ __decorate([
731
+ Accept(ContainerExportDirectoryOptions.required()),
732
+ __metadata("design:type", Function),
733
+ __metadata("design:paramtypes", [ContainerExportDirectoryOptions]),
734
+ __metadata("design:returntype", Promise)
735
+ ], DockerContainer.prototype, "exportDirectory", null);
736
+ DockerContainer = __decorate([
737
+ Transient()
738
+ ], DockerContainer);
739
+ export { DockerContainer };