使用自定义的Dockerfile运行testcontainers:没有这样的镜像。

huangapple go评论78阅读模式
英文:

Running testcontainers with a custom Dockerfile: no such image

问题

从<custom-name>.artifactory.<company>.net/base/gobuilder:latest作为构建器开始
...


从<custom-name>.artifactory.<company>.net/base/distroless-base:<hash>开始
...

我在testcontainers库中遇到了一个问题。在大部分情况下,它只是运行Docker容器,所以我猜答案更多地与Docker相关,而不是与库本身相关。

你可以看到我使用我们公司在Artifactory注册表中的镜像的Dockerfile的大纲。在CI/CD中它工作得很好,但出于某种原因,在这个库中却不起作用。

	req := testcontainers.ContainerRequest{
		FromDockerfile: testcontainers.FromDockerfile{
			Context:    "/path/to/context/",
			Dockerfile: "Dockerfile",
		},
	}

	container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
		ContainerRequest: req,
		Started:          true,
	})

这是我在代码中创建容器的方式。

我得到的错误是:

Error response from daemon: no such image: 9305d9c8-1cfe-4c16-924b-3f734757d016:a6417aac-340b-4c37-a785-a45aa11f9ede: No such image: 9305d9c8-1cfe-4c16-924b-3f734757d016:a6417aac-340b-4c37-a785-a45aa11f9ede: failed to create container
--- FAIL: TestContainer

然而,如果我运行docker images -a,我可以看到列出的镜像:

<custom-name>.artifactory.<company>.net/base/gobuilder   latest        0ca0c1df3fa1   3 months ago    935MB

我尝试多次重启Docker服务,但没有成功。

我还可以尝试什么?

作为一个实验,我尝试使用Go的公共镜像,但得到了相同的错误。当返回错误时,它显示了一个不存在的镜像哈希,这也很奇怪。


<details>
<summary>英文:</summary>

FROM <custom-name>.artifactory.<company>.net/base/gobuilder:latest as builder
...

FROM <custom-name>.artifactory.<company>.net/base/distroless-base:<hash>
...


I have an issue with the testcontainers library. For the most part, it just runs Docker containers so I guess the answer is more Docker-specific rather than bound to the library itself. 

You can see the outline of my Dockerfile that uses our company&#39;s images in our Artifactory registry. It works just fine in CI/CD but for some reason doesn&#39;t with this library. 

req := testcontainers.ContainerRequest{
	FromDockerfile: testcontainers.FromDockerfile{
		Context:    &quot;/path/to/context/,
		Dockerfile: &quot;Dockerfile&quot;,
	},
}

container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
	ContainerRequest: req,
	Started:          true,
})

This is how I create the container in my code. 

What I get is this error:

Error response from daemon: no such image: 9305d9c8-1cfe-4c16-924b-3f734757d016:a6417aac-340b-4c37-a785-a45aa11f9ede: No such image: 9305d9c8-1cfe-4c16-924b-3f734757d016:a6417aac-340b-4c37-a785-a45aa11f9ede: failed to create container
--- FAIL: TestContainer


Nonetheless, if I run `docker images -a`, I see the image listed:

<custom-name>.artifactory.<company>.net/base/gobuilder latest 0ca0c1df3fa1 3 months ago 935MB


I have tried to restart the Docker service multiple times but with no luck. 

What else could I try? 

As an experiment, I tried to use a public image for Go but got the same error. It&#39;s also strange that it shows a non-existing image hash when returning the error. 

</details>


# 答案1
**得分**: 2

我们使用的是Testcontainers for Go的哪个版本?在最新的发布版本v0.19.0中,可以从私有注册表构建Dockerfile,而无需传递凭据,因为Docker凭据助手会自动发现它们。https://golang.testcontainers.org/features/docker_auth/

在以前的版本中,你被迫将认证凭据作为`FromDockerfile`结构的一部分传递。

<details>
<summary>英文:</summary>

What version of Testcontainers for Go do you use? In the latest release, v0.19.0, it&#39;s possible to build from a Dockerfile from private registries without passing the credentials, as they will be automatically discovered by the Docker credentials helpers. https://golang.testcontainers.org/features/docker_auth/


    req := ContainerRequest{
    FromDockerfile: testcontainers.FromDockerfile{
        Context: &quot;/path/to/build/context&quot;,
        Dockerfile: &quot;CustomDockerfile&quot;,
        BuildArgs: map[string]*string {
            &quot;FOO&quot;: &quot;BAR&quot;,
        },
    },
}

In previous versions you were forced to pass the auth credentials as part of the `FromDockerfile` struct.

</details>



huangapple
  • 本文由 发表于 2023年3月8日 02:58:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75666125.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定