mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #27857 from vasil-yordanov/docker-service-hostname-2
Adding the hostname option to docker service command
This commit is contained in:
commit
b4e14c6edc
6 changed files with 31 additions and 16 deletions
|
@ -13,6 +13,7 @@ type ContainerSpec struct {
|
||||||
Labels map[string]string `json:",omitempty"`
|
Labels map[string]string `json:",omitempty"`
|
||||||
Command []string `json:",omitempty"`
|
Command []string `json:",omitempty"`
|
||||||
Args []string `json:",omitempty"`
|
Args []string `json:",omitempty"`
|
||||||
|
Hostname string `json:",omitempty"`
|
||||||
Env []string `json:",omitempty"`
|
Env []string `json:",omitempty"`
|
||||||
Dir string `json:",omitempty"`
|
Dir string `json:",omitempty"`
|
||||||
User string `json:",omitempty"`
|
User string `json:",omitempty"`
|
||||||
|
|
|
@ -33,6 +33,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
|
|
||||||
flags.VarP(&opts.labels, flagLabel, "l", "Service labels")
|
flags.VarP(&opts.labels, flagLabel, "l", "Service labels")
|
||||||
flags.Var(&opts.containerLabels, flagContainerLabel, "Container 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.VarP(&opts.env, flagEnv, "e", "Set environment variables")
|
||||||
flags.Var(&opts.envFile, flagEnvFile, "Read in a file of environment variables")
|
flags.Var(&opts.envFile, flagEnvFile, "Read in a file of environment variables")
|
||||||
flags.Var(&opts.mounts, flagMount, "Attach a filesystem mount to the service")
|
flags.Var(&opts.mounts, flagMount, "Attach a filesystem mount to the service")
|
||||||
|
|
|
@ -316,6 +316,7 @@ type serviceOptions struct {
|
||||||
containerLabels opts.ListOpts
|
containerLabels opts.ListOpts
|
||||||
image string
|
image string
|
||||||
args []string
|
args []string
|
||||||
|
hostname string
|
||||||
env opts.ListOpts
|
env opts.ListOpts
|
||||||
envFile opts.ListOpts
|
envFile opts.ListOpts
|
||||||
workdir string
|
workdir string
|
||||||
|
@ -387,6 +388,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
||||||
Image: opts.image,
|
Image: opts.image,
|
||||||
Args: opts.args,
|
Args: opts.args,
|
||||||
Env: currentEnv,
|
Env: currentEnv,
|
||||||
|
Hostname: opts.hostname,
|
||||||
Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()),
|
Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()),
|
||||||
Dir: opts.workdir,
|
Dir: opts.workdir,
|
||||||
User: opts.user,
|
User: opts.user,
|
||||||
|
@ -486,6 +488,7 @@ const (
|
||||||
flagContainerLabelRemove = "container-label-rm"
|
flagContainerLabelRemove = "container-label-rm"
|
||||||
flagContainerLabelAdd = "container-label-add"
|
flagContainerLabelAdd = "container-label-add"
|
||||||
flagEndpointMode = "endpoint-mode"
|
flagEndpointMode = "endpoint-mode"
|
||||||
|
flagHostname = "hostname"
|
||||||
flagEnv = "env"
|
flagEnv = "env"
|
||||||
flagEnvFile = "env-file"
|
flagEnvFile = "env-file"
|
||||||
flagEnvRemove = "env-rm"
|
flagEnvRemove = "env-rm"
|
||||||
|
|
|
@ -13,14 +13,15 @@ import (
|
||||||
|
|
||||||
func containerSpecFromGRPC(c *swarmapi.ContainerSpec) types.ContainerSpec {
|
func containerSpecFromGRPC(c *swarmapi.ContainerSpec) types.ContainerSpec {
|
||||||
containerSpec := types.ContainerSpec{
|
containerSpec := types.ContainerSpec{
|
||||||
Image: c.Image,
|
Image: c.Image,
|
||||||
Labels: c.Labels,
|
Labels: c.Labels,
|
||||||
Command: c.Command,
|
Command: c.Command,
|
||||||
Args: c.Args,
|
Args: c.Args,
|
||||||
Env: c.Env,
|
Hostname: c.Hostname,
|
||||||
Dir: c.Dir,
|
Env: c.Env,
|
||||||
User: c.User,
|
Dir: c.Dir,
|
||||||
Groups: c.Groups,
|
User: c.User,
|
||||||
|
Groups: c.Groups,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mounts
|
// Mounts
|
||||||
|
@ -67,14 +68,15 @@ func containerSpecFromGRPC(c *swarmapi.ContainerSpec) types.ContainerSpec {
|
||||||
|
|
||||||
func containerToGRPC(c types.ContainerSpec) (*swarmapi.ContainerSpec, error) {
|
func containerToGRPC(c types.ContainerSpec) (*swarmapi.ContainerSpec, error) {
|
||||||
containerSpec := &swarmapi.ContainerSpec{
|
containerSpec := &swarmapi.ContainerSpec{
|
||||||
Image: c.Image,
|
Image: c.Image,
|
||||||
Labels: c.Labels,
|
Labels: c.Labels,
|
||||||
Command: c.Command,
|
Command: c.Command,
|
||||||
Args: c.Args,
|
Args: c.Args,
|
||||||
Env: c.Env,
|
Hostname: c.Hostname,
|
||||||
Dir: c.Dir,
|
Env: c.Env,
|
||||||
User: c.User,
|
Dir: c.Dir,
|
||||||
Groups: c.Groups,
|
User: c.User,
|
||||||
|
Groups: c.Groups,
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.StopGracePeriod != nil {
|
if c.StopGracePeriod != nil {
|
||||||
|
|
|
@ -128,6 +128,7 @@ func (c *containerConfig) config() *enginecontainer.Config {
|
||||||
config := &enginecontainer.Config{
|
config := &enginecontainer.Config{
|
||||||
Labels: c.labels(),
|
Labels: c.labels(),
|
||||||
User: c.spec().User,
|
User: c.spec().User,
|
||||||
|
Hostname: c.spec().Hostname,
|
||||||
Env: c.spec().Env,
|
Env: c.spec().Env,
|
||||||
WorkingDir: c.spec().Dir,
|
WorkingDir: c.spec().Dir,
|
||||||
Image: c.image(),
|
Image: c.image(),
|
||||||
|
|
|
@ -32,6 +32,7 @@ Options:
|
||||||
--health-retries int Consecutive failures needed to report unhealthy
|
--health-retries int Consecutive failures needed to report unhealthy
|
||||||
--health-timeout duration Maximum time to allow one check to run
|
--health-timeout duration Maximum time to allow one check to run
|
||||||
--help Print usage
|
--help Print usage
|
||||||
|
--hostname Service containers hostname
|
||||||
-l, --label value Service labels (default [])
|
-l, --label value Service labels (default [])
|
||||||
--limit-cpu value Limit CPUs (default 0.000)
|
--limit-cpu value Limit CPUs (default 0.000)
|
||||||
--limit-memory value Limit Memory (default 0 B)
|
--limit-memory value Limit Memory (default 0 B)
|
||||||
|
@ -134,6 +135,12 @@ This sets environmental variables for all tasks in a service. For example:
|
||||||
$ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6
|
$ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Create a docker service with specific hostname (--hostname)
|
||||||
|
|
||||||
|
This option sets the docker service containers hostname to a specific string. For example:
|
||||||
|
```bash
|
||||||
|
$ docker service create --name redis --hostname myredis redis:3.0.6
|
||||||
|
```
|
||||||
### Set metadata on a service (-l, --label)
|
### Set metadata on a service (-l, --label)
|
||||||
|
|
||||||
A label is a `key=value` pair that applies metadata to a service. To label a
|
A label is a `key=value` pair that applies metadata to a service. To label a
|
||||||
|
|
Loading…
Add table
Reference in a new issue