diff --git a/daemon/create.go b/daemon/create.go index d4aeb77c7b..a190ab4e3d 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -187,23 +187,6 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr ctr.HostConfig.StorageOpt = opts.params.HostConfig.StorageOpt - // Fixes: https://github.com/moby/moby/issues/34074 and - // https://github.com/docker/for-win/issues/999. - // Merge the daemon's storage options if they aren't already present. We only - // do this on Windows as there's no effective sandbox size limit other than - // physical on Linux. - if isWindows { - if ctr.HostConfig.StorageOpt == nil { - ctr.HostConfig.StorageOpt = make(map[string]string) - } - for _, v := range daemon.configStore.GraphOptions { - opt := strings.SplitN(v, "=", 2) - if _, ok := ctr.HostConfig.StorageOpt[opt[0]]; !ok { - ctr.HostConfig.StorageOpt[opt[0]] = opt[1] - } - } - } - // Set RWLayer for container after mount labels have been set rwLayer, err := daemon.imageService.CreateLayer(ctr, setupInitLayer(daemon.idMapping)) if err != nil { diff --git a/daemon/graphdriver/lcow/lcow.go b/daemon/graphdriver/lcow/lcow.go index 1bf48fed2a..f7af11ed26 100644 --- a/daemon/graphdriver/lcow/lcow.go +++ b/daemon/graphdriver/lcow/lcow.go @@ -124,6 +124,7 @@ type Driver struct { cachedScratchMutex sync.Mutex // Protects race conditions from multiple threads creating the cached scratch. options []string // Graphdriver options we are initialised with. globalMode bool // Indicates if running in an unsafe/global service VM mode. + defaultSandboxSize uint64 // The default sandbox size to use if one is not specified // NOTE: It is OK to use a cache here because Windows does not support // restoring containers when the daemon dies. @@ -163,7 +164,8 @@ func InitDriver(dataRoot string, options []string, _, _ []idtools.IDMap) (graphd serviceVms: &serviceVMMap{ svms: make(map[string]*serviceVMMapItem), }, - globalMode: false, + globalMode: false, + defaultSandboxSize: client.DefaultVhdxSizeGB, } // Looks for relevant options @@ -178,6 +180,16 @@ func InitDriver(dataRoot string, options []string, _, _ []idtools.IDMap) (graphd return nil, fmt.Errorf("%s failed to parse value for 'lcow.globalmode' - must be 'true' or 'false'", title) } break + case "lcow.sandboxsize": + var err error + d.defaultSandboxSize, err = strconv.ParseUint(opt[1], 10, 32) + if err != nil { + return nil, fmt.Errorf("%s failed to parse value '%s' for 'lcow.sandboxsize'", title, v) + } + if d.defaultSandboxSize < client.DefaultVhdxSizeGB { + return nil, fmt.Errorf("%s 'lcow.sandboxsize' option cannot be less than %d", title, client.DefaultVhdxSizeGB) + } + break } } } @@ -517,7 +529,7 @@ func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts } // Look for an explicit sandbox size option. - sandboxSize := uint64(client.DefaultVhdxSizeGB) + sandboxSize := d.defaultSandboxSize for k, v := range opts.StorageOpt { switch strings.ToLower(k) { case "lcow.sandboxsize": diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index 5213dda6f0..04a027f69b 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -112,9 +112,17 @@ func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) return nil, fmt.Errorf("windowsfilter failed to create '%s': %v", home, err) } - size, err := units.RAMInBytes(defaultSandboxSize) + storageOpt := make(map[string]string) + storageOpt["size"] = defaultSandboxSize + + for _, v := range options { + opt := strings.SplitN(v, "=", 2) + storageOpt[strings.ToLower(opt[0])] = opt[1] + } + + storageOptions, err := parseStorageOpt(storageOpt) if err != nil { - return nil, fmt.Errorf("windowsfilter failed to parse default size '%s': %v", defaultSandboxSize, err) + return nil, fmt.Errorf("windowsfilter failed to parse default storage options - %s", err) } d := &Driver{ @@ -122,11 +130,9 @@ func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap) HomeDir: home, Flavour: filterDriver, }, - cache: make(map[string]string), - ctr: graphdriver.NewRefCounter(&checker{}), - defaultStorageOpts: &storageOptions{ - size: uint64(size), - }, + cache: make(map[string]string), + ctr: graphdriver.NewRefCounter(&checker{}), + defaultStorageOpts: storageOptions, } return d, nil }