docker - GoLang postgres testcontainer 将 BindMounts 转换为 Mounts

标签 docker go docker-compose testcontainers

我刚刚将测试容器库从 github.com/testcontainers/testcontainers-go v0.12.0 升级到 github.com/testcontainers/testcontainers-go v0.13.0 以前这是我创建请求的方式

    ContainerRequest: testcontainers.ContainerRequest{
            Image:          mountebankImage,
            Name:           uuid.New().String(),
            ExposedPorts:   []string{mountebankExposedPort},
            BindMounts:     map[string]string{"/mountebank": path.Join(c.rootDir, "/test/stubs/mountebank")},
            Entrypoint:     []string{"mb", "start", "--configfile", "/mountebank/imposters.ejs"},
            Networks:       []string{c.network.Name},
   

在最新版本的测试容器库中,BindMounts(不再支持 link )已被 Mounts 取代。 尝试在我的初始化脚本中替换相同的内容,但找不到它。

BindMounts:     map[string]string{"/mountebank": path.Join(c.rootDir, "/test/stubs/mountebank")},

它是请求正文的一部分。尝试使用 testcontainers.ContainerMounts{} 等。

我错过了什么吗?

最佳答案

ContainerRequest对象包含 ContainerMount 的列表对象,记录了

Source is typically either a GenericBindMountSource or a GenericVolumeMountSource

GenericBindMountSource只是命名一个主机路径。您还可以使用DockerBindMountSource如果您需要高级选项。

因此,您应该能够将 BindMounts: 参数替换为 Mounts:

ContainerRequest: testcontainers.ContainerRequest{
        Mounts: testcontainers.Mounts(testcontainers.ContainerMount{
                Source: testcontainers.GenericBindMountSource{
                        HostPath: path.Join(c.rootDir, "/test/stubs/mountebank"),
                },
                Target: testcontainers.ContainerMountTarget("/mountebank"),
        }),
        ...
},

关于docker - GoLang postgres testcontainer 将 BindMounts 转换为 Mounts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72181947/

相关文章:

go - 未反射(reflect)在实例上替换的字符串数组

google-app-engine - 使用 Google App Engine 的 OAuth2

mysql - 尝试通过 docker-compose 将 NodeJS 应用程序连接到 MySQL 图像时 ECONNREFUSED

vagrant - 如何将其转换为在Vagrant中运行的Docker容器?

docker - Docker-Compose:是否可以在不同容器上强制使用IP地址?

docker - 在docker中将ksql与融合版本3.3.0的kafka连接的问题

docker - Keycloak 无法在 Docker 撰写文件中工作。我该如何修复它?

tomcat - 访问docker容器内的Tomcat时出现CORS错误

post - 如何在 golang 中编码 POST 策略 - 基于浏览器的上传到 amazon S3?

python - 为 docker-compose 文件设置预 Hook