@@ -78,12 +78,58 @@ func (runtime *Runtime) containerRoot(id string) string {
7878 return path .Join (runtime .repository , id )
7979}
8080
81+ func (runtime * Runtime ) mergeConfig (userConf , imageConf * Config ) {
82+ if userConf .Hostname != "" {
83+ userConf .Hostname = imageConf .Hostname
84+ }
85+ if userConf .User != "" {
86+ userConf .User = imageConf .User
87+ }
88+ if userConf .Memory == 0 {
89+ userConf .Memory = imageConf .Memory
90+ }
91+ if userConf .MemorySwap == 0 {
92+ userConf .MemorySwap = imageConf .MemorySwap
93+ }
94+ if userConf .PortSpecs == nil || len (userConf .PortSpecs ) == 0 {
95+ userConf .PortSpecs = imageConf .PortSpecs
96+ }
97+ if ! userConf .Tty {
98+ userConf .Tty = userConf .Tty
99+ }
100+ if ! userConf .OpenStdin {
101+ userConf .OpenStdin = imageConf .OpenStdin
102+ }
103+ if ! userConf .StdinOnce {
104+ userConf .StdinOnce = imageConf .StdinOnce
105+ }
106+ if userConf .Env == nil || len (userConf .Env ) == 0 {
107+ userConf .Env = imageConf .Env
108+ }
109+ if userConf .Cmd == nil || len (userConf .Cmd ) == 0 {
110+ userConf .Cmd = imageConf .Cmd
111+ }
112+ if userConf .Dns == nil || len (userConf .Dns ) == 0 {
113+ userConf .Dns = imageConf .Dns
114+ }
115+ }
116+
81117func (runtime * Runtime ) Create (config * Config ) (* Container , error ) {
118+
82119 // Lookup image
83120 img , err := runtime .repositories .LookupImage (config .Image )
84121 if err != nil {
85122 return nil , err
86123 }
124+
125+ if img .Config != nil {
126+ runtime .mergeConfig (config , img .Config )
127+ }
128+
129+ if config .Cmd == nil {
130+ return nil , fmt .Errorf ("No command specified" )
131+ }
132+
87133 // Generate id
88134 id := GenerateId ()
89135 // Generate default hostname
@@ -104,6 +150,7 @@ func (runtime *Runtime) Create(config *Config) (*Container, error) {
104150 // FIXME: do we need to store this in the container?
105151 SysInitPath : sysInitPath ,
106152 }
153+
107154 container .root = runtime .containerRoot (container .Id )
108155 // Step 1: create the container directory.
109156 // This doubles as a barrier to avoid race conditions.
@@ -265,7 +312,7 @@ func (runtime *Runtime) Destroy(container *Container) error {
265312
266313// Commit creates a new filesystem image from the current state of a container.
267314// The image can optionally be tagged into a repository
268- func (runtime * Runtime ) Commit (id , repository , tag , comment , author string ) (* Image , error ) {
315+ func (runtime * Runtime ) Commit (id , repository , tag , comment , author string , config * Config ) (* Image , error ) {
269316 container := runtime .Get (id )
270317 if container == nil {
271318 return nil , fmt .Errorf ("No such container: %s" , id )
@@ -277,7 +324,7 @@ func (runtime *Runtime) Commit(id, repository, tag, comment, author string) (*Im
277324 return nil , err
278325 }
279326 // Create a new image from the container's base layers + a new layer from container changes
280- img , err := runtime .graph .Create (rwTar , container , comment , author )
327+ img , err := runtime .graph .Create (rwTar , container , comment , author , config )
281328 if err != nil {
282329 return nil , err
283330 }
0 commit comments