daemon_unix.go 19 KB

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