1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
|
//go:build !windows
package daemon // import "github.com/docker/docker/daemon"
import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
v2runcoptions "github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/containerd/log"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/rootless"
"github.com/docker/docker/pkg/sysinfo"
"github.com/pkg/errors"
rkclient "github.com/rootless-containers/rootlesskit/v2/pkg/api/client"
)
// fillPlatformInfo fills the platform related info.
func (daemon *Daemon) fillPlatformInfo(ctx context.Context, v *system.Info, sysInfo *sysinfo.SysInfo, cfg *configStore) error {
v.CgroupDriver = cgroupDriver(&cfg.Config)
v.CgroupVersion = "1"
if sysInfo.CgroupUnified {
v.CgroupVersion = "2"
}
if v.CgroupDriver != cgroupNoneDriver {
v.MemoryLimit = sysInfo.MemoryLimit
v.SwapLimit = sysInfo.SwapLimit
v.KernelMemory = sysInfo.KernelMemory
v.KernelMemoryTCP = sysInfo.KernelMemoryTCP
v.OomKillDisable = sysInfo.OomKillDisable
v.CPUCfsPeriod = sysInfo.CPUCfs
v.CPUCfsQuota = sysInfo.CPUCfs
v.CPUShares = sysInfo.CPUShares
v.CPUSet = sysInfo.Cpuset
v.PidsLimit = sysInfo.PidsLimit
}
v.Runtimes = make(map[string]system.RuntimeWithStatus)
for n, p := range stockRuntimes() {
v.Runtimes[n] = system.RuntimeWithStatus{
Runtime: system.Runtime{
Path: p,
},
Status: daemon.runtimeStatus(ctx, cfg, n),
}
}
for n, r := range cfg.Config.Runtimes {
v.Runtimes[n] = system.RuntimeWithStatus{
Runtime: system.Runtime{
Path: r.Path,
Args: append([]string(nil), r.Args...),
},
Status: daemon.runtimeStatus(ctx, cfg, n),
}
}
v.DefaultRuntime = cfg.Runtimes.Default
v.RuncCommit.ID = "N/A"
v.ContainerdCommit.ID = "N/A"
v.InitCommit.ID = "N/A"
if err := populateRuncCommit(&v.RuncCommit, cfg); err != nil {
log.G(ctx).WithError(err).Warn("Failed to retrieve default runtime version")
}
if err := daemon.populateContainerdCommit(ctx, &v.ContainerdCommit); err != nil {
return err
}
if err := daemon.populateInitCommit(ctx, v, cfg); err != nil {
return err
}
// Set expected and actual commits to the same value to prevent the client
// showing that the version does not match the "expected" version/commit.
if v.CgroupDriver == cgroupNoneDriver {
if v.CgroupVersion == "2" {
v.Warnings = append(v.Warnings, "WARNING: Running in rootless-mode without cgroups. Systemd is required to enable cgroups in rootless-mode.")
} else {
v.Warnings = append(v.Warnings, "WARNING: Running in rootless-mode without cgroups. To enable cgroups in rootless-mode, you need to boot the system in cgroup v2 mode.")
}
} else {
if !v.MemoryLimit {
v.Warnings = append(v.Warnings, "WARNING: No memory limit support")
}
if !v.SwapLimit {
v.Warnings = append(v.Warnings, "WARNING: No swap limit support")
}
if !v.KernelMemoryTCP && v.CgroupVersion == "1" {
// kernel memory is not available for cgroup v2.
// Warning is not printed on cgroup v2, because there is no action user can take.
v.Warnings = append(v.Warnings, "WARNING: No kernel memory TCP limit support")
}
if !v.OomKillDisable && v.CgroupVersion == "1" {
// oom kill disable is not available for cgroup v2.
// Warning is not printed on cgroup v2, because there is no action user can take.
v.Warnings = append(v.Warnings, "WARNING: No oom kill disable support")
}
if !v.CPUCfsQuota {
v.Warnings = append(v.Warnings, "WARNING: No cpu cfs quota support")
}
if !v.CPUCfsPeriod {
v.Warnings = append(v.Warnings, "WARNING: No cpu cfs period support")
}
if !v.CPUShares {
v.Warnings = append(v.Warnings, "WARNING: No cpu shares support")
}
if !v.CPUSet {
v.Warnings = append(v.Warnings, "WARNING: No cpuset support")
}
// TODO add fields for these options in types.Info
if !sysInfo.BlkioWeight && v.CgroupVersion == "2" {
// blkio weight is not available on cgroup v1 since kernel 5.0.
// Warning is not printed on cgroup v1, because there is no action user can take.
// On cgroup v2, blkio weight is implemented using io.weight
v.Warnings = append(v.Warnings, "WARNING: No io.weight support")
}
if !sysInfo.BlkioWeightDevice && v.CgroupVersion == "2" {
v.Warnings = append(v.Warnings, "WARNING: No io.weight (per device) support")
}
if !sysInfo.BlkioReadBpsDevice {
if v.CgroupVersion == "2" {
v.Warnings = append(v.Warnings, "WARNING: No io.max (rbps) support")
} else {
v.Warnings = append(v.Warnings, "WARNING: No blkio throttle.read_bps_device support")
}
}
if !sysInfo.BlkioWriteBpsDevice {
if v.CgroupVersion == "2" {
v.Warnings = append(v.Warnings, "WARNING: No io.max (wbps) support")
} else {
v.Warnings = append(v.Warnings, "WARNING: No blkio throttle.write_bps_device support")
}
}
if !sysInfo.BlkioReadIOpsDevice {
if v.CgroupVersion == "2" {
v.Warnings = append(v.Warnings, "WARNING: No io.max (riops) support")
} else {
v.Warnings = append(v.Warnings, "WARNING: No blkio throttle.read_iops_device support")
}
}
if !sysInfo.BlkioWriteIOpsDevice {
if v.CgroupVersion == "2" {
v.Warnings = append(v.Warnings, "WARNING: No io.max (wiops) support")
} else {
v.Warnings = append(v.Warnings, "WARNING: No blkio throttle.write_iops_device support")
}
}
}
if !v.IPv4Forwarding {
v.Warnings = append(v.Warnings, "WARNING: IPv4 forwarding is disabled")
}
return nil
}
func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *types.Version, cfg *configStore) error {
if err := daemon.populateContainerdVersion(ctx, v); err != nil {
return err
}
if err := populateRuncVersion(cfg, v); err != nil {
log.G(ctx).WithError(err).Warn("Failed to retrieve default runtime version")
}
if err := populateInitVersion(ctx, cfg, v); err != nil {
return err
}
if err := daemon.fillRootlessVersion(ctx, v); err != nil {
if errdefs.IsContext(err) {
return err
}
log.G(ctx).WithError(err).Warn("Failed to fill rootless version")
}
return nil
}
func populateRuncCommit(v *system.Commit, cfg *configStore) error {
_, _, commit, err := parseDefaultRuntimeVersion(&cfg.Runtimes)
if err != nil {
return err
}
v.ID = commit
v.Expected = commit
return nil
}
func (daemon *Daemon) populateInitCommit(ctx context.Context, v *system.Info, cfg *configStore) error {
v.InitBinary = cfg.GetInitPath()
initBinary, err := cfg.LookupInitPath()
if err != nil {
log.G(ctx).WithError(err).Warnf("Failed to find docker-init")
return nil
}
rv, err := exec.CommandContext(ctx, initBinary, "--version").Output()
if err != nil {
if errdefs.IsContext(err) {
return err
}
log.G(ctx).WithError(err).Warnf("Failed to retrieve %s version", initBinary)
return nil
}
_, commit, err := parseInitVersion(string(rv))
if err != nil {
log.G(ctx).WithError(err).Warnf("failed to parse %s version", initBinary)
return nil
}
v.InitCommit.ID = commit
v.InitCommit.Expected = v.InitCommit.ID
return nil
}
func (daemon *Daemon) fillRootlessVersion(ctx context.Context, v *types.Version) error {
if !rootless.RunningWithRootlessKit() {
return nil
}
rlc, err := getRootlessKitClient()
if err != nil {
return errors.Wrap(err, "failed to create RootlessKit client")
}
rlInfo, err := rlc.Info(ctx)
if err != nil {
return errors.Wrap(err, "failed to retrieve RootlessKit version")
}
rlV := types.ComponentVersion{
Name: "rootlesskit",
Version: rlInfo.Version,
Details: map[string]string{
"ApiVersion": rlInfo.APIVersion,
"StateDir": rlInfo.StateDir,
},
}
if netDriver := rlInfo.NetworkDriver; netDriver != nil {
// netDriver is nil for the "host" network driver
// (not used for Rootless Docker)
rlV.Details["NetworkDriver"] = netDriver.Driver
}
if portDriver := rlInfo.PortDriver; portDriver != nil {
// portDriver is nil for the "implicit" port driver
// (used with "pasta" network driver)
//
// Because the ports are not managed via RootlessKit API in this case.
rlV.Details["PortDriver"] = portDriver.Driver
}
v.Components = append(v.Components, rlV)
switch rlInfo.NetworkDriver.Driver {
case "slirp4netns":
err = func() error {
rv, err := exec.CommandContext(ctx, "slirp4netns", "--version").Output()
if err != nil {
if errdefs.IsContext(err) {
return err
}
log.G(ctx).WithError(err).Warn("Failed to retrieve slirp4netns version")
return nil
}
_, ver, commit, err := parseRuntimeVersion(string(rv))
if err != nil {
log.G(ctx).WithError(err).Warn("Failed to parse slirp4netns version")
return nil
}
v.Components = append(v.Components, types.ComponentVersion{
Name: "slirp4netns",
Version: ver,
Details: map[string]string{
"GitCommit": commit,
},
})
return nil
}()
if err != nil {
return err
}
case "vpnkit":
err = func() error {
out, err := exec.CommandContext(ctx, "vpnkit", "--version").Output()
if err != nil {
if errdefs.IsContext(err) {
return err
}
log.G(ctx).WithError(err).Warn("Failed to retrieve vpnkit version")
return nil
}
v.Components = append(v.Components, types.ComponentVersion{
Name: "vpnkit",
Version: strings.TrimSpace(strings.TrimSpace(string(out))),
})
return nil
}()
if err != nil {
return err
}
}
return nil
}
// getRootlessKitClient returns RootlessKit client
func getRootlessKitClient() (rkclient.Client, error) {
stateDir := os.Getenv("ROOTLESSKIT_STATE_DIR")
if stateDir == "" {
return nil, errors.New("environment variable `ROOTLESSKIT_STATE_DIR` is not set")
}
apiSock := filepath.Join(stateDir, "api.sock")
return rkclient.New(apiSock)
}
func fillDriverWarnings(v *system.Info) {
for _, pair := range v.DriverStatus {
if pair[0] == "Extended file attributes" && pair[1] == "best-effort" {
msg := fmt.Sprintf("WARNING: %s: extended file attributes from container images "+
"will be silently discarded if the backing filesystem does not support them.\n"+
" CONTAINERS MAY MALFUNCTION IF EXTENDED ATTRIBUTES ARE MISSING.\n"+
" This is an UNSUPPORTABLE configuration for which no bug reports will be accepted.\n", v.Driver)
v.Warnings = append(v.Warnings, msg)
continue
}
}
}
// parseInitVersion parses a Tini version string, and extracts the "version"
// and "git commit" from the output.
//
// Output example from `docker-init --version`:
//
// tini version 0.18.0 - git.fec3683
func parseInitVersion(v string) (version string, commit string, err error) {
parts := strings.Split(v, " - ")
if len(parts) >= 2 {
gitParts := strings.Split(strings.TrimSpace(parts[1]), ".")
if len(gitParts) == 2 && gitParts[0] == "git" {
commit = gitParts[1]
}
}
parts[0] = strings.TrimSpace(parts[0])
if strings.HasPrefix(parts[0], "tini version ") {
version = strings.TrimPrefix(parts[0], "tini version ")
}
if version == "" && commit == "" {
err = errors.Errorf("unknown output format: %s", v)
}
return version, commit, err
}
// parseRuntimeVersion parses the output of `[runtime] --version` and extracts the
// "name", "version" and "git commit" from the output.
//
// Output example from `runc --version`:
//
// runc version 1.0.0-rc5+dev
// commit: 69663f0bd4b60df09991c08812a60108003fa340
// spec: 1.0.0
func parseRuntimeVersion(v string) (runtime, version, commit string, err error) {
lines := strings.Split(strings.TrimSpace(v), "\n")
for _, line := range lines {
if strings.Contains(line, "version") {
s := strings.Split(line, "version")
runtime = strings.TrimSpace(s[0])
version = strings.TrimSpace(s[len(s)-1])
continue
}
if strings.HasPrefix(line, "commit:") {
commit = strings.TrimSpace(strings.TrimPrefix(line, "commit:"))
continue
}
}
if version == "" && commit == "" {
err = errors.Errorf("unknown output format: %s", v)
}
return runtime, version, commit, err
}
func parseDefaultRuntimeVersion(rts *runtimes) (runtime, version, commit string, err error) {
shim, opts, err := rts.Get(rts.Default)
if err != nil {
return "", "", "", err
}
shimopts, ok := opts.(*v2runcoptions.Options)
if !ok {
return "", "", "", fmt.Errorf("%s: retrieving version not supported", shim)
}
rt := shimopts.BinaryName
if rt == "" {
rt = defaultRuntimeName
}
rv, err := exec.Command(rt, "--version").Output()
if err != nil {
return "", "", "", fmt.Errorf("failed to retrieve %s version: %w", rt, err)
}
runtime, version, commit, err = parseRuntimeVersion(string(rv))
if err != nil {
return "", "", "", fmt.Errorf("failed to parse %s version: %w", rt, err)
}
return runtime, version, commit, err
}
func cgroupNamespacesEnabled(sysInfo *sysinfo.SysInfo, cfg *config.Config) bool {
return sysInfo.CgroupNamespaces && containertypes.CgroupnsMode(cfg.CgroupNamespaceMode).IsPrivate()
}
// Rootless returns true if daemon is running in rootless mode
func Rootless(cfg *config.Config) bool {
return cfg.Rootless
}
func noNewPrivileges(cfg *config.Config) bool {
return cfg.NoNewPrivileges
}
func (daemon *Daemon) populateContainerdCommit(ctx context.Context, v *system.Commit) error {
rv, err := daemon.containerd.Version(ctx)
if err != nil {
if errdefs.IsContext(err) {
return err
}
log.G(ctx).WithError(err).Warnf("Failed to retrieve containerd version")
return nil
}
v.ID = rv.Revision
v.Expected = rv.Revision
return nil
}
func (daemon *Daemon) populateContainerdVersion(ctx context.Context, v *types.Version) error {
rv, err := daemon.containerd.Version(ctx)
if err != nil {
if errdefs.IsContext(err) {
return err
}
log.G(ctx).WithError(err).Warn("Failed to retrieve containerd version")
return nil
}
v.Components = append(v.Components, types.ComponentVersion{
Name: "containerd",
Version: rv.Version,
Details: map[string]string{
"GitCommit": rv.Revision,
},
})
return nil
}
func populateRuncVersion(cfg *configStore, v *types.Version) error {
_, ver, commit, err := parseDefaultRuntimeVersion(&cfg.Runtimes)
if err != nil {
return err
}
v.Components = append(v.Components, types.ComponentVersion{
Name: cfg.Runtimes.Default,
Version: ver,
Details: map[string]string{
"GitCommit": commit,
},
})
return nil
}
func populateInitVersion(ctx context.Context, cfg *configStore, v *types.Version) error {
initBinary, err := cfg.LookupInitPath()
if err != nil {
log.G(ctx).WithError(err).Warn("Failed to find docker-init")
return nil
}
rv, err := exec.CommandContext(ctx, initBinary, "--version").Output()
if err != nil {
if errdefs.IsContext(err) {
return err
}
log.G(ctx).WithError(err).Warnf("Failed to retrieve %s version", initBinary)
return nil
}
ver, commit, err := parseInitVersion(string(rv))
if err != nil {
log.G(ctx).WithError(err).Warnf("failed to parse %s version", initBinary)
return nil
}
v.Components = append(v.Components, types.ComponentVersion{
Name: filepath.Base(initBinary),
Version: ver,
Details: map[string]string{
"GitCommit": commit,
},
})
return nil
}
// ociRuntimeFeaturesKey is the "well-known" key used for including the
// OCI runtime spec "features" struct.
//
// see https://github.com/opencontainers/runtime-spec/blob/main/features.md
const ociRuntimeFeaturesKey = "org.opencontainers.runtime-spec.features"
func (daemon *Daemon) runtimeStatus(ctx context.Context, cfg *configStore, runtimeName string) map[string]string {
m := make(map[string]string)
if runtimeName == "" {
runtimeName = cfg.Runtimes.Default
}
if features := cfg.Runtimes.Features(runtimeName); features != nil {
if j, err := json.Marshal(features); err == nil {
m[ociRuntimeFeaturesKey] = string(j)
} else {
log.G(ctx).WithFields(log.Fields{"error": err, "runtime": runtimeName}).Warn("Failed to call json.Marshal for the OCI features struct of runtime")
}
}
return m
}
|