Windows: Support embedded utility VM images

For TP5, the utility VM for Hyper-V containers is embedded in the base
layer's contents.

Signed-off-by: John Starks <jostarks@microsoft.com>
This commit is contained in:
John Starks 2016-04-06 17:08:24 -07:00
parent 15b0f06a9a
commit c70f153f52
2 changed files with 44 additions and 23 deletions

View file

@ -1,7 +1,10 @@
package daemon package daemon
import ( import (
"errors"
"fmt" "fmt"
"os"
"path/filepath"
"syscall" "syscall"
"github.com/docker/docker/container" "github.com/docker/docker/container"
@ -47,21 +50,6 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
}) })
} }
// Are we going to run as a Hyper-V container?
hv := false
if c.HostConfig.Isolation.IsDefault() {
// Container is set to use the default, so take the default from the daemon configuration
hv = daemon.defaultIsolation.IsHyperV()
} else {
// Container is requesting an isolation mode. Honour it.
hv = c.HostConfig.Isolation.IsHyperV()
}
if hv {
// TODO We don't yet have the ImagePath hooked up. But set to
// something non-nil to pickup in libcontainerd.
s.Windows.HvRuntime = &windowsoci.HvRuntime{}
}
// In s.Process // In s.Process
s.Process.Args = append([]string{c.Path}, c.Args...) s.Process.Args = append([]string{c.Path}, c.Args...)
if !c.Config.ArgsEscaped { if !c.Config.ArgsEscaped {
@ -109,6 +97,36 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
} }
s.Windows.LayerPaths = layerPaths s.Windows.LayerPaths = layerPaths
// Are we going to run as a Hyper-V container?
hv := false
if c.HostConfig.Isolation.IsDefault() {
// Container is set to use the default, so take the default from the daemon configuration
hv = daemon.defaultIsolation.IsHyperV()
} else {
// Container is requesting an isolation mode. Honour it.
hv = c.HostConfig.Isolation.IsHyperV()
}
if hv {
hvr := &windowsoci.HvRuntime{}
if img.RootFS != nil && img.RootFS.Type == image.TypeLayers {
// For TP5, the utility VM is part of the base layer.
// TODO-jstarks: Add support for separate utility VM images
// once it is decided how they can be stored.
uvmpath := filepath.Join(layerPaths[len(layerPaths)-1], "UtilityVM")
_, err = os.Stat(uvmpath)
if err != nil {
if os.IsNotExist(err) {
err = errors.New("container image does not contain a utility VM")
}
return nil, err
}
hvr.ImagePath = uvmpath
}
s.Windows.HvRuntime = hvr
}
// In s.Windows.Networking // In s.Windows.Networking
// Connect all the libnetwork allocated networks to the container // Connect all the libnetwork allocated networks to the container
var epList []string var epList []string

View file

@ -69,6 +69,10 @@ type mappedDir struct {
ReadOnly bool ReadOnly bool
} }
type hvRuntime struct {
ImagePath string `json:",omitempty"`
}
// TODO Windows: @darrenstahlmsft Add ProcessorCount // TODO Windows: @darrenstahlmsft Add ProcessorCount
type containerInit struct { type containerInit struct {
SystemType string // HCS requires this to be hard-coded to "Container" SystemType string // HCS requires this to be hard-coded to "Container"
@ -91,6 +95,7 @@ type containerInit struct {
SandboxPath string // Location of unmounted sandbox (used for Hyper-V containers) SandboxPath string // Location of unmounted sandbox (used for Hyper-V containers)
HvPartition bool // True if it a Hyper-V Container HvPartition bool // True if it a Hyper-V Container
EndpointList []string // List of networking endpoints to be attached to container EndpointList []string // List of networking endpoints to be attached to container
HvRuntime *hvRuntime // Hyper-V container settings
} }
// defaultOwner is a tag passed to HCS to allow it to differentiate between // defaultOwner is a tag passed to HCS to allow it to differentiate between
@ -145,14 +150,12 @@ func (clnt *client) Create(containerID string, spec Spec, options ...CreateOptio
} }
} }
cu.HvPartition = (spec.Windows.HvRuntime != nil) if spec.Windows.HvRuntime != nil {
cu.HvPartition = true
// TODO Windows @jhowardmsft. FIXME post TP5. cu.HvRuntime = &hvRuntime{
// if spec.Windows.HvRuntime != nil { ImagePath: spec.Windows.HvRuntime.ImagePath,
// if spec.WIndows.HVRuntime.ImagePath != "" { }
// cu.TBD = spec.Windows.HvRuntime.ImagePath }
// }
// }
if cu.HvPartition { if cu.HvPartition {
cu.SandboxPath = filepath.Dir(spec.Windows.LayerFolder) cu.SandboxPath = filepath.Dir(spec.Windows.LayerFolder)