mirror of https://github.com/docker/docs.git
Merge pull request #7443 from ewindisch/name-id-lookup-reversal
Container name lookups to prefer IDs over names
This commit is contained in:
commit
140e6abb17
|
@ -140,16 +140,13 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
|
||||||
// Get looks for a container by the specified ID or name, and returns it.
|
// Get looks for a container by the specified ID or name, and returns it.
|
||||||
// If the container is not found, or if an error occurs, nil is returned.
|
// If the container is not found, or if an error occurs, nil is returned.
|
||||||
func (daemon *Daemon) Get(name string) *Container {
|
func (daemon *Daemon) Get(name string) *Container {
|
||||||
|
if id, err := daemon.idIndex.Get(name); err == nil {
|
||||||
|
return daemon.containers.Get(id)
|
||||||
|
}
|
||||||
if c, _ := daemon.GetByName(name); c != nil {
|
if c, _ := daemon.GetByName(name); c != nil {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
id, err := daemon.idIndex.Get(name)
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return daemon.containers.Get(id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exists returns a true if a container of the specified ID or name exists,
|
// Exists returns a true if a container of the specified ID or name exists,
|
||||||
|
|
Loading…
Reference in New Issue