使用 Jib-Core 将 Docker 个图像容器化到特定的本地目录
Containerize Docker images to specific local directory using Jib-Core
我正在请求帮助使用 jib-core 创建本地 Docker 图像。
我知道如何将图像推送到 DockerHub Repo,但现在我想将所有图像放入本地单个存储库。
到目前为止我做了什么:
- 通过阅读 jib-core 文档,成功创建了一个 image.tar 但无法构建它(缺少 dockerfile)
目前我是这样做的:
public void buildLocalImage(String appName) throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException {
Jib.from("openjdk:15")
.addLayer(Arrays.asList(Paths.get("jars/"+appName+".jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/local-kube-api.jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/script.sh")), AbsoluteUnixPath.get("/"))
.setEntrypoint("sh","/script.sh")
.containerize(
Containerizer.to(DockerDaemonImage.named("images/"+appName+"-images:TEST")).setOfflineMode(true)
);
}
最终目标是在一个容器中 运行 2 个罐子,当我使用传统方法(通过添加凭据等推送到 dockerHub 存储库)时,运行 成功。
上面的代码运行没有错误,但是后面的图片我找不到了,不知道为什么。
我一定是哪里出错了。这是一个大学项目,如果你有任何我可以阅读的关于这些主题的文档,那将对我有很大帮助。
public void buildLocalImage(String appName) throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException {
Jib.from("openjdk:15")
.addLayer(Arrays.asList(Paths.get("jars/"+appName+".jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/local-kube-api.jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/script.sh")), AbsoluteUnixPath.get("/"))
.setEntrypoint("sh","/script.sh")
.containerize(
Containerizer.to(TarImage.at(Paths.get("images/"+appName+"-image:latest.tar"))
.named(appName+"-image:latest")));
}
通过构建 .tar 图像,然后通过 docker load < image_name
将其加载到 docker,您可以在容器中存储和 运行 多个本地 docker 图像
我正在请求帮助使用 jib-core 创建本地 Docker 图像。
我知道如何将图像推送到 DockerHub Repo,但现在我想将所有图像放入本地单个存储库。
到目前为止我做了什么:
- 通过阅读 jib-core 文档,成功创建了一个 image.tar 但无法构建它(缺少 dockerfile)
目前我是这样做的:
public void buildLocalImage(String appName) throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException {
Jib.from("openjdk:15")
.addLayer(Arrays.asList(Paths.get("jars/"+appName+".jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/local-kube-api.jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/script.sh")), AbsoluteUnixPath.get("/"))
.setEntrypoint("sh","/script.sh")
.containerize(
Containerizer.to(DockerDaemonImage.named("images/"+appName+"-images:TEST")).setOfflineMode(true)
);
}
最终目标是在一个容器中 运行 2 个罐子,当我使用传统方法(通过添加凭据等推送到 dockerHub 存储库)时,运行 成功。
上面的代码运行没有错误,但是后面的图片我找不到了,不知道为什么。
我一定是哪里出错了。这是一个大学项目,如果你有任何我可以阅读的关于这些主题的文档,那将对我有很大帮助。
public void buildLocalImage(String appName) throws InvalidImageReferenceException, IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException {
Jib.from("openjdk:15")
.addLayer(Arrays.asList(Paths.get("jars/"+appName+".jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/local-kube-api.jar")), AbsoluteUnixPath.get("/"))
.addLayer(Arrays.asList(Paths.get("jars/script.sh")), AbsoluteUnixPath.get("/"))
.setEntrypoint("sh","/script.sh")
.containerize(
Containerizer.to(TarImage.at(Paths.get("images/"+appName+"-image:latest.tar"))
.named(appName+"-image:latest")));
}
通过构建 .tar 图像,然后通过 docker load < image_name
将其加载到 docker,您可以在容器中存储和 运行 多个本地 docker 图像