为了账号安全,请及时绑定邮箱和手机立即绑定

测试容器中的卷-go

测试容器中的卷-go

Go
HUX布斯 2022-06-06 16:05:37
我有一个 docker-compose 文件,我正在尝试使用testcontainers-go重新创建它:version: '3'services:  node1:    image: "osixia/openldap:1.3.0"    command: ['--copy-service', '--loglevel=debug']    environment:      - LDAP_ORGANISATION=Test      - LDAP_DOMAIN=test.com      - LDAP_BASE_DN=dc=test,dc=com      - LDAP_TLS=false    ports:      - "3898:389"    volumes:      - "/path/to/testdata/node1.ldif:/container/service/slapd/assets/config/bootstrap/ldif/custom/node1.ldif"下面是go代码:ldapPort, err := nat.NewPort("tcp", "389")if err != nil {    panic(err)}ctx := context.Background()req := testcontainers.ContainerRequest{    Image:        imageName,    ExposedPorts: []string{ldapPort.Port() + "/" + ldapPort.Proto()},    Env: map[string]string{        "LDAP_ORGANISATION": "Test",        "LDAP_DOMAIN": "test.com",        "LDAP_BASE_DN": "dc=test,dc=com",        "LDAP_TLS": "false",    },    BindMounts: map[string]string{        "/path/to/testdata/node1.ldif":            "/container/service/slapd/assets/config/bootstrap/ldif/custom/node.ldif",    },    WaitingFor:   wait.ForLog("slapd starting"),}ldapC, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{    ContainerRequest: req,    Started:          true,})if err != nil {    panic(err)}defer ldapC.Terminate(ctx)docker-compose 文件工作正常,但是当我尝试使用 go 运行容器时,容器崩溃,并且它的日志包含以下内容:sed: cannot rename /container/service/slapd/assets/config/bootstrap/ldif/custom/sedah0ove: Device or resource busy我不确定 go 代码和 docker-compose 声明之间有什么区别。
查看完整描述

1 回答

?
ibeautiful

TA贡献1993条经验 获得超5个赞

答案实际上在问题中,在这种情况下:

Cmd:          []string{"--copy-service"}

需要添加到testcontainers.ContainerRequest.

来自osxia/docker-openldap文档:

由于启动脚本会修改 ldif 文件,因此如果您不想覆盖它们,则必须将 --copy-service 参数添加到入口点。

我将此添加到我的 docker-compose 文件中,但在 Go 代码中忘记了它。


查看完整回答
反对 回复 2022-06-06
  • 1 回答
  • 0 关注
  • 131 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信