2016-09-08 13:11:39 -04:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
2016-09-08 13:11:39 -04:00
|
|
|
"fmt"
|
2017-05-10 16:38:06 -04:00
|
|
|
"io"
|
docker info: skip API connection if possible
The docker info output contains both "local" and "remote" (daemon-side) information.
The API endpoint to collect daemon information (`/info`) is known to be "heavy",
and (depending on what information is needed) not needed.
This patch checks if the template (`--format`) used requires information from the
daemon, and if not, omits making an API request.
This will improve performance if (for example), the current "context" is requested
from `docker info` or if only plugin information is requested.
Before:
time docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 301.91 millis fish external
usr time 168.64 millis 82.00 micros 168.56 millis
sys time 113.72 millis 811.00 micros 112.91 millis
time docker info --format '{{json .ClientInfo.Plugins}}'
time docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 334.38 millis fish external
usr time 177.23 millis 93.00 micros 177.13 millis
sys time 124.90 millis 927.00 micros 123.97 millis
docker context use remote-ssh-daemon
time docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.22 secs fish external
usr time 116.93 millis 110.00 micros 116.82 millis
sys time 144.36 millis 887.00 micros 143.47 millis
And daemon logs:
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.139529947Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.140772052Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.163832016Z" level=debug msg="Calling GET /v1.41/info"
After:
time ./build/docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 139.84 millis fish external
usr time 76.53 millis 62.00 micros 76.46 millis
sys time 69.25 millis 723.00 micros 68.53 millis
time ./build/docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 136.94 millis fish external
usr time 74.61 millis 74.00 micros 74.54 millis
sys time 65.77 millis 858.00 micros 64.91 millis
docker context use remote-ssh-daemon
time ./build/docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.02 secs fish external
usr time 74.25 millis 76.00 micros 74.17 millis
sys time 65.09 millis 643.00 micros 64.44 millis
And daemon logs:
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.313654687Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.314811624Z" level=debug msg="Calling HEAD /_ping"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-06 08:43:42 -04:00
|
|
|
"regexp"
|
2016-11-03 14:23:58 -04:00
|
|
|
"sort"
|
2016-09-08 13:11:39 -04:00
|
|
|
"strings"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli"
|
2018-12-19 09:49:20 -05:00
|
|
|
pluginmanager "github.com/docker/cli/cli-plugins/manager"
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command"
|
2022-03-30 09:27:25 -04:00
|
|
|
"github.com/docker/cli/cli/command/completion"
|
2023-04-09 07:11:19 -04:00
|
|
|
"github.com/docker/cli/cli/command/formatter"
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/debug"
|
2023-04-09 07:11:19 -04:00
|
|
|
flagsHelper "github.com/docker/cli/cli/flags"
|
2017-08-08 11:26:24 -04:00
|
|
|
"github.com/docker/cli/templates"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2021-08-03 10:46:18 -04:00
|
|
|
"github.com/docker/docker/api/types/versions"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/go-units"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
type infoOptions struct {
|
|
|
|
format string
|
|
|
|
}
|
|
|
|
|
2019-01-23 08:34:43 -05:00
|
|
|
type clientInfo struct {
|
2023-04-10 09:25:31 -04:00
|
|
|
Debug bool
|
|
|
|
clientVersion
|
2018-12-19 09:49:20 -05:00
|
|
|
Plugins []pluginmanager.Plugin
|
2019-01-23 08:34:43 -05:00
|
|
|
Warnings []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type info struct {
|
|
|
|
// This field should/could be ServerInfo but is anonymous to
|
|
|
|
// preserve backwards compatibility in the JSON rendering
|
|
|
|
// which has ServerInfo immediately within the top-level
|
|
|
|
// object.
|
|
|
|
*types.Info `json:",omitempty"`
|
|
|
|
ServerErrors []string `json:",omitempty"`
|
|
|
|
|
|
|
|
ClientInfo *clientInfo `json:",omitempty"`
|
|
|
|
ClientErrors []string `json:",omitempty"`
|
|
|
|
}
|
|
|
|
|
2023-04-10 09:25:31 -04:00
|
|
|
func (i *info) clientPlatform() string {
|
|
|
|
if i.ClientInfo != nil && i.ClientInfo.Platform != nil {
|
|
|
|
return i.ClientInfo.Platform.Name
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
// NewInfoCommand creates a new cobra.Command for `docker info`
|
2017-10-11 12:18:27 -04:00
|
|
|
func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
|
2016-09-08 13:11:39 -04:00
|
|
|
var opts infoOptions
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "info [OPTIONS]",
|
|
|
|
Short: "Display system-wide information",
|
|
|
|
Args: cli.NoArgs,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2018-12-19 09:49:20 -05:00
|
|
|
return runInfo(cmd, dockerCli, &opts)
|
2016-09-08 13:11:39 -04:00
|
|
|
},
|
2022-03-30 03:37:08 -04:00
|
|
|
Annotations: map[string]string{
|
|
|
|
"category-top": "12",
|
cli: use custom annotation for aliases
Cobra allows for aliases to be defined for a command, but only allows these
to be defined at the same level (for example, `docker image ls` as alias for
`docker image list`). Our CLI has some commands that are available both as a
top-level shorthand as well as `docker <object> <verb>` subcommands. For example,
`docker ps` is a shorthand for `docker container ps` / `docker container ls`.
This patch introduces a custom "aliases" annotation that can be used to print
all available aliases for a command. While this requires these aliases to be
defined manually, in practice the list of aliases rarely changes, so maintenance
should be minimal.
As a convention, we could consider the first command in this list to be the
canonical command, so that we can use this information to add redirects in
our documentation in future.
Before this patch:
docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
...
With this patch:
docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Aliases:
docker image ls, docker image list, docker images
Options:
-a, --all Show all images (default hides intermediate images)
...
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-06-28 04:52:25 -04:00
|
|
|
"aliases": "docker system info, docker info",
|
2022-03-30 03:37:08 -04:00
|
|
|
},
|
2022-03-30 09:27:25 -04:00
|
|
|
ValidArgsFunction: completion.NoComplete,
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2023-04-09 07:11:19 -04:00
|
|
|
cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
|
2016-09-08 13:11:39 -04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2018-12-19 09:49:20 -05:00
|
|
|
func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error {
|
2022-05-06 10:15:20 -04:00
|
|
|
info := info{
|
|
|
|
ClientInfo: &clientInfo{
|
2023-04-10 09:25:31 -04:00
|
|
|
// Don't pass a dockerCLI to newClientVersion(), because we currently
|
|
|
|
// don't include negotiated API version, and want to avoid making an
|
|
|
|
// API connection when only printing the Client section.
|
|
|
|
clientVersion: newClientVersion(dockerCli.CurrentContext(), nil),
|
|
|
|
Debug: debug.IsEnabled(),
|
2022-05-06 10:15:20 -04:00
|
|
|
},
|
|
|
|
Info: &types.Info{},
|
2019-01-23 08:34:43 -05:00
|
|
|
}
|
2018-12-19 09:49:20 -05:00
|
|
|
if plugins, err := pluginmanager.ListPlugins(dockerCli, cmd.Root()); err == nil {
|
|
|
|
info.ClientInfo.Plugins = plugins
|
|
|
|
} else {
|
|
|
|
info.ClientErrors = append(info.ClientErrors, err.Error())
|
|
|
|
}
|
2019-01-23 08:34:43 -05:00
|
|
|
|
docker info: skip API connection if possible
The docker info output contains both "local" and "remote" (daemon-side) information.
The API endpoint to collect daemon information (`/info`) is known to be "heavy",
and (depending on what information is needed) not needed.
This patch checks if the template (`--format`) used requires information from the
daemon, and if not, omits making an API request.
This will improve performance if (for example), the current "context" is requested
from `docker info` or if only plugin information is requested.
Before:
time docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 301.91 millis fish external
usr time 168.64 millis 82.00 micros 168.56 millis
sys time 113.72 millis 811.00 micros 112.91 millis
time docker info --format '{{json .ClientInfo.Plugins}}'
time docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 334.38 millis fish external
usr time 177.23 millis 93.00 micros 177.13 millis
sys time 124.90 millis 927.00 micros 123.97 millis
docker context use remote-ssh-daemon
time docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.22 secs fish external
usr time 116.93 millis 110.00 micros 116.82 millis
sys time 144.36 millis 887.00 micros 143.47 millis
And daemon logs:
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.139529947Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.140772052Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.163832016Z" level=debug msg="Calling GET /v1.41/info"
After:
time ./build/docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 139.84 millis fish external
usr time 76.53 millis 62.00 micros 76.46 millis
sys time 69.25 millis 723.00 micros 68.53 millis
time ./build/docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 136.94 millis fish external
usr time 74.61 millis 74.00 micros 74.54 millis
sys time 65.77 millis 858.00 micros 64.91 millis
docker context use remote-ssh-daemon
time ./build/docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.02 secs fish external
usr time 74.25 millis 76.00 micros 74.17 millis
sys time 65.09 millis 643.00 micros 64.44 millis
And daemon logs:
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.313654687Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.314811624Z" level=debug msg="Calling HEAD /_ping"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-06 08:43:42 -04:00
|
|
|
if needsServerInfo(opts.format, info) {
|
|
|
|
ctx := context.Background()
|
|
|
|
if dinfo, err := dockerCli.Client().Info(ctx); err == nil {
|
|
|
|
info.Info = &dinfo
|
|
|
|
} else {
|
|
|
|
info.ServerErrors = append(info.ServerErrors, err.Error())
|
2022-05-10 06:13:03 -04:00
|
|
|
if opts.format == "" {
|
|
|
|
// reset the server info to prevent printing "empty" Server info
|
|
|
|
// and warnings, but don't reset it if a custom format was specified
|
|
|
|
// to prevent errors from Go's template parsing during format.
|
|
|
|
info.Info = nil
|
|
|
|
} else {
|
|
|
|
// if a format is provided, print the error, as it may be hidden
|
|
|
|
// otherwise if the template doesn't include the ServerErrors field.
|
|
|
|
fmt.Fprintln(dockerCli.Err(), err)
|
|
|
|
}
|
docker info: skip API connection if possible
The docker info output contains both "local" and "remote" (daemon-side) information.
The API endpoint to collect daemon information (`/info`) is known to be "heavy",
and (depending on what information is needed) not needed.
This patch checks if the template (`--format`) used requires information from the
daemon, and if not, omits making an API request.
This will improve performance if (for example), the current "context" is requested
from `docker info` or if only plugin information is requested.
Before:
time docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 301.91 millis fish external
usr time 168.64 millis 82.00 micros 168.56 millis
sys time 113.72 millis 811.00 micros 112.91 millis
time docker info --format '{{json .ClientInfo.Plugins}}'
time docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 334.38 millis fish external
usr time 177.23 millis 93.00 micros 177.13 millis
sys time 124.90 millis 927.00 micros 123.97 millis
docker context use remote-ssh-daemon
time docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.22 secs fish external
usr time 116.93 millis 110.00 micros 116.82 millis
sys time 144.36 millis 887.00 micros 143.47 millis
And daemon logs:
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.139529947Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.140772052Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.163832016Z" level=debug msg="Calling GET /v1.41/info"
After:
time ./build/docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 139.84 millis fish external
usr time 76.53 millis 62.00 micros 76.46 millis
sys time 69.25 millis 723.00 micros 68.53 millis
time ./build/docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 136.94 millis fish external
usr time 74.61 millis 74.00 micros 74.54 millis
sys time 65.77 millis 858.00 micros 64.91 millis
docker context use remote-ssh-daemon
time ./build/docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.02 secs fish external
usr time 74.25 millis 76.00 micros 74.17 millis
sys time 65.09 millis 643.00 micros 64.44 millis
And daemon logs:
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.313654687Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.314811624Z" level=debug msg="Calling HEAD /_ping"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-06 08:43:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
if opts.format == "" {
|
|
|
|
return prettyPrintInfo(dockerCli, info)
|
|
|
|
}
|
|
|
|
return formatInfo(dockerCli, info, opts.format)
|
|
|
|
}
|
|
|
|
|
docker info: skip API connection if possible
The docker info output contains both "local" and "remote" (daemon-side) information.
The API endpoint to collect daemon information (`/info`) is known to be "heavy",
and (depending on what information is needed) not needed.
This patch checks if the template (`--format`) used requires information from the
daemon, and if not, omits making an API request.
This will improve performance if (for example), the current "context" is requested
from `docker info` or if only plugin information is requested.
Before:
time docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 301.91 millis fish external
usr time 168.64 millis 82.00 micros 168.56 millis
sys time 113.72 millis 811.00 micros 112.91 millis
time docker info --format '{{json .ClientInfo.Plugins}}'
time docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 334.38 millis fish external
usr time 177.23 millis 93.00 micros 177.13 millis
sys time 124.90 millis 927.00 micros 123.97 millis
docker context use remote-ssh-daemon
time docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.22 secs fish external
usr time 116.93 millis 110.00 micros 116.82 millis
sys time 144.36 millis 887.00 micros 143.47 millis
And daemon logs:
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.139529947Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.140772052Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.163832016Z" level=debug msg="Calling GET /v1.41/info"
After:
time ./build/docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 139.84 millis fish external
usr time 76.53 millis 62.00 micros 76.46 millis
sys time 69.25 millis 723.00 micros 68.53 millis
time ./build/docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 136.94 millis fish external
usr time 74.61 millis 74.00 micros 74.54 millis
sys time 65.77 millis 858.00 micros 64.91 millis
docker context use remote-ssh-daemon
time ./build/docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.02 secs fish external
usr time 74.25 millis 76.00 micros 74.17 millis
sys time 65.09 millis 643.00 micros 64.44 millis
And daemon logs:
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.313654687Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.314811624Z" level=debug msg="Calling HEAD /_ping"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-06 08:43:42 -04:00
|
|
|
// placeHolders does a rudimentary match for possible placeholders in a
|
|
|
|
// template, matching a '.', followed by an letter (a-z/A-Z).
|
|
|
|
var placeHolders = regexp.MustCompile(`\.[a-zA-Z]`)
|
|
|
|
|
|
|
|
// needsServerInfo detects if the given template uses any server information.
|
|
|
|
// If only client-side information is used in the template, we can skip
|
|
|
|
// connecting to the daemon. This allows (e.g.) to only get cli-plugin
|
|
|
|
// information, without also making a (potentially expensive) API call.
|
|
|
|
func needsServerInfo(template string, info info) bool {
|
|
|
|
if len(template) == 0 || placeHolders.FindString(template) == "" {
|
|
|
|
// The template is empty, or does not contain formatting fields
|
|
|
|
// (e.g. `table` or `raw` or `{{ json .}}`). Assume we need server-side
|
|
|
|
// information to render it.
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// A template is provided and has at least one field set.
|
|
|
|
tmpl, err := templates.NewParse("", template)
|
|
|
|
if err != nil {
|
|
|
|
// ignore parsing errors here, and let regular code handle them
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
type sparseInfo struct {
|
|
|
|
ClientInfo *clientInfo `json:",omitempty"`
|
|
|
|
ClientErrors []string `json:",omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// This constructs an "info" object that only has the client-side fields.
|
2022-02-25 08:32:43 -05:00
|
|
|
err = tmpl.Execute(io.Discard, sparseInfo{
|
docker info: skip API connection if possible
The docker info output contains both "local" and "remote" (daemon-side) information.
The API endpoint to collect daemon information (`/info`) is known to be "heavy",
and (depending on what information is needed) not needed.
This patch checks if the template (`--format`) used requires information from the
daemon, and if not, omits making an API request.
This will improve performance if (for example), the current "context" is requested
from `docker info` or if only plugin information is requested.
Before:
time docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 301.91 millis fish external
usr time 168.64 millis 82.00 micros 168.56 millis
sys time 113.72 millis 811.00 micros 112.91 millis
time docker info --format '{{json .ClientInfo.Plugins}}'
time docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 334.38 millis fish external
usr time 177.23 millis 93.00 micros 177.13 millis
sys time 124.90 millis 927.00 micros 123.97 millis
docker context use remote-ssh-daemon
time docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.22 secs fish external
usr time 116.93 millis 110.00 micros 116.82 millis
sys time 144.36 millis 887.00 micros 143.47 millis
And daemon logs:
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.139529947Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.140772052Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:12 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:12.163832016Z" level=debug msg="Calling GET /v1.41/info"
After:
time ./build/docker info --format '{{range .ClientInfo.Plugins}}Plugin: {{.Name}}, {{end}}'
Plugin: buildx, Plugin: compose, Plugin: scan,
________________________________________________________
Executed in 139.84 millis fish external
usr time 76.53 millis 62.00 micros 76.46 millis
sys time 69.25 millis 723.00 micros 68.53 millis
time ./build/docker info --format '{{.ClientInfo.Context}}'
default
________________________________________________________
Executed in 136.94 millis fish external
usr time 74.61 millis 74.00 micros 74.54 millis
sys time 65.77 millis 858.00 micros 64.91 millis
docker context use remote-ssh-daemon
time ./build/docker info --format '{{.ClientInfo.Context}}'
remote-ssh-daemon
________________________________________________________
Executed in 1.02 secs fish external
usr time 74.25 millis 76.00 micros 74.17 millis
sys time 65.09 millis 643.00 micros 64.44 millis
And daemon logs:
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.313654687Z" level=debug msg="Calling HEAD /_ping"
Jul 06 12:42:55 remote-ssh-daemon dockerd[14377]: time="2021-07-06T12:42:55.314811624Z" level=debug msg="Calling HEAD /_ping"
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-06 08:43:42 -04:00
|
|
|
ClientInfo: info.ClientInfo,
|
|
|
|
ClientErrors: info.ClientErrors,
|
|
|
|
})
|
|
|
|
// If executing the template failed, it means the template needs
|
|
|
|
// server-side information as well. If it succeeded without server-side
|
|
|
|
// information, we don't need to make API calls to collect that information.
|
|
|
|
return err != nil
|
|
|
|
}
|
|
|
|
|
2019-01-23 08:34:43 -05:00
|
|
|
func prettyPrintInfo(dockerCli command.Cli, info info) error {
|
2023-04-10 09:25:31 -04:00
|
|
|
// Only append the platform info if it's not empty, to prevent printing a trailing space.
|
|
|
|
if p := info.clientPlatform(); p != "" {
|
|
|
|
_, _ = fmt.Fprintln(dockerCli.Out(), "Client:", p)
|
|
|
|
} else {
|
|
|
|
_, _ = fmt.Fprintln(dockerCli.Out(), "Client:")
|
|
|
|
}
|
2019-01-23 08:34:43 -05:00
|
|
|
if info.ClientInfo != nil {
|
2019-04-02 07:38:48 -04:00
|
|
|
prettyPrintClientInfo(dockerCli, *info.ClientInfo)
|
2019-01-23 08:34:43 -05:00
|
|
|
}
|
|
|
|
for _, err := range info.ClientErrors {
|
2021-04-08 19:46:13 -04:00
|
|
|
fmt.Fprintln(dockerCli.Err(), "ERROR:", err)
|
2019-01-23 08:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(dockerCli.Out())
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), "Server:")
|
2019-01-23 08:34:43 -05:00
|
|
|
if info.Info != nil {
|
2019-01-24 09:22:55 -05:00
|
|
|
for _, err := range prettyPrintServerInfo(dockerCli, *info.Info) {
|
2019-01-23 08:34:43 -05:00
|
|
|
info.ServerErrors = append(info.ServerErrors, err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, err := range info.ServerErrors {
|
2021-04-08 19:46:13 -04:00
|
|
|
fmt.Fprintln(dockerCli.Err(), "ERROR:", err)
|
2019-01-23 08:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 {
|
|
|
|
return fmt.Errorf("errors pretty printing info")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-02 07:38:48 -04:00
|
|
|
func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) {
|
2023-04-10 09:25:31 -04:00
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Version: ", info.Version)
|
2020-05-07 07:28:37 -04:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Context: ", info.Context)
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Debug Mode:", info.Debug)
|
2019-01-23 08:34:43 -05:00
|
|
|
|
2018-12-19 09:49:20 -05:00
|
|
|
if len(info.Plugins) > 0 {
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Plugins:")
|
|
|
|
for _, p := range info.Plugins {
|
|
|
|
if p.Err == nil {
|
2022-06-01 06:44:41 -04:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s: %s (%s)\n", p.Name, p.ShortDescription, p.Vendor)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Version: ", p.Version)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Path: ", p.Path)
|
2018-12-19 09:49:20 -05:00
|
|
|
} else {
|
|
|
|
info.Warnings = append(info.Warnings, fmt.Sprintf("WARNING: Plugin %q is not valid: %s", p.Path, p.Err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 08:34:43 -05:00
|
|
|
if len(info.Warnings) > 0 {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 06:29:49 -04:00
|
|
|
//nolint:gocyclo
|
2019-01-24 09:22:55 -05:00
|
|
|
func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
|
|
|
|
var errs []error
|
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Containers:", info.Containers)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Running:", info.ContainersRunning)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Paused:", info.ContainersPaused)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Stopped:", info.ContainersStopped)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Images:", info.Images)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Server Version:", info.ServerVersion)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Storage Driver:", info.Driver)
|
2016-09-08 13:11:39 -04:00
|
|
|
if info.DriverStatus != nil {
|
|
|
|
for _, pair := range info.DriverStatus {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s: %s\n", pair[0], pair[1])
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if info.SystemStatus != nil {
|
|
|
|
for _, pair := range info.SystemStatus {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s: %s\n", pair[0], pair[1])
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Logging Driver:", info.LoggingDriver)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Cgroup Driver:", info.CgroupDriver)
|
2020-04-29 17:29:36 -04:00
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Cgroup Version:", info.CgroupVersion)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Plugins:")
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Volume:", strings.Join(info.Plugins.Volume, " "))
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Network:", strings.Join(info.Plugins.Network, " "))
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
if len(info.Plugins.Authorization) != 0 {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Authorization:", strings.Join(info.Plugins.Authorization, " "))
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Log:", strings.Join(info.Plugins.Log, " "))
|
2017-04-11 17:21:21 -04:00
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Swarm:", info.Swarm.LocalNodeState)
|
2017-08-06 17:23:15 -04:00
|
|
|
printSwarmInfo(dockerCli, info)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
if len(info.Runtimes) > 0 {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprint(dockerCli.Out(), " Runtimes:")
|
2016-09-08 13:11:39 -04:00
|
|
|
for name := range info.Runtimes {
|
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s", name)
|
|
|
|
}
|
|
|
|
fmt.Fprint(dockerCli.Out(), "\n")
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Default Runtime:", info.DefaultRuntime)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2016-09-07 14:14:49 -04:00
|
|
|
if info.OSType == "linux" {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Init Binary:", info.InitBinary)
|
2016-10-24 18:18:58 -04:00
|
|
|
|
|
|
|
for _, ci := range []struct {
|
|
|
|
Name string
|
|
|
|
Commit types.Commit
|
|
|
|
}{
|
|
|
|
{"containerd", info.ContainerdCommit},
|
|
|
|
{"runc", info.RuncCommit},
|
|
|
|
{"init", info.InitCommit},
|
|
|
|
} {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s version: %s", ci.Name, ci.Commit.ID)
|
2016-10-24 18:18:58 -04:00
|
|
|
if ci.Commit.ID != ci.Commit.Expected {
|
|
|
|
fmt.Fprintf(dockerCli.Out(), " (expected: %s)", ci.Commit.Expected)
|
|
|
|
}
|
2017-08-06 17:23:15 -04:00
|
|
|
fmt.Fprint(dockerCli.Out(), "\n")
|
2016-10-24 18:18:58 -04:00
|
|
|
}
|
2016-09-02 09:20:54 -04:00
|
|
|
if len(info.SecurityOptions) != 0 {
|
2019-01-24 09:22:55 -05:00
|
|
|
if kvs, err := types.DecodeSecurityOptions(info.SecurityOptions); err != nil {
|
|
|
|
errs = append(errs, err)
|
|
|
|
} else {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Security Options:")
|
2019-01-24 09:22:55 -05:00
|
|
|
for _, so := range kvs {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " "+so.Name)
|
2019-01-24 09:22:55 -05:00
|
|
|
for _, o := range so.Options {
|
|
|
|
switch o.Key {
|
|
|
|
case "profile":
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Profile:", o.Value)
|
2016-11-16 16:30:29 -05:00
|
|
|
}
|
2016-09-02 09:20:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 14:14:49 -04:00
|
|
|
}
|
2016-09-08 13:11:39 -04:00
|
|
|
|
2016-09-07 18:10:00 -04:00
|
|
|
// Isolation only has meaning on a Windows daemon.
|
|
|
|
if info.OSType == "windows" {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Default Isolation:", info.Isolation)
|
2016-09-07 18:10:00 -04:00
|
|
|
}
|
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Kernel Version:", info.KernelVersion)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Operating System:", info.OperatingSystem)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " OSType:", info.OSType)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Architecture:", info.Architecture)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " CPUs:", info.NCPU)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Total Memory:", units.BytesSize(float64(info.MemTotal)))
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " Name:", info.Name)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " ID:", info.ID)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Docker Root Dir:", info.DockerRootDir)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Debug Mode:", info.Debug)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
if info.Debug {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " File Descriptors:", info.NFd)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Goroutines:", info.NGoroutines)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " System Time:", info.SystemTime)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " EventsListeners:", info.NEventsListener)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " HTTP Proxy:", info.HTTPProxy)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " HTTPS Proxy:", info.HTTPSProxy)
|
|
|
|
fprintlnNonEmpty(dockerCli.Out(), " No Proxy:", info.NoProxy)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
if info.IndexServerAddress != "" {
|
|
|
|
u := dockerCli.ConfigFile().AuthConfigs[info.IndexServerAddress].Username
|
|
|
|
if len(u) > 0 {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Username:", u)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-05 08:44:08 -04:00
|
|
|
if len(info.Labels) > 0 {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Labels:")
|
2017-08-06 17:23:15 -04:00
|
|
|
for _, lbl := range info.Labels {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " "+lbl)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Experimental:", info.ExperimentalBuild)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
if info.RegistryConfig != nil && (len(info.RegistryConfig.InsecureRegistryCIDRs) > 0 || len(info.RegistryConfig.IndexConfigs) > 0) {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Insecure Registries:")
|
2016-09-08 13:11:39 -04:00
|
|
|
for _, registry := range info.RegistryConfig.IndexConfigs {
|
2017-06-09 17:42:16 -04:00
|
|
|
if !registry.Secure {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " "+registry.Name)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, registry := range info.RegistryConfig.InsecureRegistryCIDRs {
|
|
|
|
mask, _ := registry.Mask.Size()
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s/%d\n", registry.IP.String(), mask)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if info.RegistryConfig != nil && len(info.RegistryConfig.Mirrors) > 0 {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Registry Mirrors:")
|
2016-09-08 13:11:39 -04:00
|
|
|
for _, mirror := range info.RegistryConfig.Mirrors {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " "+mirror)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Live Restore Enabled:", info.LiveRestoreEnabled)
|
2018-08-27 18:33:16 -04:00
|
|
|
if info.ProductLicense != "" {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Product License:", info.ProductLicense)
|
2018-08-27 18:33:16 -04:00
|
|
|
}
|
2020-03-18 11:58:23 -04:00
|
|
|
|
|
|
|
if info.DefaultAddressPools != nil && len(info.DefaultAddressPools) > 0 {
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Default Address Pools:")
|
|
|
|
for _, pool := range info.DefaultAddressPools {
|
|
|
|
fmt.Fprintf(dockerCli.Out(), " Base: %s, Size: %d\n", pool.Base, pool.Size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-06 17:23:15 -04:00
|
|
|
fmt.Fprint(dockerCli.Out(), "\n")
|
add d_type warning to docker info, and optimize output
The overlay(2) drivers were moved up in the list of storage drivers,
and are known to have problems if the backing filesystem does not
support d_type.
Commit 2e20e63da2a8a0ffbbb3f2146f87559e17f43046 added a warning,
which is logged in the daemon logs, however, many users do not
check those logs, and may overlook this warning.
This patch adds the same warning to the output of `docker info`
so that the warning is more easily found.
In addition, the output of warnings printed by `docker info` is
optimized, by;
- moving all warnings to the _end_ of the output, instead of
mixing them with the regular output
- wrapping the storage-driver warnings, so that they are more
easily readable
Example output with this patch applied
============================================
devicemapper using loopback devices:
...
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
overlay2 on xfs without d_type support;
...
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: overlay2: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior.
Reformat the filesystem with ftype=1 to enable d_type support.
Running without d_type support will not be supported in future releases.
WARNING: bridge-nf-call-iptables is disabled
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-02-23 07:36:57 -05:00
|
|
|
|
2019-01-23 08:34:43 -05:00
|
|
|
printServerWarnings(dockerCli, info)
|
2019-01-24 09:22:55 -05:00
|
|
|
return errs
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-13 06:29:49 -04:00
|
|
|
//nolint:gocyclo
|
2017-08-06 17:23:15 -04:00
|
|
|
func printSwarmInfo(dockerCli command.Cli, info types.Info) {
|
|
|
|
if info.Swarm.LocalNodeState == swarm.LocalNodeStateInactive || info.Swarm.LocalNodeState == swarm.LocalNodeStateLocked {
|
|
|
|
return
|
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " NodeID:", info.Swarm.NodeID)
|
2017-08-06 17:23:15 -04:00
|
|
|
if info.Swarm.Error != "" {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Error:", info.Swarm.Error)
|
2017-08-06 17:23:15 -04:00
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Is Manager:", info.Swarm.ControlAvailable)
|
2017-08-06 17:23:15 -04:00
|
|
|
if info.Swarm.Cluster != nil && info.Swarm.ControlAvailable && info.Swarm.Error == "" && info.Swarm.LocalNodeState != swarm.LocalNodeStateError {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " ClusterID:", info.Swarm.Cluster.ID)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Managers:", info.Swarm.Managers)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Nodes:", info.Swarm.Nodes)
|
2018-07-28 22:44:11 -04:00
|
|
|
var strAddrPool strings.Builder
|
|
|
|
if info.Swarm.Cluster.DefaultAddrPool != nil {
|
|
|
|
for _, p := range info.Swarm.Cluster.DefaultAddrPool {
|
|
|
|
strAddrPool.WriteString(p + " ")
|
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Default Address Pool:", strAddrPool.String())
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " SubnetSize:", info.Swarm.Cluster.SubnetSize)
|
2018-07-28 22:44:11 -04:00
|
|
|
}
|
2018-11-26 16:04:39 -05:00
|
|
|
if info.Swarm.Cluster.DataPathPort > 0 {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Data Path Port:", info.Swarm.Cluster.DataPathPort)
|
2018-11-26 16:04:39 -05:00
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Orchestration:")
|
2018-07-28 22:44:11 -04:00
|
|
|
|
2017-08-06 17:23:15 -04:00
|
|
|
taskHistoryRetentionLimit := int64(0)
|
|
|
|
if info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit != nil {
|
|
|
|
taskHistoryRetentionLimit = *info.Swarm.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit
|
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Task History Retention Limit:", taskHistoryRetentionLimit)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Raft:")
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Snapshot Interval:", info.Swarm.Cluster.Spec.Raft.SnapshotInterval)
|
2017-08-06 17:23:15 -04:00
|
|
|
if info.Swarm.Cluster.Spec.Raft.KeepOldSnapshots != nil {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " Number of Old Snapshots to Retain: %d\n", *info.Swarm.Cluster.Spec.Raft.KeepOldSnapshots)
|
2017-08-06 17:23:15 -04:00
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Heartbeat Tick:", info.Swarm.Cluster.Spec.Raft.HeartbeatTick)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Election Tick:", info.Swarm.Cluster.Spec.Raft.ElectionTick)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Dispatcher:")
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Heartbeat Period:", units.HumanDuration(info.Swarm.Cluster.Spec.Dispatcher.HeartbeatPeriod))
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " CA Configuration:")
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Expiry Duration:", units.HumanDuration(info.Swarm.Cluster.Spec.CAConfig.NodeCertExpiry))
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Force Rotate:", info.Swarm.Cluster.Spec.CAConfig.ForceRotate)
|
2017-08-06 17:23:15 -04:00
|
|
|
if caCert := strings.TrimSpace(info.Swarm.Cluster.Spec.CAConfig.SigningCACert); caCert != "" {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " Signing CA Certificate: \n%s\n\n", caCert)
|
2017-08-06 17:23:15 -04:00
|
|
|
}
|
|
|
|
if len(info.Swarm.Cluster.Spec.CAConfig.ExternalCAs) > 0 {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " External CAs:")
|
2017-08-06 17:23:15 -04:00
|
|
|
for _, entry := range info.Swarm.Cluster.Spec.CAConfig.ExternalCAs {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s: %s\n", entry.Protocol, entry.URL)
|
2017-08-06 17:23:15 -04:00
|
|
|
}
|
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Autolock Managers:", info.Swarm.Cluster.Spec.EncryptionConfig.AutoLockManagers)
|
|
|
|
fmt.Fprintln(dockerCli.Out(), " Root Rotation In Progress:", info.Swarm.Cluster.RootRotationInProgress)
|
2017-08-06 17:23:15 -04:00
|
|
|
}
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Node Address:", info.Swarm.NodeAddr)
|
2017-08-06 17:23:15 -04:00
|
|
|
if len(info.Swarm.RemoteManagers) > 0 {
|
|
|
|
managers := []string{}
|
|
|
|
for _, entry := range info.Swarm.RemoteManagers {
|
|
|
|
managers = append(managers, entry.Addr)
|
|
|
|
}
|
|
|
|
sort.Strings(managers)
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintln(dockerCli.Out(), " Manager Addresses:")
|
2017-08-06 17:23:15 -04:00
|
|
|
for _, entry := range managers {
|
2019-01-25 08:10:59 -05:00
|
|
|
fmt.Fprintf(dockerCli.Out(), " %s\n", entry)
|
2017-08-06 17:23:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 08:34:43 -05:00
|
|
|
func printServerWarnings(dockerCli command.Cli, info types.Info) {
|
2021-08-03 10:46:18 -04:00
|
|
|
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.42") {
|
|
|
|
printSecurityOptionsWarnings(dockerCli, info)
|
|
|
|
}
|
2018-07-19 13:45:04 -04:00
|
|
|
if len(info.Warnings) > 0 {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// daemon didn't return warnings. Fallback to old behavior
|
2019-01-23 08:34:43 -05:00
|
|
|
printServerWarningsLegacy(dockerCli, info)
|
2018-07-19 13:45:04 -04:00
|
|
|
}
|
|
|
|
|
2021-08-03 10:46:18 -04:00
|
|
|
// printSecurityOptionsWarnings prints warnings based on the security options
|
|
|
|
// returned by the daemon.
|
|
|
|
// DEPRECATED: warnings are now generated by the daemon, and returned in
|
|
|
|
// info.Warnings. This function is used to provide backward compatibility with
|
|
|
|
// daemons that do not provide these warnings. No new warnings should be added
|
|
|
|
// here.
|
|
|
|
func printSecurityOptionsWarnings(dockerCli command.Cli, info types.Info) {
|
|
|
|
if info.OSType == "windows" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
kvs, _ := types.DecodeSecurityOptions(info.SecurityOptions)
|
|
|
|
for _, so := range kvs {
|
|
|
|
if so.Name != "seccomp" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for _, o := range so.Options {
|
|
|
|
if o.Key == "profile" && o.Value != "default" && o.Value != "builtin" {
|
|
|
|
_, _ = fmt.Fprintln(dockerCli.Err(), "WARNING: You're not using the default seccomp profile")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 08:34:43 -05:00
|
|
|
// printServerWarningsLegacy generates warnings based on information returned by the daemon.
|
2018-07-19 13:45:04 -04:00
|
|
|
// DEPRECATED: warnings are now generated by the daemon, and returned in
|
|
|
|
// info.Warnings. This function is used to provide backward compatibility with
|
|
|
|
// daemons that do not provide these warnings. No new warnings should be added
|
|
|
|
// here.
|
2019-01-23 08:34:43 -05:00
|
|
|
func printServerWarningsLegacy(dockerCli command.Cli, info types.Info) {
|
2018-07-19 13:45:04 -04:00
|
|
|
if info.OSType == "windows" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !info.MemoryLimit {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: No memory limit support")
|
|
|
|
}
|
|
|
|
if !info.SwapLimit {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: No swap limit support")
|
|
|
|
}
|
2021-05-04 05:43:18 -04:00
|
|
|
if !info.OomKillDisable && info.CgroupVersion != "2" {
|
2018-07-19 13:45:04 -04:00
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: No oom kill disable support")
|
|
|
|
}
|
|
|
|
if !info.CPUCfsQuota {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs quota support")
|
|
|
|
}
|
|
|
|
if !info.CPUCfsPeriod {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs period support")
|
|
|
|
}
|
|
|
|
if !info.CPUShares {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu shares support")
|
|
|
|
}
|
|
|
|
if !info.CPUSet {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpuset support")
|
|
|
|
}
|
|
|
|
if !info.IPv4Forwarding {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: IPv4 forwarding is disabled")
|
|
|
|
}
|
|
|
|
if !info.BridgeNfIptables {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-iptables is disabled")
|
|
|
|
}
|
|
|
|
if !info.BridgeNfIP6tables {
|
|
|
|
fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-ip6tables is disabled")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 08:34:43 -05:00
|
|
|
func formatInfo(dockerCli command.Cli, info info, format string) error {
|
2023-04-09 07:11:19 -04:00
|
|
|
if format == formatter.JSONFormatKey {
|
|
|
|
format = formatter.JSONFormat
|
|
|
|
}
|
|
|
|
|
2018-12-19 09:49:20 -05:00
|
|
|
// Ensure slice/array fields render as `[]` not `null`
|
|
|
|
if info.ClientInfo != nil && info.ClientInfo.Plugins == nil {
|
|
|
|
info.ClientInfo.Plugins = make([]pluginmanager.Plugin, 0)
|
|
|
|
}
|
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
tmpl, err := templates.Parse(format)
|
|
|
|
if err != nil {
|
2022-09-29 11:21:51 -04:00
|
|
|
return cli.StatusError{
|
|
|
|
StatusCode: 64,
|
|
|
|
Status: "template parsing error: " + err.Error(),
|
|
|
|
}
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
err = tmpl.Execute(dockerCli.Out(), info)
|
|
|
|
dockerCli.Out().Write([]byte{'\n'})
|
|
|
|
return err
|
|
|
|
}
|
2017-05-10 16:38:06 -04:00
|
|
|
|
2017-08-06 17:23:15 -04:00
|
|
|
func fprintlnNonEmpty(w io.Writer, label, value string) {
|
2017-05-10 16:38:06 -04:00
|
|
|
if value != "" {
|
2017-08-06 17:23:15 -04:00
|
|
|
fmt.Fprintln(w, label, value)
|
2017-05-10 16:38:06 -04:00
|
|
|
}
|
|
|
|
}
|