daemon_unix.go 19 KB

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