daemon_unix.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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. // memory subsystem checks and adjustments
  141. if hostConfig.Memory != 0 && hostConfig.Memory < 4194304 {
  142. return warnings, fmt.Errorf("Minimum memory limit allowed is 4MB")
  143. }
  144. if hostConfig.Memory > 0 && !sysInfo.MemoryLimit {
  145. warnings = append(warnings, "Your kernel does not support memory limit capabilities. Limitation discarded.")
  146. logrus.Warnf("Your kernel does not support memory limit capabilities. Limitation discarded.")
  147. hostConfig.Memory = 0
  148. hostConfig.MemorySwap = -1
  149. }
  150. if hostConfig.Memory > 0 && hostConfig.MemorySwap != -1 && !sysInfo.SwapLimit {
  151. warnings = append(warnings, "Your kernel does not support swap limit capabilities, memory limited without swap.")
  152. logrus.Warnf("Your kernel does not support swap limit capabilities, memory limited without swap.")
  153. hostConfig.MemorySwap = -1
  154. }
  155. if hostConfig.Memory > 0 && hostConfig.MemorySwap > 0 && hostConfig.MemorySwap < hostConfig.Memory {
  156. return warnings, fmt.Errorf("Minimum memoryswap limit should be larger than memory limit, see usage.")
  157. }
  158. if hostConfig.Memory == 0 && hostConfig.MemorySwap > 0 {
  159. return warnings, fmt.Errorf("You should always set the Memory limit when using Memoryswap limit, see usage.")
  160. }
  161. if hostConfig.MemorySwappiness != nil && *hostConfig.MemorySwappiness != -1 && !sysInfo.MemorySwappiness {
  162. warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, memory swappiness discarded.")
  163. logrus.Warnf("Your kernel does not support memory swappiness capabilities, memory swappiness discarded.")
  164. hostConfig.MemorySwappiness = nil
  165. }
  166. if hostConfig.MemorySwappiness != nil {
  167. swappiness := *hostConfig.MemorySwappiness
  168. if swappiness < -1 || swappiness > 100 {
  169. return warnings, fmt.Errorf("Invalid value: %v, valid memory swappiness range is 0-100.", swappiness)
  170. }
  171. }
  172. if hostConfig.CPUShares > 0 && !sysInfo.CPUShares {
  173. warnings = append(warnings, "Your kernel does not support CPU shares. Shares discarded.")
  174. logrus.Warnf("Your kernel does not support CPU shares. Shares discarded.")
  175. hostConfig.CPUShares = 0
  176. }
  177. if hostConfig.CPUPeriod > 0 && !sysInfo.CPUCfsPeriod {
  178. warnings = append(warnings, "Your kernel does not support CPU cfs period. Period discarded.")
  179. logrus.Warnf("Your kernel does not support CPU cfs period. Period discarded.")
  180. hostConfig.CPUPeriod = 0
  181. }
  182. if hostConfig.CPUQuota > 0 && !sysInfo.CPUCfsQuota {
  183. warnings = append(warnings, "Your kernel does not support CPU cfs quota. Quota discarded.")
  184. logrus.Warnf("Your kernel does not support CPU cfs quota. Quota discarded.")
  185. hostConfig.CPUQuota = 0
  186. }
  187. if (hostConfig.CpusetCpus != "" || hostConfig.CpusetMems != "") && !sysInfo.Cpuset {
  188. warnings = append(warnings, "Your kernel does not support cpuset. Cpuset discarded.")
  189. logrus.Warnf("Your kernel does not support cpuset. Cpuset discarded.")
  190. hostConfig.CpusetCpus = ""
  191. hostConfig.CpusetMems = ""
  192. }
  193. if hostConfig.BlkioWeight > 0 && !sysInfo.BlkioWeight {
  194. warnings = append(warnings, "Your kernel does not support Block I/O weight. Weight discarded.")
  195. logrus.Warnf("Your kernel does not support Block I/O weight. Weight discarded.")
  196. hostConfig.BlkioWeight = 0
  197. }
  198. if hostConfig.BlkioWeight > 0 && (hostConfig.BlkioWeight < 10 || hostConfig.BlkioWeight > 1000) {
  199. return warnings, fmt.Errorf("Range of blkio weight is from 10 to 1000.")
  200. }
  201. if hostConfig.OomKillDisable && !sysInfo.OomKillDisable {
  202. hostConfig.OomKillDisable = false
  203. return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
  204. }
  205. if sysInfo.IPv4ForwardingDisabled {
  206. warnings = append(warnings, "IPv4 forwarding is disabled. Networking will not work.")
  207. logrus.Warnf("IPv4 forwarding is disabled. Networking will not work")
  208. }
  209. return warnings, nil
  210. }
  211. // checkConfigOptions checks for mutually incompatible config options
  212. func checkConfigOptions(config *Config) error {
  213. // Check for mutually incompatible config options
  214. if config.Bridge.Iface != "" && config.Bridge.IP != "" {
  215. return fmt.Errorf("You specified -b & --bip, mutually exclusive options. Please specify only one.")
  216. }
  217. if !config.Bridge.EnableIPTables && !config.Bridge.InterContainerCommunication {
  218. return fmt.Errorf("You specified --iptables=false with --icc=false. ICC uses iptables to function. Please set --icc or --iptables to true.")
  219. }
  220. if !config.Bridge.EnableIPTables && config.Bridge.EnableIPMasq {
  221. config.Bridge.EnableIPMasq = false
  222. }
  223. return nil
  224. }
  225. // checkSystem validates platform-specific requirements
  226. func checkSystem() error {
  227. if os.Geteuid() != 0 {
  228. return fmt.Errorf("The Docker daemon needs to be run as root")
  229. }
  230. if err := checkKernel(); err != nil {
  231. return err
  232. }
  233. return nil
  234. }
  235. // configureKernelSecuritySupport configures and validate security support for the kernel
  236. func configureKernelSecuritySupport(config *Config, driverName string) error {
  237. if config.EnableSelinuxSupport {
  238. if selinuxEnabled() {
  239. // As Docker on btrfs and SELinux are incompatible at present, error on both being enabled
  240. if driverName == "btrfs" {
  241. return fmt.Errorf("SELinux is not supported with the BTRFS graph driver")
  242. }
  243. logrus.Debug("SELinux enabled successfully")
  244. } else {
  245. logrus.Warn("Docker could not enable SELinux on the host system")
  246. }
  247. } else {
  248. selinuxSetDisabled()
  249. }
  250. return nil
  251. }
  252. // MigrateIfDownlevel is a wrapper for AUFS migration for downlevel
  253. func migrateIfDownlevel(driver graphdriver.Driver, root string) error {
  254. return migrateIfAufs(driver, root)
  255. }
  256. func configureVolumes(config *Config) error {
  257. volumesDriver, err := local.New(config.Root)
  258. if err != nil {
  259. return err
  260. }
  261. volumedrivers.Register(volumesDriver, volumesDriver.Name())
  262. return nil
  263. }
  264. func configureSysInit(config *Config) (string, error) {
  265. localCopy := filepath.Join(config.Root, "init", fmt.Sprintf("dockerinit-%s", dockerversion.VERSION))
  266. sysInitPath := utils.DockerInitPath(localCopy)
  267. if sysInitPath == "" {
  268. 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.")
  269. }
  270. if sysInitPath != localCopy {
  271. // 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).
  272. if err := os.Mkdir(filepath.Dir(localCopy), 0700); err != nil && !os.IsExist(err) {
  273. return "", err
  274. }
  275. if _, err := fileutils.CopyFile(sysInitPath, localCopy); err != nil {
  276. return "", err
  277. }
  278. if err := os.Chmod(localCopy, 0700); err != nil {
  279. return "", err
  280. }
  281. sysInitPath = localCopy
  282. }
  283. return sysInitPath, nil
  284. }
  285. func isBridgeNetworkDisabled(config *Config) bool {
  286. return config.Bridge.Iface == disableNetworkBridge
  287. }
  288. func networkOptions(dconfig *Config) ([]nwconfig.Option, error) {
  289. options := []nwconfig.Option{}
  290. if dconfig == nil {
  291. return options, nil
  292. }
  293. if strings.TrimSpace(dconfig.DefaultNetwork) != "" {
  294. dn := strings.Split(dconfig.DefaultNetwork, ":")
  295. if len(dn) < 2 {
  296. return nil, fmt.Errorf("default network daemon config must be of the form NETWORKDRIVER:NETWORKNAME")
  297. }
  298. options = append(options, nwconfig.OptionDefaultDriver(dn[0]))
  299. options = append(options, nwconfig.OptionDefaultNetwork(strings.Join(dn[1:], ":")))
  300. } else {
  301. dd := runconfig.DefaultDaemonNetworkMode()
  302. dn := runconfig.DefaultDaemonNetworkMode().NetworkName()
  303. options = append(options, nwconfig.OptionDefaultDriver(string(dd)))
  304. options = append(options, nwconfig.OptionDefaultNetwork(dn))
  305. }
  306. if strings.TrimSpace(dconfig.NetworkKVStore) != "" {
  307. kv := strings.Split(dconfig.NetworkKVStore, ":")
  308. if len(kv) < 2 {
  309. return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER:KV-URL")
  310. }
  311. options = append(options, nwconfig.OptionKVProvider(kv[0]))
  312. options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], ":")))
  313. }
  314. options = append(options, nwconfig.OptionLabels(dconfig.Labels))
  315. return options, nil
  316. }
  317. func initNetworkController(config *Config) (libnetwork.NetworkController, error) {
  318. netOptions, err := networkOptions(config)
  319. if err != nil {
  320. return nil, err
  321. }
  322. controller, err := libnetwork.New(netOptions...)
  323. if err != nil {
  324. return nil, fmt.Errorf("error obtaining controller instance: %v", err)
  325. }
  326. // Initialize default driver "null"
  327. if err := controller.ConfigureNetworkDriver("null", options.Generic{}); err != nil {
  328. return nil, fmt.Errorf("Error initializing null driver: %v", err)
  329. }
  330. // Initialize default network on "null"
  331. if _, err := controller.NewNetwork("null", "none"); err != nil {
  332. return nil, fmt.Errorf("Error creating default \"null\" network: %v", err)
  333. }
  334. // Initialize default driver "host"
  335. if err := controller.ConfigureNetworkDriver("host", options.Generic{}); err != nil {
  336. return nil, fmt.Errorf("Error initializing host driver: %v", err)
  337. }
  338. // Initialize default network on "host"
  339. if _, err := controller.NewNetwork("host", "host"); err != nil {
  340. return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
  341. }
  342. if !config.DisableBridge {
  343. // Initialize default driver "bridge"
  344. if err := initBridgeDriver(controller, config); err != nil {
  345. return nil, err
  346. }
  347. }
  348. return controller, nil
  349. }
  350. func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
  351. option := options.Generic{
  352. "EnableIPForwarding": config.Bridge.EnableIPForward}
  353. if err := controller.ConfigureNetworkDriver("bridge", options.Generic{netlabel.GenericData: option}); err != nil {
  354. return fmt.Errorf("Error initializing bridge driver: %v", err)
  355. }
  356. netOption := options.Generic{
  357. "BridgeName": config.Bridge.Iface,
  358. "Mtu": config.Mtu,
  359. "EnableIPTables": config.Bridge.EnableIPTables,
  360. "EnableIPMasquerade": config.Bridge.EnableIPMasq,
  361. "EnableICC": config.Bridge.InterContainerCommunication,
  362. "EnableUserlandProxy": config.Bridge.EnableUserlandProxy,
  363. }
  364. if config.Bridge.IP != "" {
  365. ip, bipNet, err := net.ParseCIDR(config.Bridge.IP)
  366. if err != nil {
  367. return err
  368. }
  369. bipNet.IP = ip
  370. netOption["AddressIPv4"] = bipNet
  371. }
  372. if config.Bridge.FixedCIDR != "" {
  373. _, fCIDR, err := net.ParseCIDR(config.Bridge.FixedCIDR)
  374. if err != nil {
  375. return err
  376. }
  377. netOption["FixedCIDR"] = fCIDR
  378. }
  379. if config.Bridge.FixedCIDRv6 != "" {
  380. _, fCIDRv6, err := net.ParseCIDR(config.Bridge.FixedCIDRv6)
  381. if err != nil {
  382. return err
  383. }
  384. netOption["FixedCIDRv6"] = fCIDRv6
  385. }
  386. if config.Bridge.DefaultGatewayIPv4 != nil {
  387. netOption["DefaultGatewayIPv4"] = config.Bridge.DefaultGatewayIPv4
  388. }
  389. if config.Bridge.DefaultGatewayIPv6 != nil {
  390. netOption["DefaultGatewayIPv6"] = config.Bridge.DefaultGatewayIPv6
  391. }
  392. // --ip processing
  393. if config.Bridge.DefaultIP != nil {
  394. netOption["DefaultBindingIP"] = config.Bridge.DefaultIP
  395. }
  396. // Initialize default network on "bridge" with the same name
  397. _, err := controller.NewNetwork("bridge", "bridge",
  398. libnetwork.NetworkOptionGeneric(options.Generic{
  399. netlabel.GenericData: netOption,
  400. netlabel.EnableIPv6: config.Bridge.EnableIPv6,
  401. }))
  402. if err != nil {
  403. return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
  404. }
  405. return nil
  406. }
  407. // setupInitLayer populates a directory with mountpoints suitable
  408. // for bind-mounting dockerinit into the container. The mountpoint is simply an
  409. // empty file at /.dockerinit
  410. //
  411. // This extra layer is used by all containers as the top-most ro layer. It protects
  412. // the container from unwanted side-effects on the rw layer.
  413. func setupInitLayer(initLayer string) error {
  414. for pth, typ := range map[string]string{
  415. "/dev/pts": "dir",
  416. "/dev/shm": "dir",
  417. "/proc": "dir",
  418. "/sys": "dir",
  419. "/.dockerinit": "file",
  420. "/.dockerenv": "file",
  421. "/etc/resolv.conf": "file",
  422. "/etc/hosts": "file",
  423. "/etc/hostname": "file",
  424. "/dev/console": "file",
  425. "/etc/mtab": "/proc/mounts",
  426. } {
  427. parts := strings.Split(pth, "/")
  428. prev := "/"
  429. for _, p := range parts[1:] {
  430. prev = filepath.Join(prev, p)
  431. syscall.Unlink(filepath.Join(initLayer, prev))
  432. }
  433. if _, err := os.Stat(filepath.Join(initLayer, pth)); err != nil {
  434. if os.IsNotExist(err) {
  435. if err := system.MkdirAll(filepath.Join(initLayer, filepath.Dir(pth)), 0755); err != nil {
  436. return err
  437. }
  438. switch typ {
  439. case "dir":
  440. if err := system.MkdirAll(filepath.Join(initLayer, pth), 0755); err != nil {
  441. return err
  442. }
  443. case "file":
  444. f, err := os.OpenFile(filepath.Join(initLayer, pth), os.O_CREATE, 0755)
  445. if err != nil {
  446. return err
  447. }
  448. f.Close()
  449. default:
  450. if err := os.Symlink(typ, filepath.Join(initLayer, pth)); err != nil {
  451. return err
  452. }
  453. }
  454. } else {
  455. return err
  456. }
  457. }
  458. }
  459. // Layer is ready to use, if it wasn't before.
  460. return nil
  461. }
  462. func (daemon *Daemon) NetworkApiRouter() func(w http.ResponseWriter, req *http.Request) {
  463. return nwapi.NewHTTPHandler(daemon.netController)
  464. }
  465. func (daemon *Daemon) RegisterLinks(container *Container, hostConfig *runconfig.HostConfig) error {
  466. if hostConfig == nil || hostConfig.Links == nil {
  467. return nil
  468. }
  469. for _, l := range hostConfig.Links {
  470. name, alias, err := parsers.ParseLink(l)
  471. if err != nil {
  472. return err
  473. }
  474. child, err := daemon.Get(name)
  475. if err != nil {
  476. //An error from daemon.Get() means this name could not be found
  477. return fmt.Errorf("Could not get container for %s", name)
  478. }
  479. for child.hostConfig.NetworkMode.IsContainer() {
  480. parts := strings.SplitN(string(child.hostConfig.NetworkMode), ":", 2)
  481. child, err = daemon.Get(parts[1])
  482. if err != nil {
  483. return fmt.Errorf("Could not get container for %s", parts[1])
  484. }
  485. }
  486. if child.hostConfig.NetworkMode.IsHost() {
  487. return runconfig.ErrConflictHostNetworkAndLinks
  488. }
  489. if err := daemon.RegisterLink(container, child, alias); err != nil {
  490. return err
  491. }
  492. }
  493. // After we load all the links into the daemon
  494. // set them to nil on the hostconfig
  495. hostConfig.Links = nil
  496. if err := container.WriteHostConfig(); err != nil {
  497. return err
  498. }
  499. return nil
  500. }
  501. func (daemon *Daemon) newBaseContainer(id string) Container {
  502. return Container{
  503. CommonContainer: CommonContainer{
  504. ID: id,
  505. State: NewState(),
  506. execCommands: newExecStore(),
  507. root: daemon.containerRoot(id),
  508. },
  509. MountPoints: make(map[string]*mountPoint),
  510. Volumes: make(map[string]string),
  511. VolumesRW: make(map[string]bool),
  512. }
  513. }