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

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

Running testcontainers with a custom Dockerfile: no such image

问题

  1. 从<custom-name>.artifactory.<company>.net/base/gobuilder:latest作为构建器开始
  2. ...
  3. 从<custom-name>.artifactory.<company>.net/base/distroless-base:<hash>开始
  4. ...

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

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

  1. req := testcontainers.ContainerRequest{
  2. FromDockerfile: testcontainers.FromDockerfile{
  3. Context: "/path/to/context/",
  4. Dockerfile: "Dockerfile",
  5. },
  6. }
  7. container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
  8. ContainerRequest: req,
  9. Started: true,
  10. })

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

我得到的错误是:

  1. 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
  2. --- FAIL: TestContainer

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

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

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

我还可以尝试什么?

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

  1. <details>
  2. <summary>英文:</summary>

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

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

  1. 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.
  2. 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.
  1. req := testcontainers.ContainerRequest{
  2. FromDockerfile: testcontainers.FromDockerfile{
  3. Context: &quot;/path/to/context/,
  4. Dockerfile: &quot;Dockerfile&quot;,
  5. },
  6. }
  7. container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
  8. ContainerRequest: req,
  9. Started: true,
  10. })
  1. This is how I create the container in my code.
  2. 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

  1. 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

  1. I have tried to restart the Docker service multiple times but with no luck.
  2. What else could I try?
  3. 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.
  4. </details>
  5. # 答案1
  6. **得分**: 2
  7. 我们使用的是Testcontainers for Go的哪个版本?在最新的发布版本v0.19.0中,可以从私有注册表构建Dockerfile,而无需传递凭据,因为Docker凭据助手会自动发现它们。https://golang.testcontainers.org/features/docker_auth/
  8. 在以前的版本中,你被迫将认证凭据作为`FromDockerfile`结构的一部分传递。
  9. <details>
  10. <summary>英文:</summary>
  11. 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/
  12. req := ContainerRequest{
  13. FromDockerfile: testcontainers.FromDockerfile{
  14. Context: &quot;/path/to/build/context&quot;,
  15. Dockerfile: &quot;CustomDockerfile&quot;,
  16. BuildArgs: map[string]*string {
  17. &quot;FOO&quot;: &quot;BAR&quot;,
  18. },
  19. },
  20. }
  21. In previous versions you were forced to pass the auth credentials as part of the `FromDockerfile` struct.
  22. </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:

确定