diff --git a/components/cli/command/service/create.go b/components/cli/command/service/create.go index 28790ec8e6..430d448565 100644 --- a/components/cli/command/service/create.go +++ b/components/cli/command/service/create.go @@ -33,6 +33,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command { flags.VarP(&opts.labels, flagLabel, "l", "Service labels") flags.Var(&opts.containerLabels, flagContainerLabel, "Container labels") + flags.StringVar(&opts.hostname, flagHostname, "", "Container hostname") flags.VarP(&opts.env, flagEnv, "e", "Set environment variables") flags.Var(&opts.envFile, flagEnvFile, "Read in a file of environment variables") flags.Var(&opts.mounts, flagMount, "Attach a mount to the service") diff --git a/components/cli/command/service/opts.go b/components/cli/command/service/opts.go index 43b7b671cb..a134327356 100644 --- a/components/cli/command/service/opts.go +++ b/components/cli/command/service/opts.go @@ -455,6 +455,7 @@ type serviceOptions struct { containerLabels opts.ListOpts image string args []string + hostname string env opts.ListOpts envFile opts.ListOpts workdir string @@ -526,6 +527,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) { Image: opts.image, Args: opts.args, Env: currentEnv, + Hostname: opts.hostname, Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()), Dir: opts.workdir, User: opts.user, @@ -625,6 +627,7 @@ const ( flagContainerLabelRemove = "container-label-rm" flagContainerLabelAdd = "container-label-add" flagEndpointMode = "endpoint-mode" + flagHostname = "hostname" flagEnv = "env" flagEnvFile = "env-file" flagEnvRemove = "env-rm"