How to fix runtime error: index out of range [0] with length 0

  docker, go, port

I’m using testcontainers-go package and basically I’m using the following snippet:

    req := testcontainers.ContainerRequest{
        Image: "adven27/grpc-wiremock:0.0.8",
        ExposedPorts: []string{
            fmt.Sprintf("%s/tcp", wiremockHttpContainerPort),
            fmt.Sprintf("%s/tcp", proxyGrpcContainerPort),
        },
        BindMounts: map[string]string{protoFilesPath: "/proto"},
        WaitingFor: wait.ForLog("Started GrpcWiremock in").WithStartupTimeout(time.Minute * 5),
    }
    // piece of line below causes the isue
    wiremockContainer, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
        ContainerRequest: req,
        Started:          true,
    })

The thing is, it started failing with

test panicked: runtime error: index out of range [0] with length 0

and it seems like the core issue is here:
https://github.com/testcontainers/testcontainers-go/blob/master/docker.go#L136

I used to have this issue before but restarting did help usually but not this time around.

Source: Docker Questions

LEAVE A COMMENT