Skip to content

Commit

Permalink
Merge pull request testcontainers#4 from gianarb/feature/pull-image-a…
Browse files Browse the repository at this point in the history
…nd-auth

Pull image and accept registry out
  • Loading branch information
gianarb authored Jul 25, 2018
2 parents c1d0092 + f0e5d4b commit ef61195
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type RequestContainer struct {
Env map[string]string
ExportedPort []string
Cmd string
RegistryCred string
}

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

pullOpt := types.ImagePullOptions{}
if input.RegistryCred != "" {
pullOpt.RegistryAuth = input.RegistryCred
}
_, err = cli.ImagePull(ctx, dockerInput.Image, pullOpt)
if err != nil {
return nil, err
}

resp, err := cli.ContainerCreate(ctx, dockerInput, nil, nil, "")
if err != nil {
return nil, err
Expand Down

0 comments on commit ef61195

Please sign in to comment.