|
@@ -78,12 +78,58 @@ func (runtime *Runtime) containerRoot(id string) string {
|
|
return path.Join(runtime.repository, id)
|
|
return path.Join(runtime.repository, id)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (runtime *Runtime) mergeConfig(userConf, imageConf *Config) {
|
|
|
|
+ if userConf.Hostname != "" {
|
|
|
|
+ userConf.Hostname = imageConf.Hostname
|
|
|
|
+ }
|
|
|
|
+ if userConf.User != "" {
|
|
|
|
+ userConf.User = imageConf.User
|
|
|
|
+ }
|
|
|
|
+ if userConf.Memory == 0 {
|
|
|
|
+ userConf.Memory = imageConf.Memory
|
|
|
|
+ }
|
|
|
|
+ if userConf.MemorySwap == 0 {
|
|
|
|
+ userConf.MemorySwap = imageConf.MemorySwap
|
|
|
|
+ }
|
|
|
|
+ if userConf.PortSpecs == nil || len(userConf.PortSpecs) == 0 {
|
|
|
|
+ userConf.PortSpecs = imageConf.PortSpecs
|
|
|
|
+ }
|
|
|
|
+ if !userConf.Tty {
|
|
|
|
+ userConf.Tty = userConf.Tty
|
|
|
|
+ }
|
|
|
|
+ if !userConf.OpenStdin {
|
|
|
|
+ userConf.OpenStdin = imageConf.OpenStdin
|
|
|
|
+ }
|
|
|
|
+ if !userConf.StdinOnce {
|
|
|
|
+ userConf.StdinOnce = imageConf.StdinOnce
|
|
|
|
+ }
|
|
|
|
+ if userConf.Env == nil || len(userConf.Env) == 0 {
|
|
|
|
+ userConf.Env = imageConf.Env
|
|
|
|
+ }
|
|
|
|
+ if userConf.Cmd == nil || len(userConf.Cmd) == 0 {
|
|
|
|
+ userConf.Cmd = imageConf.Cmd
|
|
|
|
+ }
|
|
|
|
+ if userConf.Dns == nil || len(userConf.Dns) == 0 {
|
|
|
|
+ userConf.Dns = imageConf.Dns
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
func (runtime *Runtime) Create(config *Config) (*Container, error) {
|
|
func (runtime *Runtime) Create(config *Config) (*Container, error) {
|
|
|
|
+
|
|
// Lookup image
|
|
// Lookup image
|
|
img, err := runtime.repositories.LookupImage(config.Image)
|
|
img, err := runtime.repositories.LookupImage(config.Image)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if img.Config != nil {
|
|
|
|
+ runtime.mergeConfig(config, img.Config)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if config.Cmd == nil {
|
|
|
|
+ return nil, fmt.Errorf("No command specified")
|
|
|
|
+ }
|
|
|
|
+
|
|
// Generate id
|
|
// Generate id
|
|
id := GenerateId()
|
|
id := GenerateId()
|
|
// Generate default hostname
|
|
// Generate default hostname
|
|
@@ -104,6 +150,7 @@ func (runtime *Runtime) Create(config *Config) (*Container, error) {
|
|
// FIXME: do we need to store this in the container?
|
|
// FIXME: do we need to store this in the container?
|
|
SysInitPath: sysInitPath,
|
|
SysInitPath: sysInitPath,
|
|
}
|
|
}
|
|
|
|
+
|
|
container.root = runtime.containerRoot(container.Id)
|
|
container.root = runtime.containerRoot(container.Id)
|
|
// Step 1: create the container directory.
|
|
// Step 1: create the container directory.
|
|
// This doubles as a barrier to avoid race conditions.
|
|
// This doubles as a barrier to avoid race conditions.
|
|
@@ -265,7 +312,7 @@ func (runtime *Runtime) Destroy(container *Container) error {
|
|
|
|
|
|
// Commit creates a new filesystem image from the current state of a container.
|
|
// Commit creates a new filesystem image from the current state of a container.
|
|
// The image can optionally be tagged into a repository
|
|
// The image can optionally be tagged into a repository
|
|
-func (runtime *Runtime) Commit(id, repository, tag, comment, author string) (*Image, error) {
|
|
|
|
|
|
+func (runtime *Runtime) Commit(id, repository, tag, comment, author string, config *Config) (*Image, error) {
|
|
container := runtime.Get(id)
|
|
container := runtime.Get(id)
|
|
if container == nil {
|
|
if container == nil {
|
|
return nil, fmt.Errorf("No such container: %s", id)
|
|
return nil, fmt.Errorf("No such container: %s", id)
|
|
@@ -277,7 +324,7 @@ func (runtime *Runtime) Commit(id, repository, tag, comment, author string) (*Im
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
// Create a new image from the container's base layers + a new layer from container changes
|
|
// Create a new image from the container's base layers + a new layer from container changes
|
|
- img, err := runtime.graph.Create(rwTar, container, comment, author)
|
|
|
|
|
|
+ img, err := runtime.graph.Create(rwTar, container, comment, author, config)
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|