diff --git a/client/driver/docker.go b/client/driver/docker.go index 48e65f6fe2a8..8448f5d6b2e5 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net" + "net/url" "os" "os/exec" "path/filepath" @@ -471,7 +472,20 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle if authConfigurations, err = docker.NewAuthConfigurations(f); err != nil { return nil, fmt.Errorf("Failed to create docker auth object: %v", err) } - if authConfiguration, ok := authConfigurations.Configs[repo]; ok { + authConfigurationKey := "" + + if parsedUrl, err := url.Parse(repo); err == nil { + if parsedUrl.Scheme != "" { + authConfigurationKey += parsedUrl.Scheme + "://" + } + + authConfigurationKey += parsedUrl.Host + pullOptions.Repository = parsedUrl.Host + parsedUrl.Path + } else { + return nil, fmt.Errorf("Failed to parse image repo: %v", err) + } + + if authConfiguration, ok := authConfigurations.Configs[authConfigurationKey]; ok { authOptions = authConfiguration } } else { @@ -487,6 +501,8 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle d.logger.Printf("[DEBUG] driver.docker: docker pull %s:%s succeeded", repo, tag) // Now that we have the image we can get the image id + driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1) + image = driverConfig.ImageName dockerImage, err = client.InspectImage(image) if err != nil { d.logger.Printf("[ERR] driver.docker: failed getting image id for %s: %s", image, err)