1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

'docker run' can reference an image by REPOSITORY:TAG

This commit is contained in:
Solomon Hykes 2013-03-21 19:01:55 -07:00
parent d0c776528b
commit 379d449c44
2 changed files with 34 additions and 6 deletions

View file

@ -35,6 +35,7 @@ func (graph *Graph) Exists(id string) bool {
}
func (graph *Graph) Get(id string) (*Image, error) {
// FIXME: return nil when the image doesn't exist, instead of an error
img, err := LoadImage(graph.imageRoot(id))
if err != nil {
return nil, err

View file

@ -9,6 +9,7 @@ import (
"os"
"path"
"sort"
"strings"
"sync"
"time"
)
@ -62,15 +63,41 @@ func (runtime *Runtime) containerRoot(id string) string {
return path.Join(runtime.repository, id)
}
func (runtime *Runtime) LookupImage(name string) (*Image, error) {
img, err := runtime.graph.Get(name)
if err != nil {
// FIXME: standardize on returning nil when the image doesn't exist, and err for everything else
// (so we can pass all errors here)
repoAndTag := strings.SplitN(name, ":", 2)
if len(repoAndTag) == 1 {
repoAndTag = append(repoAndTag, "")
}
if i, err := runtime.repositories.GetImage(repoAndTag[0], repoAndTag[1]); err != nil {
return nil, err
} else if i == nil {
return nil, fmt.Errorf("No such image: %s", name)
} else {
img = i
}
}
return img, nil
}
func (runtime *Runtime) Create(command string, args []string, image string, config *Config) (*Container, error) {
// Lookup image
img, err := runtime.LookupImage(image)
if err != nil {
return nil, err
}
container := &Container{
// FIXME: we should generate the ID here instead of receiving it as an argument
Id: GenerateId(),
Created: time.Now(),
Path: command,
Args: args,
Config: config,
Image: image,
Id: GenerateId(),
Created: time.Now(),
Path: command,
Args: args,
Config: config,
Image: img.Id, // Always use the resolved image id
//FIXME: store the name under which the image was given, for reference
NetworkSettings: &NetworkSettings{},
// FIXME: do we need to store this in the container?
SysInitPath: sysInitPath,