Merge pull request #11281 from coolljt0725/fix_ipc_from_non_exist_container

Fix error from daemon no such image even when the image exist
This commit is contained in:
Phil Estes 2015-03-28 06:58:48 -04:00
commit 61069d8b69
6 changed files with 18 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import (
"io"
"net/url"
"os"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/graph"
@ -94,7 +95,7 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
//create the container
stream, statusCode, err := cli.call("POST", "/containers/create?"+containerValues.Encode(), mergedConfig, nil)
//if image not found try to pull it
if statusCode == 404 {
if statusCode == 404 && strings.Contains(err.Error(), config.Image) {
repo, tag := parsers.ParseRepositoryTag(config.Image)
if tag == "" {
tag = graph.DEFAULTTAG

View File

@ -166,7 +166,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
}
}
if err != nil {
if b.Daemon.Graph().IsNotExist(err) {
if b.Daemon.Graph().IsNotExist(err, name) {
image, err = b.pullImage(name)
}

View File

@ -46,7 +46,7 @@ func (daemon *Daemon) ContainerCreate(job *engine.Job) error {
container, buildWarnings, err := daemon.Create(config, hostConfig, name)
if err != nil {
if daemon.Graph().IsNotExist(err) {
if daemon.Graph().IsNotExist(err, config.Image) {
_, tag := parsers.ParseRepositoryTag(config.Image)
if tag == "" {
tag = graph.DEFAULTTAG

View File

@ -138,7 +138,7 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
for _, container := range daemon.List() {
parent, err := daemon.Repositories().LookupImage(container.ImageID)
if err != nil {
if daemon.Graph().IsNotExist(err) {
if daemon.Graph().IsNotExist(err, container.ImageID) {
return nil
}
return err

View File

@ -74,8 +74,8 @@ func (graph *Graph) restore() error {
// FIXME: Implement error subclass instead of looking at the error text
// Note: This is the way golang implements os.IsNotExists on Plan9
func (graph *Graph) IsNotExist(err error) bool {
return err != nil && (strings.Contains(strings.ToLower(err.Error()), "does not exist") || strings.Contains(strings.ToLower(err.Error()), "no such"))
func (graph *Graph) IsNotExist(err error, id string) bool {
return err != nil && (strings.Contains(strings.ToLower(err.Error()), "does not exist") || strings.Contains(strings.ToLower(err.Error()), "no such")) && strings.Contains(err.Error(), id)
}
// Exists returns true if an image is registered at the given id.

View File

@ -2990,6 +2990,17 @@ func TestRunModeIpcContainer(t *testing.T) {
logDone("run - ipc container mode")
}
func TestRunModeIpcContainerNotExists(t *testing.T) {
defer deleteAllContainers()
cmd := exec.Command(dockerBinary, "run", "-d", "--ipc", "container:abcd1234", "busybox", "top")
out, _, err := runCommandWithOutput(cmd)
if !strings.Contains(out, "abcd1234") || err == nil {
t.Fatalf("run IPC from a non exists container should with correct error out")
}
logDone("run - ipc from a non exists container failed with correct error out")
}
func TestContainerNetworkMode(t *testing.T) {
defer deleteAllContainers()
testRequires(t, SameHostDaemon)