daemon_unix.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. // +build linux freebsd
  2. package daemon
  3. import (
  4. "fmt"
  5. "net"
  6. "net/http"
  7. "os"
  8. "path/filepath"
  9. "strings"
  10. "syscall"
  11. "github.com/Sirupsen/logrus"
  12. "github.com/docker/docker/autogen/dockerversion"
  13. "github.com/docker/docker/context"
  14. "github.com/docker/docker/daemon/graphdriver"
  15. "github.com/docker/docker/pkg/fileutils"
  16. "github.com/docker/docker/pkg/parsers"
  17. "github.com/docker/docker/pkg/parsers/kernel"
  18. "github.com/docker/docker/pkg/sysinfo"
  19. "github.com/docker/docker/pkg/system"
  20. "github.com/docker/docker/runconfig"
  21. "github.com/docker/docker/utils"
  22. "github.com/docker/libnetwork"
  23. nwapi "github.com/docker/libnetwork/api"
  24. nwconfig "github.com/docker/libnetwork/config"
  25. "github.com/docker/libnetwork/netlabel"
  26. "github.com/docker/libnetwork/options"
  27. "github.com/opencontainers/runc/libcontainer/label"
  28. )
  29. const (
  30. // See https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/tree/kernel/sched/sched.h?id=8cd9234c64c584432f6992fe944ca9e46ca8ea76#n269
  31. linuxMinCPUShares = 2
  32. linuxMaxCPUShares = 262144
  33. platformSupported = true
  34. )
  35. func parseSecurityOpt(container *Container, config *runconfig.HostConfig) error {
  36. var (
  37. labelOpts []string
  38. err error
  39. )
  40. for _, opt := range config.SecurityOpt {
  41. con := strings.SplitN(opt, ":", 2)
  42. if len(con) == 1 {
  43. return fmt.Errorf("Invalid --security-opt: %q", opt)
  44. }
  45. switch con[0] {
  46. case "label":
  47. labelOpts = append(labelOpts, con[1])
  48. case "apparmor":
  49. container.AppArmorProfile = con[1]
  50. default:
  51. return fmt.Errorf("Invalid --security-opt: %q", opt)
  52. }
  53. }
  54. container.ProcessLabel, container.MountLabel, err = label.InitLabels(labelOpts)
  55. return err
  56. }
  57. func checkKernelVersion(k, major, minor int) bool {
  58. if v, err := kernel.GetKernelVersion(); err != nil {
  59. logrus.Warnf("%s", err)
  60. } else {
  61. if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: k, Major: major, Minor: minor}) < 0 {
  62. return false
  63. }
  64. }
  65. return true
  66. }
  67. func checkKernel() error {
  68. // Check for unsupported kernel versions
  69. // FIXME: it would be cleaner to not test for specific versions, but rather
  70. // test for specific functionalities.
  71. // Unfortunately we can't test for the feature "does not cause a kernel panic"
  72. // without actually causing a kernel panic, so we need this workaround until
  73. // the circumstances of pre-3.10 crashes are clearer.
  74. // For details see https://github.com/docker/docker/issues/407
  75. if !checkKernelVersion(3, 10, 0) {
  76. v, _ := kernel.GetKernelVersion()
  77. if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" {
  78. logrus.Warnf("Your Linux kernel version %s can be unstable running docker. Please upgrade your kernel to 3.10.0.", v.String())
  79. }
  80. }
  81. return nil
  82. }
  83. // adaptContainerSettings is called during container creation to modify any
  84. // settings necessary in the HostConfig structure.
  85. func (daemon *Daemon) adaptContainerSettings(hostConfig *runconfig.HostConfig, adjustCPUShares bool) {
  86. if hostConfig == nil {
  87. return
  88. }
  89. if adjustCPUShares && hostConfig.CPUShares > 0 {
  90. // Handle unsupported CPUShares
  91. if hostConfig.CPUShares < linuxMinCPUShares {
  92. logrus.Warnf("Changing requested CPUShares of %d to minimum allowed of %d", hostConfig.CPUShares, linuxMinCPUShares)
  93. hostConfig.CPUShares = linuxMinCPUShares
  94. } else if hostConfig.CPUShares > linuxMaxCPUShares {
  95. logrus.Warnf("Changing requested CPUShares of %d to maximum allowed of %d", hostConfig.CPUShares, linuxMaxCPUShares)
  96. hostConfig.CPUShares = linuxMaxCPUShares
  97. }
  98. }
  99. if hostConfig.Memory > 0 && hostConfig.MemorySwap == 0 {
  100. // By default, MemorySwap is set to twice the size of Memory.
  101. hostConfig.MemorySwap = hostConfig.Memory * 2
  102. }
  103. }
  104. // verifyPlatformContainerSettings performs platform-specific validation of the
  105. // hostconfig and config structures.
  106. func verifyPlatformContainerSettings(ctx context.Context, daemon *Daemon, hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) {
  107. warnings := []string{}
  108. sysInfo := sysinfo.New(true)
  109. if hostConfig.LxcConf.Len() > 0 && !strings.Contains(daemon.ExecutionDriver(ctx).Name(), "lxc") {
  110. return warnings, fmt.Errorf("Cannot use --lxc-conf with execdriver: %s", daemon.ExecutionDriver(ctx).Name())
  111. }
  112. // memory subsystem checks and adjustments
  113. if hostConfig.Memory != 0 && hostConfig.Memory < 4194304 {
  114. return warnings, fmt.Errorf("Minimum memory limit allowed is 4MB")
  115. }
  116. if hostConfig.Memory > 0 && !sysInfo.MemoryLimit {
  117. warnings = append(warnings, "Your kernel does not support memory limit capabilities. Limitation discarded.")
  118. logrus.Warnf("Your kernel does not support memory limit capabilities. Limitation discarded.")
  119. hostConfig.Memory = 0
  120. hostConfig.MemorySwap = -1
  121. }
  122. if hostConfig.Memory > 0 && hostConfig.MemorySwap != -1 && !sysInfo.SwapLimit {
  123. warnings = append(warnings, "Your kernel does not support swap limit capabilities, memory limited without swap.")
  124. logrus.Warnf("Your kernel does not support swap limit capabilities, memory limited without swap.")
  125. hostConfig.MemorySwap = -1
  126. }
  127. if hostConfig.Memory > 0 && hostConfig.MemorySwap > 0 && hostConfig.MemorySwap < hostConfig.Memory {
  128. return warnings, fmt.Errorf("Minimum memoryswap limit should be larger than memory limit, see usage.")
  129. }
  130. if hostConfig.Memory == 0 && hostConfig.MemorySwap > 0 {
  131. return warnings, fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage.")
  132. }
  133. if hostConfig.MemorySwappiness != nil && *hostConfig.MemorySwappiness != -1 && !sysInfo.MemorySwappiness {
  134. warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, memory swappiness discarded.")
  135. logrus.Warnf("Your kernel does not support memory swappiness capabilities, memory swappiness discarded.")
  136. hostConfig.MemorySwappiness = nil
  137. }
  138. if hostConfig.MemorySwappiness != nil {
  139. swappiness := *hostConfig.MemorySwappiness
  140. if swappiness < -1 || swappiness > 100 {
  141. return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100.", swappiness)
  142. }
  143. }
  144. if hostConfig.KernelMemory > 0 && !sysInfo.KernelMemory {
  145. warnings = append(warnings, "Your kernel does not support kernel memory limit capabilities. Limitation discarded.")
  146. logrus.Warnf("Your kernel does not support kernel memory limit capabilities. Limitation discarded.")
  147. hostConfig.KernelMemory = 0
  148. }
  149. if hostConfig.KernelMemory > 0 && !checkKernelVersion(4, 0, 0) {
  150. warnings = append(warnings, "You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.")
  151. logrus.Warnf("You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.")
  152. }
  153. if hostConfig.CPUShares > 0 && !sysInfo.CPUShares {
  154. warnings = append(warnings, "Your kernel does not support CPU shares. Shares discarded.")
  155. logrus.Warnf("Your kernel does not support CPU shares. Shares discarded.")
  156. hostConfig.CPUShares = 0
  157. }
  158. if hostConfig.CPUPeriod > 0 && !sysInfo.CPUCfsPeriod {
  159. warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.")
  160. logrus.Warnf("Your kernel does not support CPU cfs period. Period discarded.")
  161. hostConfig.CPUPeriod = 0
  162. }
  163. if hostConfig.CPUQuota > 0 && !sysInfo.CPUCfsQuota {
  164. warnings = append(warnings, "Your kernel does not support CPU cfs quota. Quota discarded.")
  165. logrus.Warnf("Your kernel does not support CPU cfs quota. Quota discarded.")
  166. hostConfig.CPUQuota = 0
  167. }
  168. if (hostConfig.CpusetCpus != "" || hostConfig.CpusetMems != "") && !sysInfo.Cpuset {
  169. warnings = append(warnings, "Your kernel does not support cpuset. Cpuset discarded.")
  170. logrus.Warnf("Your kernel does not support cpuset. Cpuset discarded.")
  171. hostConfig.CpusetCpus = ""
  172. hostConfig.CpusetMems = ""
  173. }
  174. if hostConfig.BlkioWeight > 0 && !sysInfo.BlkioWeight {
  175. warnings = append(warnings, "Your kernel does not support Block I/O weight. Weight discarded.")
  176. logrus.Warnf("Your kernel does not support Block I/O weight. Weight discarded.")
  177. hostConfig.BlkioWeight = 0
  178. }
  179. if hostConfig.BlkioWeight > 0 && (hostConfig.BlkioWeight < 10 || hostConfig.BlkioWeight > 1000) {
  180. return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000.")
  181. }
  182. if hostConfig.OomKillDisable && !sysInfo.OomKillDisable {
  183. hostConfig.OomKillDisable = false
  184. return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
  185. }
  186. if sysInfo.IPv4ForwardingDisabled {
  187. warnings = append(warnings, "IPv4 forwarding is disabled. Networking will not work.")
  188. logrus.Warnf("IPv4 forwarding is disabled. Networking will not work")
  189. }
  190. return warnings, nil
  191. }
  192. // checkConfigOptions checks for mutually incompatible config options
  193. func checkConfigOptions(config *Config) error {
  194. // Check for mutually incompatible config options
  195. if config.Bridge.Iface != "" && config.Bridge.IP != "" {
  196. return fmt.Errorf("You specified -b & --bip, mutually exclusive options. Please specify only one.")
  197. }
  198. if !config.Bridge.EnableIPTables && !config.Bridge.InterContainerCommunication {
  199. return fmt.Errorf("You specified --iptables=false with --icc=false. ICC uses iptables to function. Please set --icc or --iptables to true.")
  200. }
  201. if !config.Bridge.EnableIPTables && config.Bridge.EnableIPMasq {
  202. config.Bridge.EnableIPMasq = false
  203. }
  204. return nil
  205. }
  206. // checkSystem validates platform-specific requirements
  207. func checkSystem() error {
  208. if os.Geteuid() != 0 {
  209. return fmt.Errorf("The Docker daemon needs to be run as root")
  210. }
  211. if err := checkKernel(); err != nil {
  212. return err
  213. }
  214. return nil
  215. }
  216. // configureKernelSecuritySupport configures and validate security support for the kernel
  217. func configureKernelSecuritySupport(config *Config, driverName string) error {
  218. if config.EnableSelinuxSupport {
  219. if selinuxEnabled() {
  220. // As Docker on either btrfs or overlayFS and SELinux are incompatible at present, error on both being enabled
  221. if driverName == "btrfs" || driverName == "overlay" {
  222. return fmt.Errorf("SELinux is not supported with the %s graph driver", driverName)
  223. }
  224. logrus.Debug("SELinux enabled successfully")
  225. } else {
  226. logrus.Warn("Docker could not enable SELinux on the host system")
  227. }
  228. } else {
  229. selinuxSetDisabled()
  230. }
  231. return nil
  232. }
  233. // MigrateIfDownlevel is a wrapper for AUFS migration for downlevel
  234. func migrateIfDownlevel(driver graphdriver.Driver, root string) error {
  235. return migrateIfAufs(driver, root)
  236. }
  237. func configureSysInit(config *Config) (string, error) {
  238. localCopy := filepath.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", dockerversion.VERSION))
  239. sysInitPath := utils.DockerInitPath(localCopy)
  240. if sysInitPath == "" {
  241. return "", fmt.Errorf("Could not locate dockerinit: This usually means docker was built incorrectly. See https://docs.docker.com/contributing/devenvironment for official build instructions.")
  242. }
  243. if sysInitPath != localCopy {
  244. // When we find a suitable dockerinit binary (even if it's our local binary), we copy it into config.Root at localCopy for future use (so that the original can go away without that being a problem, for example during a package upgrade).
  245. if err := os.Mkdir(filepath.Dir(localCopy), 0700); err != nil && !os.IsExist(err) {
  246. return "", err
  247. }
  248. if _, err := fileutils.CopyFile(sysInitPath, localCopy); err != nil {
  249. return "", err
  250. }
  251. if err := os.Chmod(localCopy, 0700); err != nil {
  252. return "", err
  253. }
  254. sysInitPath = localCopy
  255. }
  256. return sysInitPath, nil
  257. }
  258. func isBridgeNetworkDisabled(config *Config) bool {
  259. return config.Bridge.Iface == disableNetworkBridge
  260. }
  261. func networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
  262. options := []nwconfig.Option{}
  263. if dconfig == nil {
  264. return options, nil
  265. }
  266. if strings.TrimSpace(dconfig.DefaultNetwork) != "" {
  267. dn := strings.Split(dconfig.DefaultNetwork, ":")
  268. if len(dn) < 2 {
  269. return nil, fmt.Errorf("default network daemon config must be of the form NETWORKDRIVER:NETWORKNAME")
  270. }
  271. options = append(options, nwconfig.OptionDefaultDriver(dn[0]))
  272. options = append(options, nwconfig.OptionDefaultNetwork(strings.Join(dn[1:], ":")))
  273. } else {
  274. dd := runconfig.DefaultDaemonNetworkMode()
  275. dn := runconfig.DefaultDaemonNetworkMode().NetworkName()
  276. options = append(options, nwconfig.OptionDefaultDriver(string(dd)))
  277. options = append(options, nwconfig.OptionDefaultNetwork(dn))
  278. }
  279. if strings.TrimSpace(dconfig.NetworkKVStore) != "" {
  280. kv := strings.Split(dconfig.NetworkKVStore, ":")
  281. if len(kv) < 2 {
  282. return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER:KV-URL")
  283. }
  284. options = append(options, nwconfig.OptionKVProvider(kv[0]))
  285. options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], ":")))
  286. }
  287. options = append(options, nwconfig.OptionLabels(dconfig.Labels))
  288. return options, nil
  289. }
  290. func initNetworkController(config *Config) (libnetwork.NetworkController, error) {
  291. netOptions, err := networkOptions(config)
  292. if err != nil {
  293. return nil, err
  294. }
  295. controller, err := libnetwork.New(netOptions...)
  296. if err != nil {
  297. return nil, fmt.Errorf("error obtaining controller instance: %v", err)
  298. }
  299. // Initialize default driver "null"
  300. if err := controller.ConfigureNetworkDriver("null", options.Generic{}); err != nil {
  301. return nil, fmt.Errorf("Error initializing null driver: %v", err)
  302. }
  303. // Initialize default network on "null"
  304. if _, err := controller.NewNetwork("null", "none"); err != nil {
  305. return nil, fmt.Errorf("Error creating default \"null\" network: %v", err)
  306. }
  307. // Initialize default driver "host"
  308. if err := controller.ConfigureNetworkDriver("host", options.Generic{}); err != nil {
  309. return nil, fmt.Errorf("Error initializing host driver: %v", err)
  310. }
  311. // Initialize default network on "host"
  312. if _, err := controller.NewNetwork("host", "host"); err != nil {
  313. return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
  314. }
  315. if !config.DisableBridge {
  316. // Initialize default driver "bridge"
  317. if err := initBridgeDriver(controller, config); err != nil {
  318. return nil, err
  319. }
  320. }
  321. return controller, nil
  322. }
  323. func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
  324. option := options.Generic{
  325. "EnableIPForwarding": config.Bridge.EnableIPForward,
  326. "EnableIPTables": config.Bridge.EnableIPTables,
  327. "EnableUserlandProxy": config.Bridge.EnableUserlandProxy}
  328. if err := controller.ConfigureNetworkDriver("bridge", options.Generic{netlabel.GenericData: option}); err != nil {
  329. return fmt.Errorf("Error initializing bridge driver: %v", err)
  330. }
  331. netOption := options.Generic{
  332. "BridgeName": config.Bridge.Iface,
  333. "Mtu": config.Mtu,
  334. "EnableIPMasquerade": config.Bridge.EnableIPMasq,
  335. "EnableICC": config.Bridge.InterContainerCommunication,
  336. }
  337. if config.Bridge.IP != "" {
  338. ip, bipNet, err := net.ParseCIDR(config.Bridge.IP)
  339. if err != nil {
  340. return err
  341. }
  342. bipNet.IP = ip
  343. netOption["AddressIPv4"] = bipNet
  344. }
  345. if config.Bridge.FixedCIDR != "" {
  346. _, fCIDR, err := net.ParseCIDR(config.Bridge.FixedCIDR)
  347. if err != nil {
  348. return err
  349. }
  350. netOption["FixedCIDR"] = fCIDR
  351. }
  352. if config.Bridge.FixedCIDRv6 != "" {
  353. _, fCIDRv6, err := net.ParseCIDR(config.Bridge.FixedCIDRv6)
  354. if err != nil {
  355. return err
  356. }
  357. netOption["FixedCIDRv6"] = fCIDRv6
  358. }
  359. if config.Bridge.DefaultGatewayIPv4 != nil {
  360. netOption["DefaultGatewayIPv4"] = config.Bridge.DefaultGatewayIPv4
  361. }
  362. if config.Bridge.DefaultGatewayIPv6 != nil {
  363. netOption["DefaultGatewayIPv6"] = config.Bridge.DefaultGatewayIPv6
  364. }
  365. // --ip processing
  366. if config.Bridge.DefaultIP != nil {
  367. netOption["DefaultBindingIP"] = config.Bridge.DefaultIP
  368. }
  369. // Initialize default network on "bridge" with the same name
  370. _, err := controller.NewNetwork("bridge", "bridge",
  371. libnetwork.NetworkOptionGeneric(options.Generic{
  372. netlabel.GenericData: netOption,
  373. netlabel.EnableIPv6: config.Bridge.EnableIPv6,
  374. }))
  375. if err != nil {
  376. return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
  377. }
  378. return nil
  379. }
  380. // setupInitLayer populates a directory with mountpoints suitable
  381. // for bind-mounting dockerinit into the container. The mountpoint is simply an
  382. // empty file at /.dockerinit
  383. //
  384. // This extra layer is used by all containers as the top-most ro layer. It protects
  385. // the container from unwanted side-effects on the rw layer.
  386. func setupInitLayer(initLayer string) error {
  387. for pth, typ := range map[string]string{
  388. "/dev/pts": "dir",
  389. "/dev/shm": "dir",
  390. "/proc": "dir",
  391. "/sys": "dir",
  392. "/.dockerinit": "file",
  393. "/.dockerenv": "file",
  394. "/etc/resolv.conf": "file",
  395. "/etc/hosts": "file",
  396. "/etc/hostname": "file",
  397. "/dev/console": "file",
  398. "/etc/mtab": "/proc/mounts",
  399. } {
  400. parts := strings.Split(pth, "/")
  401. prev := "/"
  402. for _, p := range parts[1:] {
  403. prev = filepath.Join(prev, p)
  404. syscall.Unlink(filepath.Join(initLayer, prev))
  405. }
  406. if _, err := os.Stat(filepath.Join(initLayer, pth)); err != nil {
  407. if os.IsNotExist(err) {
  408. if err := system.MkdirAll(filepath.Join(initLayer, filepath.Dir(pth)), 0755); err != nil {
  409. return err
  410. }
  411. switch typ {
  412. case "dir":
  413. if err := system.MkdirAll(filepath.Join(initLayer, pth), 0755); err != nil {
  414. return err
  415. }
  416. case "file":
  417. f, err := os.OpenFile(filepath.Join(initLayer, pth), os.O_CREATE, 0755)
  418. if err != nil {
  419. return err
  420. }
  421. f.Close()
  422. default:
  423. if err := os.Symlink(typ, filepath.Join(initLayer, pth)); err != nil {
  424. return err
  425. }
  426. }
  427. } else {
  428. return err
  429. }
  430. }
  431. }
  432. // Layer is ready to use, if it wasn't before.
  433. return nil
  434. }
  435. // NetworkAPIRouter implements a feature for server-experimental,
  436. // directly calling into libnetwork.
  437. func (daemon *Daemon) NetworkAPIRouter(ctx context.Context) func(w http.ResponseWriter, req *http.Request) {
  438. return nwapi.NewHTTPHandler(daemon.netController)
  439. }
  440. // registerLinks writes the links to a file.
  441. func (daemon *Daemon) registerLinks(ctx context.Context, container *Container, hostConfig *runconfig.HostConfig) error {
  442. if hostConfig == nil || hostConfig.Links == nil {
  443. return nil
  444. }
  445. for _, l := range hostConfig.Links {
  446. name, alias, err := parsers.ParseLink(l)
  447. if err != nil {
  448. return err
  449. }
  450. child, err := daemon.Get(ctx, name)
  451. if err != nil {
  452. //An error from daemon.Get() means this name could not be found
  453. return fmt.Errorf("Could not get container for %s", name)
  454. }
  455. for child.hostConfig.NetworkMode.IsContainer() {
  456. parts := strings.SplitN(string(child.hostConfig.NetworkMode), ":", 2)
  457. child, err = daemon.Get(ctx, parts[1])
  458. if err != nil {
  459. return fmt.Errorf("Could not get container for %s", parts[1])
  460. }
  461. }
  462. if child.hostConfig.NetworkMode.IsHost() {
  463. return runconfig.ErrConflictHostNetworkAndLinks
  464. }
  465. if err := daemon.registerLink(container, child, alias); err != nil {
  466. return err
  467. }
  468. }
  469. // After we load all the links into the daemon
  470. // set them to nil on the hostconfig
  471. hostConfig.Links = nil
  472. if err := container.writeHostConfig(); err != nil {
  473. return err
  474. }
  475. return nil
  476. }
  477. func (daemon *Daemon) newBaseContainer(id string) Container {
  478. return Container{
  479. CommonContainer: CommonContainer{
  480. ID: id,
  481. State: NewState(),
  482. execCommands: newExecStore(),
  483. root: daemon.containerRoot(id),
  484. },
  485. MountPoints: make(map[string]*mountPoint),
  486. Volumes: make(map[string]string),
  487. VolumesRW: make(map[string]bool),
  488. }
  489. }