You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法配置Testcontainers Docker:拉取ryuk镜像失败求助

问题:Testcontainers拉取ryuk镜像失败,提示需docker login(已登录)

我们的集成测试需要用到docker.io/testcontainers/ryuk镜像,但执行命令go test ./... --tags=integration -v时,反复出现以下错误:

=== RUN   TestLambda
2023/06/15 17:14:21 github.com/testcontainers/testcontainers-go - Connected to docker:
  Server Version: 24.0.2
  API Version: 1.42
  Operating System: Docker Desktop
  Total Memory: 7851 MB
Setting HOSTNAME_EXTERNAL to localhost (to match host-routable address for container)
2023/06/15 17:14:22 Failed to get image auth for docker.io. Setting empty credentials for the image: docker.io/testcontainers/ryuk:0.4.0. Error is:credentials not found in native keychain
2023/06/15 17:14:22 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
2023/06/15 17:14:23 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
2023/06/15 17:14:24 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
2023/06/15 17:14:25 Failed to pull image: Error response from daemon: Please run 'docker login', will retry

我已完成Docker登录,能正常拉取Redis等其他镜像,请问遗漏了什么配置?


更新1

运行测试代码后,仍出现相同错误,输出如下:

go test ./... --tags=integration -v
=== RUN   TestMongoDB
2023/06/16 08:29:40 github.com/testcontainers/testcontainers-go - Connected to docker:
  Server Version: 24.0.2
  API Version: 1.42
  Operating System: Docker Desktop
  Total Memory: 7851 MB
2023/06/16 08:29:41 Failed to get image auth for docker.io. Setting empty credentials for the image: docker.io/testcontainers/ryuk:0.4.0. Error is:credentials not found in native keychain
2023/06/16 08:29:41 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
2023/06/16 08:29:41 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
2023/06/16 08:29:42 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
2023/06/16 08:29:44 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
2023/06/16 08:29:46 Failed to pull image: Error response from daemon: Please run 'docker login', will retry
^Z
[7]  + 40346 suspended  go test ./... --tags=integration -v

我的Docker配置文件内容:

{
        "auths": {
                "https://index.docker.io/v1/": {}
        },
        "credsStore": "desktop",
        "currentContext": "desktop-linux"
}

解决方案

  • 升级testcontainers-go版本:旧版本对Docker Desktop的credsStore: desktop支持存在缺陷,升级到最新稳定版即可解决。执行命令:

    go get github.com/testcontainers/testcontainers-go@latest
    
  • 调整Docker凭证存储配置:临时修改~/.docker/config.json,将"credsStore": "desktop"替换为对应系统的凭证存储(Mac用osxkeychain,Windows用wincred),或直接注释该行(注意:注释后凭证会明文存储,存在安全风险)。

  • 手动拉取ryuk镜像:先手动执行拉取命令,确保本地已有镜像后再运行测试:

    docker pull docker.io/testcontainers/ryuk:0.4.0
    
  • 禁用ryuk镜像的凭证检查:通过环境变量跳过凭证验证,直接运行测试:

    TESTCONTAINERS_RYUK_DISABLE_AUTH=true go test ./... --tags=integration -v
    

内容的提问来源于stack exchange,提问作者rsundhar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 03:50:09