0

我正在寻求一些帮助来使用 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 存储库的传统方式时,它们可以成功运行。

上面的代码运行没有错误,但是我找不到它之后的图像,我不知道为什么。

我一定是哪里出错了。这是一个大学项目,如果您有任何我可以阅读的有关这些主题的文档,那将对我有很大帮助。

4

1 回答 1

0
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,docker load < image_name您可以在容器中存储和运行多个本地 docker 映像

于 2020-12-21T11:38:57.007 回答