Skip to content

Commit ef61195

Browse files
authored
Merge pull request testcontainers#4 from gianarb/feature/pull-image-and-auth
Pull image and accept registry out
2 parents c1d0092 + f0e5d4b commit ef61195

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docker.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type RequestContainer struct {
1616
Env map[string]string
1717
ExportedPort []string
1818
Cmd string
19+
RegistryCred string
1920
}
2021

2122
// Container is the struct used to represent a single container.
@@ -90,6 +91,15 @@ func RunContainer(ctx context.Context, containerImage string, input RequestConta
9091
dockerInput.Cmd = strings.Split(input.Cmd, " ")
9192
}
9293

94+
pullOpt := types.ImagePullOptions{}
95+
if input.RegistryCred != "" {
96+
pullOpt.RegistryAuth = input.RegistryCred
97+
}
98+
_, err = cli.ImagePull(ctx, dockerInput.Image, pullOpt)
99+
if err != nil {
100+
return nil, err
101+
}
102+
93103
resp, err := cli.ContainerCreate(ctx, dockerInput, nil, nil, "")
94104
if err != nil {
95105
return nil, err

0 commit comments

Comments
 (0)