测试容器中的卷-go

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


HUX布斯
浏览 132回答 1
1回答

ibeautiful

答案实际上在问题中,在这种情况下:Cmd:          []string{"--copy-service"}需要添加到testcontainers.ContainerRequest.来自osxia/docker-openldap文档:由于启动脚本会修改 ldif 文件,因此如果您不想覆盖它们,则必须将 --copy-service 参数添加到入口点。我将此添加到我的 docker-compose 文件中,但在 Go 代码中忘记了它。
打开App,查看更多内容
随时随地看视频慕课网APP