如何解决使用 Jib-Core 将 Docker 镜像容器化到特定的本地目录
我正在寻求帮助以使用 jib-core 创建本地 Docker 映像。
我知道如何将图像推送到 DockerHub 存储库,但现在我想将所有图像放入本地单个存储库。
到目前为止我所做的:
- 通过阅读 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 个 jar,当我使用传统方式(即通过添加凭据等推送到 dockerHub 存储库)时,这些 jar 可以成功运行。
上面的代码运行没有错误,但是我找不到后面的图片,不知道为什么。
我一定是哪里出错了。这是一个大学项目,如果您有任何我可以阅读的有关这些主题的文档,那将对我有很大帮助。
解决方法
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 镜像
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。