mirror of https://github.com/docker/cli.git
Merge pull request #1130 from cyphar/separate-domainname-flag
cli: add a separate --domainname flag
This commit is contained in:
commit
561f6e399c
|
@ -74,6 +74,7 @@ type containerOptions struct {
|
||||||
containerIDFile string
|
containerIDFile string
|
||||||
entrypoint string
|
entrypoint string
|
||||||
hostname string
|
hostname string
|
||||||
|
domainname string
|
||||||
memory opts.MemBytes
|
memory opts.MemBytes
|
||||||
memoryReservation opts.MemBytes
|
memoryReservation opts.MemBytes
|
||||||
memorySwap opts.MemSwapBytes
|
memorySwap opts.MemSwapBytes
|
||||||
|
@ -169,6 +170,7 @@ func addFlags(flags *pflag.FlagSet) *containerOptions {
|
||||||
flags.StringVar(&copts.entrypoint, "entrypoint", "", "Overwrite the default ENTRYPOINT of the image")
|
flags.StringVar(&copts.entrypoint, "entrypoint", "", "Overwrite the default ENTRYPOINT of the image")
|
||||||
flags.Var(&copts.groupAdd, "group-add", "Add additional groups to join")
|
flags.Var(&copts.groupAdd, "group-add", "Add additional groups to join")
|
||||||
flags.StringVarP(&copts.hostname, "hostname", "h", "", "Container host name")
|
flags.StringVarP(&copts.hostname, "hostname", "h", "", "Container host name")
|
||||||
|
flags.StringVar(&copts.domainname, "domainname", "", "Container NIS domain name")
|
||||||
flags.BoolVarP(&copts.stdin, "interactive", "i", false, "Keep STDIN open even if not attached")
|
flags.BoolVarP(&copts.stdin, "interactive", "i", false, "Keep STDIN open even if not attached")
|
||||||
flags.VarP(&copts.labels, "label", "l", "Set meta data on a container")
|
flags.VarP(&copts.labels, "label", "l", "Set meta data on a container")
|
||||||
flags.Var(&copts.labelsFile, "label-file", "Read in a line delimited file of labels")
|
flags.Var(&copts.labelsFile, "label-file", "Read in a line delimited file of labels")
|
||||||
|
@ -546,6 +548,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
|
||||||
|
|
||||||
config := &container.Config{
|
config := &container.Config{
|
||||||
Hostname: copts.hostname,
|
Hostname: copts.hostname,
|
||||||
|
Domainname: copts.domainname,
|
||||||
ExposedPorts: ports,
|
ExposedPorts: ports,
|
||||||
User: copts.user,
|
User: copts.user,
|
||||||
Tty: copts.tty,
|
Tty: copts.tty,
|
||||||
|
|
|
@ -265,14 +265,35 @@ func TestParseHostname(t *testing.T) {
|
||||||
hostnameWithDomainTld := "--hostname=hostname.domainname.tld"
|
hostnameWithDomainTld := "--hostname=hostname.domainname.tld"
|
||||||
for hostname, expectedHostname := range validHostnames {
|
for hostname, expectedHostname := range validHostnames {
|
||||||
if config, _ := mustParse(t, fmt.Sprintf("--hostname=%s", hostname)); config.Hostname != expectedHostname {
|
if config, _ := mustParse(t, fmt.Sprintf("--hostname=%s", hostname)); config.Hostname != expectedHostname {
|
||||||
t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
|
t.Fatalf("Expected the config to have 'hostname' as %q, got %q", expectedHostname, config.Hostname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname.domainname" && config.Domainname != "" {
|
if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname.domainname" || config.Domainname != "" {
|
||||||
t.Fatalf("Expected the config to have 'hostname' as hostname.domainname, got '%v'", config.Hostname)
|
t.Fatalf("Expected the config to have 'hostname' as hostname.domainname, got %q", config.Hostname)
|
||||||
}
|
}
|
||||||
if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname.domainname.tld" && config.Domainname != "" {
|
if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname.domainname.tld" || config.Domainname != "" {
|
||||||
t.Fatalf("Expected the config to have 'hostname' as hostname.domainname.tld, got '%v'", config.Hostname)
|
t.Fatalf("Expected the config to have 'hostname' as hostname.domainname.tld, got %q", config.Hostname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseHostnameDomainname(t *testing.T) {
|
||||||
|
validDomainnames := map[string]string{
|
||||||
|
"domainname": "domainname",
|
||||||
|
"domain-name": "domain-name",
|
||||||
|
"domainname123": "domainname123",
|
||||||
|
"123domainname": "123domainname",
|
||||||
|
"domainname-63-bytes-long-should-be-valid-and-without-any-errors": "domainname-63-bytes-long-should-be-valid-and-without-any-errors",
|
||||||
|
}
|
||||||
|
for domainname, expectedDomainname := range validDomainnames {
|
||||||
|
if config, _ := mustParse(t, "--domainname="+domainname); config.Domainname != expectedDomainname {
|
||||||
|
t.Fatalf("Expected the config to have 'domainname' as %q, got %q", expectedDomainname, config.Domainname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if config, _ := mustParse(t, "--hostname=some.prefix --domainname=domainname"); config.Hostname != "some.prefix" || config.Domainname != "domainname" {
|
||||||
|
t.Fatalf("Expected the config to have 'hostname' as 'some.prefix' and 'domainname' as 'domainname', got %q and %q", config.Hostname, config.Domainname)
|
||||||
|
}
|
||||||
|
if config, _ := mustParse(t, "--hostname=another-prefix --domainname=domainname.tld"); config.Hostname != "another-prefix" || config.Domainname != "domainname.tld" {
|
||||||
|
t.Fatalf("Expected the config to have 'hostname' as 'another-prefix' and 'domainname' as 'domainname.tld', got %q and %q", config.Hostname, config.Domainname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1802,6 +1802,7 @@ _docker_container_run_and_create() {
|
||||||
--dns
|
--dns
|
||||||
--dns-option
|
--dns-option
|
||||||
--dns-search
|
--dns-search
|
||||||
|
--domainname
|
||||||
--entrypoint
|
--entrypoint
|
||||||
--env -e
|
--env -e
|
||||||
--env-file
|
--env-file
|
||||||
|
|
|
@ -617,6 +617,7 @@ __docker_container_subcommand() {
|
||||||
"($help)*--dns=[Custom DNS servers]:DNS server: "
|
"($help)*--dns=[Custom DNS servers]:DNS server: "
|
||||||
"($help)*--dns-option=[Custom DNS options]:DNS option: "
|
"($help)*--dns-option=[Custom DNS options]:DNS option: "
|
||||||
"($help)*--dns-search=[Custom DNS search domains]:DNS domains: "
|
"($help)*--dns-search=[Custom DNS search domains]:DNS domains: "
|
||||||
|
"($help)*--domainname=[Container NIS domain name]:domainname:_hosts"
|
||||||
"($help)*"{-e=,--env=}"[Environment variables]:environment variable: "
|
"($help)*"{-e=,--env=}"[Environment variables]:environment variable: "
|
||||||
"($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: "
|
"($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: "
|
||||||
"($help)*--env-file=[Read environment variables from a file]:environment file:_files"
|
"($help)*--env-file=[Read environment variables from a file]:environment file:_files"
|
||||||
|
|
|
@ -53,6 +53,7 @@ Options:
|
||||||
--dns value Set custom DNS servers (default [])
|
--dns value Set custom DNS servers (default [])
|
||||||
--dns-option value Set DNS options (default [])
|
--dns-option value Set DNS options (default [])
|
||||||
--dns-search value Set custom DNS search domains (default [])
|
--dns-search value Set custom DNS search domains (default [])
|
||||||
|
--domainname string Container NIS domain name
|
||||||
--entrypoint string Overwrite the default ENTRYPOINT of the image
|
--entrypoint string Overwrite the default ENTRYPOINT of the image
|
||||||
-e, --env value Set environment variables (default [])
|
-e, --env value Set environment variables (default [])
|
||||||
--env-file value Read in a file of environment variables (default [])
|
--env-file value Read in a file of environment variables (default [])
|
||||||
|
|
|
@ -57,6 +57,7 @@ Options:
|
||||||
--dns value Set custom DNS servers (default [])
|
--dns value Set custom DNS servers (default [])
|
||||||
--dns-option value Set DNS options (default [])
|
--dns-option value Set DNS options (default [])
|
||||||
--dns-search value Set custom DNS search domains (default [])
|
--dns-search value Set custom DNS search domains (default [])
|
||||||
|
--domainname string Container NIS domain name
|
||||||
--entrypoint string Overwrite the default ENTRYPOINT of the image
|
--entrypoint string Overwrite the default ENTRYPOINT of the image
|
||||||
-e, --env value Set environment variables (default [])
|
-e, --env value Set environment variables (default [])
|
||||||
--env-file value Read in a file of environment variables (default [])
|
--env-file value Read in a file of environment variables (default [])
|
||||||
|
|
|
@ -256,7 +256,7 @@ The UTS namespace is for setting the hostname and the domain that is visible
|
||||||
to running processes in that namespace. By default, all containers, including
|
to running processes in that namespace. By default, all containers, including
|
||||||
those with `--network=host`, have their own UTS namespace. The `host` setting will
|
those with `--network=host`, have their own UTS namespace. The `host` setting will
|
||||||
result in the container using the same UTS namespace as the host. Note that
|
result in the container using the same UTS namespace as the host. Note that
|
||||||
`--hostname` is invalid in `host` UTS mode.
|
`--hostname` and `--domainname` are invalid in `host` UTS mode.
|
||||||
|
|
||||||
You may wish to share the UTS namespace with the host if you would like the
|
You may wish to share the UTS namespace with the host if you would like the
|
||||||
hostname of the container to change as the hostname of the host changes. A
|
hostname of the container to change as the hostname of the host changes. A
|
||||||
|
@ -396,8 +396,8 @@ network stack and all interfaces from the host will be available to the
|
||||||
container. The container's hostname will match the hostname on the host
|
container. The container's hostname will match the hostname on the host
|
||||||
system. Note that `--mac-address` is invalid in `host` netmode. Even in `host`
|
system. Note that `--mac-address` is invalid in `host` netmode. Even in `host`
|
||||||
network mode a container has its own UTS namespace by default. As such
|
network mode a container has its own UTS namespace by default. As such
|
||||||
`--hostname` is allowed in `host` network mode and will only change the
|
`--hostname` and `--domainname` are allowed in `host` network mode and will
|
||||||
hostname inside the container.
|
only change the hostname and domain name inside the container.
|
||||||
Similar to `--hostname`, the `--add-host`, `--dns`, `--dns-search`, and
|
Similar to `--hostname`, the `--add-host`, `--dns`, `--dns-search`, and
|
||||||
`--dns-option` options can be used in `host` network mode. These options update
|
`--dns-option` options can be used in `host` network mode. These options update
|
||||||
`/etc/hosts` or `/etc/resolv.conf` inside the container. No change are made to
|
`/etc/hosts` or `/etc/resolv.conf` inside the container. No change are made to
|
||||||
|
|
|
@ -35,6 +35,7 @@ docker-run - Run a command in a new container
|
||||||
[**--dns**[=*[]*]]
|
[**--dns**[=*[]*]]
|
||||||
[**--dns-option**[=*[]*]]
|
[**--dns-option**[=*[]*]]
|
||||||
[**--dns-search**[=*[]*]]
|
[**--dns-search**[=*[]*]]
|
||||||
|
[**--domainname**[=*DOMAINNAME*]]
|
||||||
[**-e**|**--env**[=*[]*]]
|
[**-e**|**--env**[=*[]*]]
|
||||||
[**--entrypoint**[=*ENTRYPOINT*]]
|
[**--entrypoint**[=*ENTRYPOINT*]]
|
||||||
[**--env-file**[=*[]*]]
|
[**--env-file**[=*[]*]]
|
||||||
|
@ -285,6 +286,12 @@ configuration passed to the container. Typically this is necessary when the
|
||||||
host DNS configuration is invalid for the container (e.g., 127.0.0.1). When this
|
host DNS configuration is invalid for the container (e.g., 127.0.0.1). When this
|
||||||
is the case the **--dns** flags is necessary for every run.
|
is the case the **--dns** flags is necessary for every run.
|
||||||
|
|
||||||
|
**--domainname**=""
|
||||||
|
Container NIS domain name
|
||||||
|
|
||||||
|
Sets the container's NIS domain name (see also **setdomainname(2)**) that is
|
||||||
|
available inside the container.
|
||||||
|
|
||||||
**-e**, **--env**=[]
|
**-e**, **--env**=[]
|
||||||
Set environment variables
|
Set environment variables
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue