我正在使用testcontainers-go库的第一步,我遇到了这样的问题:
testcontainers_test.go:25: Error response from daemon: No such image: d79b11e4-647c-4064-9e6f-94a626c9287d:964a49e9-0b99-42f5-acba-851d95792857: failed to create container
--- FAIL: TestWithRedis (23.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0xe0 pc=0x8d6731]
我的源代码几乎和docs中的完全一样
package xx
import (
"context"
"testing"
"github.com/testcontainers/testcontainers-go"
)
var token = "xxx"
var customVersion = "v1.11"
var http_proxy = "xxx"
var https_proxy = "xxx"
var no_proxy = "xxx"
func TestWithRedis(t *testing.T) {
ctx := context.Background()
req := testcontainers.ContainerRequest{FromDockerfile: testcontainers.FromDockerfile{
Context: "/home/usr/project", // this is where I have my Dockerfile
Dockerfile: "Dockerfile",
BuildArgs: map[string]*string{
"TOKEN": &token,
"CUSTOM_VERSION": &customVersion,
"http_proxy": &http_proxy,
"https_proxy": &https_proxy,
"no_proxy": &no_proxy,
},
},
}
redisC, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
ProviderType: 0,
Logger: nil,
Reuse: false,
})
if err != nil {
t.Error(err) // this is line 25 where the error from above refers to
}
defer func() {
if err := redisC.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err.Error())
}
}()
}
当我从命令行构建时,一切都工作正常:docker build --pull --build-arg TOKEN="xxx" --build-arg CUSTOM_VERSION="v1.11" --build-arg http_proxy --build-arg https_proxy --build-arg no_proxy .
你知道这是怎么回事吗Dockerfile本身运行良好,所以情况并非如此,错误信息对我毫无帮助。
1条答案
按热度按时间wljmcqd81#
使用
PrintBuildLog: true
后,显示原因是使用了buildkit,显然此时testcontainers对此没有任何解决方案。