【问题标题】:Volumes in testcontainers-go测试容器中的卷-go
【发布时间】:2020-09-16 11:19:40
【问题描述】:

我有一个 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 声明之间有什么区别。

【问题讨论】:

    标签: docker go docker-compose openldap testcontainers


    【解决方案1】:

    答案其实就在问题中,在这种情况下:

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

    需要添加到testcontainers.ContainerRequest

    来自osixia/docker-openldap 文档:

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

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

    【讨论】:

      猜你喜欢
      • 2020-06-05
      • 2022-11-09
      • 2016-04-25
      • 1970-01-01
      • 2013-06-30
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      相关资源
      最近更新 更多