diff --git a/client/driver/docker.go b/client/driver/docker.go index 48897077c03..e7d671c8add 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -69,6 +69,16 @@ type DockerDriverConfig struct { LabelsRaw []map[string]string `mapstructure:"labels"` // Labels map[string]string `mapstructure:"-"` // Labels to set when the container starts up Auth []DockerDriverAuth `mapstructure:"auth"` // Authentication credentials for a private Docker registry + SSL bool `mapstructure:"ssl"` // Flag indicating repository is served via https +} + +func (c *DockerDriverConfig) Init() error { + if strings.Contains(c.ImageName, "https://") { + c.SSL = true + c.ImageName = strings.Replace(c.ImageName, "https://", "", 1) + } + + return nil } func (c *DockerDriverConfig) Validate() error { @@ -410,6 +420,11 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil { return nil, err } + + if err := driverConfig.Init(); err != nil { + return nil, err + } + image := driverConfig.ImageName if err := driverConfig.Validate(); err != nil { @@ -473,7 +488,14 @@ 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 driverConfig.SSL { + authConfigurationKey += "https://" + } + + authConfigurationKey += strings.Split(driverConfig.ImageName, "/")[0] + if authConfiguration, ok := authConfigurations.Configs[authConfigurationKey]; ok { authOptions = authConfiguration } } else { diff --git a/website/source/docs/drivers/docker.html.md b/website/source/docs/drivers/docker.html.md index cbf4edde72a..e21ed6eebaa 100644 --- a/website/source/docs/drivers/docker.html.md +++ b/website/source/docs/drivers/docker.html.md @@ -32,7 +32,7 @@ task "webservice" { The following options are available for use in the job specification. -* `image` - The Docker image to run. The image may include a tag or custom URL. +* `image` - The Docker image to run. The image may include a tag or custom URL and should include `https://` if required. By default it will be fetched from Docker Hub. * `command` - (Optional) The command to run when starting the container. @@ -248,7 +248,7 @@ The `docker` driver has the following host-level configuration options: location). * `docker.auth.config` - Allows an operator to specify a json file which is in - the dockercfg format containing authentication information for private registry. + the dockercfg format containing authentication information for private registry. * `docker.tls.cert` - Path to the server's certificate file (`.pem`). Specify this along with `docker.tls.key` and `docker.tls.ca` to use a TLS client to