Reputation: 763
I am getting error [ERROR] when trying to pull image through test container. Reason CI machines in your organisation have access to a common registry server and is not allowed to talk to external web. Testcontainer java has something like for this use case
Private registry image name
// Referring directly to an image on a private registry - image name will vary
final MySQLContainer<?> mysql = new MySQLContainer<>(
DockerImageName.parse("registry.mycompany.com/mirror/mysql:8.0.24")
.asCompatibleSubstituteFor("mysql")
)
what's the go equivalent to override image registry urls that testcontainer-go uses?
Code
req := testcontainers.ContainerRequest{
Image: "amazon/dynamodb-local:1.15.0",
ExposedPorts: []string{"8000" + "/tcp"},
ReaperImage: artifact_path,
}
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
// auto-start the container
Started: true,
})
[ERROR]
2021/09/28 20:21:11 Failed to pull image: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers), will retry
Upvotes: 5
Views: 2232
Reputation: 111
Have you tried to put the fully qualified image name in the container request and passing your registry credentials?
func TestFoo(t *testing.T) {
authConfig := types.AuthConfig{
Username: os.Getenv("DOCKER_USER"),
Password: os.Getenv("DOCKER_PWD"),
}
json, err := json.Marshal(authConfig)
assert.Nil(t, err)
req := testcontainers.ContainerRequest{
Image: "docker.my-company.org/my-namespace/dynamodb-local:1.15.0",
ExposedPorts: []string{"8000" + "/tcp"},
RegistryCred: base64.URLEncoding.EncodeToString(json),
}
container, err := testcontainers.GenericContainer(context.Background(), testcontainers.GenericContainerRequest{
ContainerRequest: req,
// auto-start the container
Started: true,
})
assert.Nil(t, err)
assert.NotNil(t, container)
}
As far as I see in the code, there is no replacer function as in the Java version, but I do not think it makes sense, as in Java they have MySQL containers, as opposite what the Go version does, which does not have specialised containers. Therefore, in the Java version it makes sense to replace the default image for the mysql container.
Update from Oct 11th, 2023: There is an open PR to provide image name substitutors to testcontainers-go: https://github.com/testcontainers/testcontainers-go/pull/1719
Hopefully that would help
Upvotes: 0