info_unix.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // +build !windows
  2. package daemon // import "github.com/docker/docker/daemon"
  3. import (
  4. "context"
  5. "fmt"
  6. "os/exec"
  7. "path/filepath"
  8. "strings"
  9. "github.com/docker/docker/api/types"
  10. containertypes "github.com/docker/docker/api/types/container"
  11. "github.com/docker/docker/dockerversion"
  12. "github.com/docker/docker/pkg/sysinfo"
  13. "github.com/pkg/errors"
  14. "github.com/sirupsen/logrus"
  15. )
  16. // fillPlatformInfo fills the platform related info.
  17. func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) {
  18. v.MemoryLimit = sysInfo.MemoryLimit
  19. v.SwapLimit = sysInfo.SwapLimit
  20. v.KernelMemory = sysInfo.KernelMemory
  21. v.KernelMemoryTCP = sysInfo.KernelMemoryTCP
  22. v.OomKillDisable = sysInfo.OomKillDisable
  23. v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
  24. v.CPUCfsQuota = sysInfo.CPUCfsQuota
  25. v.CPUShares = sysInfo.CPUShares
  26. v.CPUSet = sysInfo.Cpuset
  27. v.PidsLimit = sysInfo.PidsLimit
  28. v.Runtimes = daemon.configStore.GetAllRuntimes()
  29. v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
  30. v.InitBinary = daemon.configStore.GetInitPath()
  31. defaultRuntimeBinary := daemon.configStore.GetRuntime(v.DefaultRuntime).Path
  32. if rv, err := exec.Command(defaultRuntimeBinary, "--version").Output(); err == nil {
  33. if _, commit, err := parseRuncVersion(string(rv)); err != nil {
  34. logrus.Warnf("failed to parse %s version: %v", defaultRuntimeBinary, err)
  35. v.RuncCommit.ID = "N/A"
  36. } else {
  37. v.RuncCommit.ID = commit
  38. }
  39. } else {
  40. logrus.Warnf("failed to retrieve %s version: %v", defaultRuntimeBinary, err)
  41. v.RuncCommit.ID = "N/A"
  42. }
  43. // runc is now shipped as a separate package. Set "expected" to same value
  44. // as "ID" to prevent clients from reporting a version-mismatch
  45. v.RuncCommit.Expected = v.RuncCommit.ID
  46. if rv, err := daemon.containerd.Version(context.Background()); err == nil {
  47. v.ContainerdCommit.ID = rv.Revision
  48. } else {
  49. logrus.Warnf("failed to retrieve containerd version: %v", err)
  50. v.ContainerdCommit.ID = "N/A"
  51. }
  52. // containerd is now shipped as a separate package. Set "expected" to same
  53. // value as "ID" to prevent clients from reporting a version-mismatch
  54. v.ContainerdCommit.Expected = v.ContainerdCommit.ID
  55. // TODO is there still a need to check the expected version for tini?
  56. // if not, we can change this, and just set "Expected" to v.InitCommit.ID
  57. v.InitCommit.Expected = dockerversion.InitCommitID
  58. defaultInitBinary := daemon.configStore.GetInitPath()
  59. if rv, err := exec.Command(defaultInitBinary, "--version").Output(); err == nil {
  60. if _, commit, err := parseInitVersion(string(rv)); err != nil {
  61. logrus.Warnf("failed to parse %s version: %s", defaultInitBinary, err)
  62. v.InitCommit.ID = "N/A"
  63. } else {
  64. v.InitCommit.ID = commit
  65. v.InitCommit.Expected = dockerversion.InitCommitID[0:len(commit)]
  66. }
  67. } else {
  68. logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
  69. v.InitCommit.ID = "N/A"
  70. }
  71. if !v.MemoryLimit {
  72. v.Warnings = append(v.Warnings, "WARNING: No memory limit support")
  73. }
  74. if !v.SwapLimit {
  75. v.Warnings = append(v.Warnings, "WARNING: No swap limit support")
  76. }
  77. if !v.KernelMemory {
  78. v.Warnings = append(v.Warnings, "WARNING: No kernel memory limit support")
  79. }
  80. if !v.KernelMemoryTCP {
  81. v.Warnings = append(v.Warnings, "WARNING: No kernel memory TCP limit support")
  82. }
  83. if !v.OomKillDisable {
  84. v.Warnings = append(v.Warnings, "WARNING: No oom kill disable support")
  85. }
  86. if !v.CPUCfsQuota {
  87. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs quota support")
  88. }
  89. if !v.CPUCfsPeriod {
  90. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs period support")
  91. }
  92. if !v.CPUShares {
  93. v.Warnings = append(v.Warnings, "WARNING: No cpu shares support")
  94. }
  95. if !v.CPUSet {
  96. v.Warnings = append(v.Warnings, "WARNING: No cpuset support")
  97. }
  98. if !v.IPv4Forwarding {
  99. v.Warnings = append(v.Warnings, "WARNING: IPv4 forwarding is disabled")
  100. }
  101. if !v.BridgeNfIptables {
  102. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-iptables is disabled")
  103. }
  104. if !v.BridgeNfIP6tables {
  105. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-ip6tables is disabled")
  106. }
  107. }
  108. func (daemon *Daemon) fillPlatformVersion(v *types.Version) {
  109. if rv, err := daemon.containerd.Version(context.Background()); err == nil {
  110. v.Components = append(v.Components, types.ComponentVersion{
  111. Name: "containerd",
  112. Version: rv.Version,
  113. Details: map[string]string{
  114. "GitCommit": rv.Revision,
  115. },
  116. })
  117. }
  118. defaultRuntime := daemon.configStore.GetDefaultRuntimeName()
  119. defaultRuntimeBinary := daemon.configStore.GetRuntime(defaultRuntime).Path
  120. if rv, err := exec.Command(defaultRuntimeBinary, "--version").Output(); err == nil {
  121. if ver, commit, err := parseRuncVersion(string(rv)); err != nil {
  122. logrus.Warnf("failed to parse %s version: %v", defaultRuntimeBinary, err)
  123. } else {
  124. v.Components = append(v.Components, types.ComponentVersion{
  125. Name: defaultRuntime,
  126. Version: ver,
  127. Details: map[string]string{
  128. "GitCommit": commit,
  129. },
  130. })
  131. }
  132. } else {
  133. logrus.Warnf("failed to retrieve %s version: %v", defaultRuntimeBinary, err)
  134. }
  135. defaultInitBinary := daemon.configStore.GetInitPath()
  136. if rv, err := exec.Command(defaultInitBinary, "--version").Output(); err == nil {
  137. if ver, commit, err := parseInitVersion(string(rv)); err != nil {
  138. logrus.Warnf("failed to parse %s version: %s", defaultInitBinary, err)
  139. } else {
  140. v.Components = append(v.Components, types.ComponentVersion{
  141. Name: filepath.Base(defaultInitBinary),
  142. Version: ver,
  143. Details: map[string]string{
  144. "GitCommit": commit,
  145. },
  146. })
  147. }
  148. } else {
  149. logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
  150. }
  151. }
  152. func fillDriverWarnings(v *types.Info) {
  153. for _, pair := range v.DriverStatus {
  154. if pair[0] == "Data loop file" {
  155. msg := fmt.Sprintf("WARNING: %s: usage of loopback devices is "+
  156. "strongly discouraged for production use.\n "+
  157. "Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.", v.Driver)
  158. v.Warnings = append(v.Warnings, msg)
  159. continue
  160. }
  161. if pair[0] == "Supports d_type" && pair[1] == "false" {
  162. backingFs := getBackingFs(v)
  163. msg := fmt.Sprintf("WARNING: %s: the backing %s filesystem is formatted without d_type support, which leads to incorrect behavior.\n", v.Driver, backingFs)
  164. if backingFs == "xfs" {
  165. msg += " Reformat the filesystem with ftype=1 to enable d_type support.\n"
  166. }
  167. msg += " Running without d_type support will not be supported in future releases."
  168. v.Warnings = append(v.Warnings, msg)
  169. continue
  170. }
  171. }
  172. }
  173. func getBackingFs(v *types.Info) string {
  174. for _, pair := range v.DriverStatus {
  175. if pair[0] == "Backing Filesystem" {
  176. return pair[1]
  177. }
  178. }
  179. return ""
  180. }
  181. // parseInitVersion parses a Tini version string, and extracts the "version"
  182. // and "git commit" from the output.
  183. //
  184. // Output example from `docker-init --version`:
  185. //
  186. // tini version 0.18.0 - git.fec3683
  187. func parseInitVersion(v string) (version string, commit string, err error) {
  188. parts := strings.Split(v, " - ")
  189. if len(parts) >= 2 {
  190. gitParts := strings.Split(strings.TrimSpace(parts[1]), ".")
  191. if len(gitParts) == 2 && gitParts[0] == "git" {
  192. commit = gitParts[1]
  193. }
  194. }
  195. parts[0] = strings.TrimSpace(parts[0])
  196. if strings.HasPrefix(parts[0], "tini version ") {
  197. version = strings.TrimPrefix(parts[0], "tini version ")
  198. }
  199. if version == "" && commit == "" {
  200. err = errors.Errorf("unknown output format: %s", v)
  201. }
  202. return version, commit, err
  203. }
  204. // parseRuncVersion parses the output of `runc --version` and extracts the
  205. // "version" and "git commit" from the output.
  206. //
  207. // Output example from `runc --version`:
  208. //
  209. // runc version 1.0.0-rc5+dev
  210. // commit: 69663f0bd4b60df09991c08812a60108003fa340
  211. // spec: 1.0.0
  212. func parseRuncVersion(v string) (version string, commit string, err error) {
  213. lines := strings.Split(strings.TrimSpace(v), "\n")
  214. for _, line := range lines {
  215. if strings.HasPrefix(line, "runc version") {
  216. version = strings.TrimSpace(strings.TrimPrefix(line, "runc version"))
  217. continue
  218. }
  219. if strings.HasPrefix(line, "commit:") {
  220. commit = strings.TrimSpace(strings.TrimPrefix(line, "commit:"))
  221. continue
  222. }
  223. }
  224. if version == "" && commit == "" {
  225. err = errors.Errorf("unknown output format: %s", v)
  226. }
  227. return version, commit, err
  228. }
  229. func (daemon *Daemon) cgroupNamespacesEnabled(sysInfo *sysinfo.SysInfo) bool {
  230. return sysInfo.CgroupNamespaces && containertypes.CgroupnsMode(daemon.configStore.CgroupNamespaceMode).IsPrivate()
  231. }
  232. // Rootless returns true if daemon is running in rootless mode
  233. func (daemon *Daemon) Rootless() bool {
  234. return daemon.configStore.Rootless
  235. }