info_unix.go 8.1 KB

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