Skip to content

Commit

Permalink
add daemon labels
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Vieux <[email protected]>
  • Loading branch information
vieux committed Nov 20, 2014
1 parent 998b591 commit 2fe36ba
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
7 changes: 7 additions & 0 deletions api/client/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
if remoteInfo.Exists("IPv4Forwarding") && !remoteInfo.GetBool("IPv4Forwarding") {
fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled.\n")
}
if remoteInfo.Exists("Labels") {
fmt.Fprintln(cli.out, "Labels:")
for _, attribute := range remoteInfo.GetList("Labels") {
fmt.Fprintf(cli.out, " %s\n", attribute)
}
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Config struct {
EnableSelinuxSupport bool
Context map[string][]string
TrustKeyPath string
Labels []string
}

// InstallFlags adds command-line options to the top-level flag parser for
Expand Down Expand Up @@ -69,6 +70,7 @@ func (config *Config) InstallFlags() {
opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "Force Docker to use specific DNS servers")
opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
opts.MirrorListVar(&config.Mirrors, []string{"-registry-mirror"}, "Specify a preferred Docker registry mirror")
opts.LabelListVar(&config.Labels, []string{"-label"}, "Set key=values labels to the daemon (displayed in `docker info`)")

// Localhost is by default considered as an insecure registry
// This is a stop-gap for people who are running a private registry on localhost (especially on Boot2docker).
Expand Down
1 change: 1 addition & 0 deletions daemon/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status {
if hostname, err := os.Hostname(); err == nil {
v.Set("Name", hostname)
}
v.SetList("Labels", daemon.Config().Labels)
if _, err := v.WriteTo(job.Stdout); err != nil {
return job.Error(err)
}
Expand Down
3 changes: 3 additions & 0 deletions docs/man/docker.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ unix://[/path/to/socket] to use.
**-l**, **--log-level**="*debug*|*info*|*error*|*fatal*""
Set the logging level. Default is `info`.

**--label**="[]"
Set key=values labels to the daemon (displayed in `docker info`)

**--mtu**=VALUE
Set the containers network mtu. Default is `1500`.

Expand Down
3 changes: 2 additions & 1 deletion docs/sources/reference/api/docker_remote_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ You can still call an old version of the API using

**New!**
`info` now returns the number of CPUs available on the machine (`NCPU`),
total memory available (`MemTotal`), a user-friendly name describing the running Docker daemon (`Name`), and a unique ID identifying the daemon (`ID`).
total memory available (`MemTotal`), a user-friendly name describing the running Docker daemon (`Name`), a unique ID identifying the daemon (`ID`), and
a list of daemon labels (`Labels`).

`POST /containers/create`

Expand Down
3 changes: 2 additions & 1 deletion docs/sources/reference/api/docker_remote_api_v1.16.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,8 @@ Display system-wide information
"IndexServerAddress":["https://index.docker.io/v1/"],
"MemoryLimit":true,
"SwapLimit":false,
"IPv4Forwarding":true
"IPv4Forwarding":true,
"Labels":["storage=ssd"]
}

Status Codes:
Expand Down
8 changes: 6 additions & 2 deletions docs/sources/reference/commandline/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ expect an integer, and they can only be specified once.
--ip-masq=true Enable IP masquerading for bridge's IP range
--iptables=true Enable Docker's addition of iptables rules
-l, --log-level="info" Set the logging level

--label=[] Set key=values labels to the daemon (displayed in `docker info`)
--mtu=0 Set the containers network MTU
if no value is provided: default to the default route MTU or 1500 if no default route is available
-p, --pidfile="/var/run/docker.pid" Path to use for daemon PID file
Expand Down Expand Up @@ -851,7 +851,9 @@ For example:
$ sudo docker -D info
Containers: 14
Images: 52
Storage Driver: btrfs
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Dirs: 545
Execution Driver: native-0.2
Kernel Version: 3.13.0-24-generic
Operating System: Ubuntu 14.04 LTS
Expand All @@ -867,6 +869,8 @@ For example:
Init Path: /usr/bin/docker
Username: svendowideit
Registry: [https://index.docker.io/v1/]
Labels:
storage=ssd

The global `-D` option tells all `docker` commands to output debug information.

Expand Down
11 changes: 11 additions & 0 deletions opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func MirrorListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateMirror), names, usage)
}

func LabelListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateLabel), names, usage)
}

// ListOpts type
type ListOpts struct {
values *[]string
Expand Down Expand Up @@ -227,3 +231,10 @@ func ValidateMirror(val string) (string, error) {

return fmt.Sprintf("%s://%s/v1/", uri.Scheme, uri.Host), nil
}

func ValidateLabel(val string) (string, error) {
if strings.Count(val, "=") != 1 {
return "", fmt.Errorf("bad attribute format: %s", val)
}
return val, nil
}

0 comments on commit 2fe36ba

Please sign in to comment.