From f0e5d4b1211b302d82376296798847500d05a4dc Mon Sep 17 00:00:00 2001 From: Gianluca Arbezzano Date: Tue, 24 Jul 2018 17:02:08 +0200 Subject: [PATCH] Pull image and accept registry out Other than pulling an image to be sure that it exists this PR introduced a mechanism to download images from a private repository. Signed-off-by: Gianluca Arbezzano --- docker.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docker.go b/docker.go index aba07d706a4..ba26365a5c6 100644 --- a/docker.go +++ b/docker.go @@ -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. @@ -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