|
@@ -31,6 +31,7 @@ import (
|
|
|
"github.com/docker/docker/errdefs"
|
|
|
"github.com/sirupsen/logrus"
|
|
|
// register graph drivers
|
|
|
+ "github.com/docker/docker/builder"
|
|
|
_ "github.com/docker/docker/daemon/graphdriver/register"
|
|
|
"github.com/docker/docker/daemon/stats"
|
|
|
dmetadata "github.com/docker/docker/distribution/metadata"
|
|
@@ -57,7 +58,6 @@ import (
|
|
|
"github.com/docker/libnetwork"
|
|
|
"github.com/docker/libnetwork/cluster"
|
|
|
nwconfig "github.com/docker/libnetwork/config"
|
|
|
- "github.com/docker/libtrust"
|
|
|
"github.com/pkg/errors"
|
|
|
)
|
|
|
|
|
@@ -70,44 +70,40 @@ var (
|
|
|
|
|
|
// Daemon holds information about the Docker daemon.
|
|
|
type Daemon struct {
|
|
|
- ID string
|
|
|
- repository string
|
|
|
- containers container.Store
|
|
|
- containersReplica container.ViewDB
|
|
|
- execCommands *exec.Store
|
|
|
- downloadManager *xfer.LayerDownloadManager
|
|
|
- uploadManager *xfer.LayerUploadManager
|
|
|
- trustKey libtrust.PrivateKey
|
|
|
- idIndex *truncindex.TruncIndex
|
|
|
- configStore *config.Config
|
|
|
- statsCollector *stats.Collector
|
|
|
- defaultLogConfig containertypes.LogConfig
|
|
|
- RegistryService registry.Service
|
|
|
- EventsService *events.Events
|
|
|
- netController libnetwork.NetworkController
|
|
|
- volumes *store.VolumeStore
|
|
|
- discoveryWatcher discovery.Reloader
|
|
|
- root string
|
|
|
- seccompEnabled bool
|
|
|
- apparmorEnabled bool
|
|
|
- shutdown bool
|
|
|
- idMappings *idtools.IDMappings
|
|
|
- graphDrivers map[string]string // By operating system
|
|
|
- referenceStore refstore.Store
|
|
|
- imageStore image.Store
|
|
|
- imageRoot string
|
|
|
- layerStores map[string]layer.Store // By operating system
|
|
|
- distributionMetadataStore dmetadata.Store
|
|
|
- PluginStore *plugin.Store // todo: remove
|
|
|
- pluginManager *plugin.Manager
|
|
|
- linkIndex *linkIndex
|
|
|
- containerd libcontainerd.Client
|
|
|
- containerdRemote libcontainerd.Remote
|
|
|
- defaultIsolation containertypes.Isolation // Default isolation mode on Windows
|
|
|
- clusterProvider cluster.Provider
|
|
|
- cluster Cluster
|
|
|
- genericResources []swarm.GenericResource
|
|
|
- metricsPluginListener net.Listener
|
|
|
+ ID string
|
|
|
+ repository string
|
|
|
+ containers container.Store
|
|
|
+ containersReplica container.ViewDB
|
|
|
+ execCommands *exec.Store
|
|
|
+
|
|
|
+ imageService *imageService
|
|
|
+
|
|
|
+ idIndex *truncindex.TruncIndex
|
|
|
+ configStore *config.Config
|
|
|
+ statsCollector *stats.Collector
|
|
|
+ defaultLogConfig containertypes.LogConfig
|
|
|
+ RegistryService registry.Service
|
|
|
+ EventsService *events.Events
|
|
|
+ netController libnetwork.NetworkController
|
|
|
+ volumes *store.VolumeStore
|
|
|
+ discoveryWatcher discovery.Reloader
|
|
|
+ root string
|
|
|
+ seccompEnabled bool
|
|
|
+ apparmorEnabled bool
|
|
|
+ shutdown bool
|
|
|
+ idMappings *idtools.IDMappings
|
|
|
+ // TODO: move graphDrivers field to an InfoService
|
|
|
+ graphDrivers map[string]string // By operating system
|
|
|
+
|
|
|
+ PluginStore *plugin.Store // todo: remove
|
|
|
+ pluginManager *plugin.Manager
|
|
|
+ linkIndex *linkIndex
|
|
|
+ containerd libcontainerd.Client
|
|
|
+ defaultIsolation containertypes.Isolation // Default isolation mode on Windows
|
|
|
+ clusterProvider cluster.Provider
|
|
|
+ cluster Cluster
|
|
|
+ genericResources []swarm.GenericResource
|
|
|
+ metricsPluginListener net.Listener
|
|
|
|
|
|
machineMemory uint64
|
|
|
|
|
@@ -162,7 +158,7 @@ func (daemon *Daemon) restore() error {
|
|
|
// Ignore the container if it does not support the current driver being used by the graph
|
|
|
currentDriverForContainerOS := daemon.graphDrivers[container.OS]
|
|
|
if (container.Driver == "" && currentDriverForContainerOS == "aufs") || container.Driver == currentDriverForContainerOS {
|
|
|
- rwlayer, err := daemon.layerStores[container.OS].GetRWLayer(container.ID)
|
|
|
+ rwlayer, err := daemon.imageService.GetRWLayerByID(container.ID, container.OS)
|
|
|
if err != nil {
|
|
|
logrus.Errorf("Failed to load container mount %v: %v", id, err)
|
|
|
continue
|
|
@@ -705,7 +701,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
// be set through an environment variable, a daemon start parameter, or chosen through
|
|
|
// initialization of the layerstore through driver priority order for example.
|
|
|
d.graphDrivers = make(map[string]string)
|
|
|
- d.layerStores = make(map[string]layer.Store)
|
|
|
+ layerStores := make(map[string]layer.Store)
|
|
|
if runtime.GOOS == "windows" {
|
|
|
d.graphDrivers[runtime.GOOS] = "windowsfilter"
|
|
|
if system.LCOWSupported() {
|
|
@@ -754,7 +750,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
}
|
|
|
|
|
|
for operatingSystem, gd := range d.graphDrivers {
|
|
|
- d.layerStores[operatingSystem], err = layer.NewStoreFromOptions(layer.StoreOptions{
|
|
|
+ layerStores[operatingSystem], err = layer.NewStoreFromOptions(layer.StoreOptions{
|
|
|
Root: config.Root,
|
|
|
MetadataStorePathTemplate: filepath.Join(config.Root, "image", "%s", "layerdb"),
|
|
|
GraphDriver: gd,
|
|
@@ -771,7 +767,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
|
|
|
// As layerstore initialization may set the driver
|
|
|
for os := range d.graphDrivers {
|
|
|
- d.graphDrivers[os] = d.layerStores[os].DriverName()
|
|
|
+ d.graphDrivers[os] = layerStores[os].DriverName()
|
|
|
}
|
|
|
|
|
|
// Configure and validate the kernels security support. Note this is a Linux/FreeBSD
|
|
@@ -780,22 +776,17 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- logrus.Debugf("Max Concurrent Downloads: %d", *config.MaxConcurrentDownloads)
|
|
|
- d.downloadManager = xfer.NewLayerDownloadManager(d.layerStores, *config.MaxConcurrentDownloads)
|
|
|
- logrus.Debugf("Max Concurrent Uploads: %d", *config.MaxConcurrentUploads)
|
|
|
- d.uploadManager = xfer.NewLayerUploadManager(*config.MaxConcurrentUploads)
|
|
|
-
|
|
|
- d.imageRoot = filepath.Join(config.Root, "image", d.graphDrivers[runtime.GOOS])
|
|
|
- ifs, err := image.NewFSStoreBackend(filepath.Join(d.imageRoot, "imagedb"))
|
|
|
+ imageRoot := filepath.Join(config.Root, "image", d.graphDrivers[runtime.GOOS])
|
|
|
+ ifs, err := image.NewFSStoreBackend(filepath.Join(imageRoot, "imagedb"))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
lgrMap := make(map[string]image.LayerGetReleaser)
|
|
|
- for os, ls := range d.layerStores {
|
|
|
+ for os, ls := range layerStores {
|
|
|
lgrMap[os] = ls
|
|
|
}
|
|
|
- d.imageStore, err = image.NewImageStore(ifs, lgrMap)
|
|
|
+ imageStore, err := image.NewImageStore(ifs, lgrMap)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -829,14 +820,13 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
// operating systems, the list of graphdrivers available isn't user configurable.
|
|
|
// For backwards compatibility, we just put it under the windowsfilter
|
|
|
// directory regardless.
|
|
|
- refStoreLocation := filepath.Join(d.imageRoot, `repositories.json`)
|
|
|
+ refStoreLocation := filepath.Join(imageRoot, `repositories.json`)
|
|
|
rs, err := refstore.NewReferenceStore(refStoreLocation)
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("Couldn't create reference store repository: %s", err)
|
|
|
}
|
|
|
- d.referenceStore = rs
|
|
|
|
|
|
- d.distributionMetadataStore, err = dmetadata.NewFSMetadataStore(filepath.Join(d.imageRoot, "distribution"))
|
|
|
+ distributionMetadataStore, err := dmetadata.NewFSMetadataStore(filepath.Join(imageRoot, "distribution"))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
@@ -844,7 +834,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
// No content-addressability migration on Windows as it never supported pre-CA
|
|
|
if runtime.GOOS != "windows" {
|
|
|
migrationStart := time.Now()
|
|
|
- if err := v1.Migrate(config.Root, d.graphDrivers[runtime.GOOS], d.layerStores[runtime.GOOS], d.imageStore, rs, d.distributionMetadataStore); err != nil {
|
|
|
+ if err := v1.Migrate(config.Root, d.graphDrivers[runtime.GOOS], layerStores[runtime.GOOS], imageStore, rs, distributionMetadataStore); err != nil {
|
|
|
logrus.Errorf("Graph migration failed: %q. Your old graph data was found to be too inconsistent for upgrading to content-addressable storage. Some of the old data was probably not upgraded. We recommend starting over with a clean storage directory if possible.", err)
|
|
|
}
|
|
|
logrus.Infof("Graph migration to content-addressability took %.2f seconds", time.Since(migrationStart).Seconds())
|
|
@@ -870,7 +860,6 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
return nil, err
|
|
|
}
|
|
|
d.execCommands = exec.NewStore()
|
|
|
- d.trustKey = trustKey
|
|
|
d.idIndex = truncindex.NewTruncIndex([]string{})
|
|
|
d.statsCollector = d.newStatsCollector(1 * time.Second)
|
|
|
|
|
@@ -880,10 +869,23 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
|
|
|
d.idMappings = idMappings
|
|
|
d.seccompEnabled = sysInfo.Seccomp
|
|
|
d.apparmorEnabled = sysInfo.AppArmor
|
|
|
- d.containerdRemote = containerdRemote
|
|
|
|
|
|
d.linkIndex = newLinkIndex()
|
|
|
|
|
|
+ logrus.Debugf("Max Concurrent Downloads: %d", *config.MaxConcurrentDownloads)
|
|
|
+ logrus.Debugf("Max Concurrent Uploads: %d", *config.MaxConcurrentUploads)
|
|
|
+ d.imageService = &imageService{
|
|
|
+ trustKey: trustKey,
|
|
|
+ uploadManager: xfer.NewLayerUploadManager(*config.MaxConcurrentUploads),
|
|
|
+ downloadManager: xfer.NewLayerDownloadManager(layerStores, *config.MaxConcurrentDownloads),
|
|
|
+ registryService: registryService,
|
|
|
+ referenceStore: rs,
|
|
|
+ distributionMetadataStore: distributionMetadataStore,
|
|
|
+ imageStore: imageStore,
|
|
|
+ eventsService: eventsService,
|
|
|
+ containers: d.containers,
|
|
|
+ }
|
|
|
+
|
|
|
go d.execCommandGC()
|
|
|
|
|
|
d.containerd, err = containerdRemote.NewClient(ContainersNamespace, d)
|
|
@@ -1005,7 +1007,7 @@ func (daemon *Daemon) Shutdown() error {
|
|
|
logrus.Errorf("Stop container error: %v", err)
|
|
|
return
|
|
|
}
|
|
|
- if mountid, err := daemon.layerStores[c.OS].GetMountID(c.ID); err == nil {
|
|
|
+ if mountid, err := daemon.imageService.GetContainerMountID(c.ID, c.OS); err == nil {
|
|
|
daemon.cleanupMountsByID(mountid)
|
|
|
}
|
|
|
logrus.Debugf("container stopped %s", c.ID)
|
|
@@ -1018,13 +1020,7 @@ func (daemon *Daemon) Shutdown() error {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for os, ls := range daemon.layerStores {
|
|
|
- if ls != nil {
|
|
|
- if err := ls.Cleanup(); err != nil {
|
|
|
- logrus.Errorf("Error during layer Store.Cleanup(): %v %s", err, os)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ daemon.imageService.Cleanup()
|
|
|
|
|
|
// If we are part of a cluster, clean up cluster's stuff
|
|
|
if daemon.clusterProvider != nil {
|
|
@@ -1064,7 +1060,7 @@ func (daemon *Daemon) Mount(container *container.Container) error {
|
|
|
if runtime.GOOS != "windows" {
|
|
|
daemon.Unmount(container)
|
|
|
return fmt.Errorf("Error: driver %s is returning inconsistent paths for container %s ('%s' then '%s')",
|
|
|
- daemon.GraphDriverName(container.OS), container.ID, container.BaseFS, dir)
|
|
|
+ daemon.imageService.GraphDriverForOS(container.OS), container.ID, container.BaseFS, dir)
|
|
|
}
|
|
|
}
|
|
|
container.BaseFS = dir // TODO: combine these fields
|
|
@@ -1108,11 +1104,6 @@ func (daemon *Daemon) Subnets() ([]net.IPNet, []net.IPNet) {
|
|
|
return v4Subnets, v6Subnets
|
|
|
}
|
|
|
|
|
|
-// GraphDriverName returns the name of the graph driver used by the layer.Store
|
|
|
-func (daemon *Daemon) GraphDriverName(os string) string {
|
|
|
- return daemon.layerStores[os].DriverName()
|
|
|
-}
|
|
|
-
|
|
|
// prepareTempDir prepares and returns the default directory to use
|
|
|
// for temporary files.
|
|
|
// If it doesn't exist, it is created. If it exists, its content is removed.
|
|
@@ -1323,3 +1314,20 @@ func fixMemorySwappiness(resources *containertypes.Resources) {
|
|
|
func (daemon *Daemon) GetAttachmentStore() *network.AttachmentStore {
|
|
|
return &daemon.attachmentStore
|
|
|
}
|
|
|
+
|
|
|
+// IDMappings returns uid/gid mappings for the builder
|
|
|
+func (daemon *Daemon) IDMappings() *idtools.IDMappings {
|
|
|
+ return daemon.idMappings
|
|
|
+}
|
|
|
+
|
|
|
+func (daemon *Daemon) ImageService() *imageService {
|
|
|
+ return daemon.imageService
|
|
|
+}
|
|
|
+
|
|
|
+// TODO: tmp hack to merge interfaces
|
|
|
+func (daemon *Daemon) BuilderBackend() builder.Backend {
|
|
|
+ return struct {
|
|
|
+ *Daemon
|
|
|
+ *imageService
|
|
|
+ }{daemon, daemon.imageService}
|
|
|
+}
|