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:
commit
61069d8b69
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph"
|
||||||
|
@ -94,7 +95,7 @@ func (cli *DockerCli) createContainer(config *runconfig.Config, hostConfig *runc
|
||||||
//create the container
|
//create the container
|
||||||
stream, statusCode, err := cli.call("POST", "/containers/create?"+containerValues.Encode(), mergedConfig, nil)
|
stream, statusCode, err := cli.call("POST", "/containers/create?"+containerValues.Encode(), mergedConfig, nil)
|
||||||
//if image not found try to pull it
|
//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)
|
repo, tag := parsers.ParseRepositoryTag(config.Image)
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = graph.DEFAULTTAG
|
tag = graph.DEFAULTTAG
|
||||||
|
|
|
@ -166,7 +166,7 @@ func from(b *Builder, args []string, attributes map[string]bool, original string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if b.Daemon.Graph().IsNotExist(err) {
|
if b.Daemon.Graph().IsNotExist(err, name) {
|
||||||
image, err = b.pullImage(name)
|
image, err = b.pullImage(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (daemon *Daemon) ContainerCreate(job *engine.Job) error {
|
||||||
|
|
||||||
container, buildWarnings, err := daemon.Create(config, hostConfig, name)
|
container, buildWarnings, err := daemon.Create(config, hostConfig, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if daemon.Graph().IsNotExist(err) {
|
if daemon.Graph().IsNotExist(err, config.Image) {
|
||||||
_, tag := parsers.ParseRepositoryTag(config.Image)
|
_, tag := parsers.ParseRepositoryTag(config.Image)
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
tag = graph.DEFAULTTAG
|
tag = graph.DEFAULTTAG
|
||||||
|
|
|
@ -138,7 +138,7 @@ func (daemon *Daemon) canDeleteImage(imgID string, force bool) error {
|
||||||
for _, container := range daemon.List() {
|
for _, container := range daemon.List() {
|
||||||
parent, err := daemon.Repositories().LookupImage(container.ImageID)
|
parent, err := daemon.Repositories().LookupImage(container.ImageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if daemon.Graph().IsNotExist(err) {
|
if daemon.Graph().IsNotExist(err, container.ImageID) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -74,8 +74,8 @@ func (graph *Graph) restore() error {
|
||||||
|
|
||||||
// FIXME: Implement error subclass instead of looking at the error text
|
// FIXME: Implement error subclass instead of looking at the error text
|
||||||
// Note: This is the way golang implements os.IsNotExists on Plan9
|
// Note: This is the way golang implements os.IsNotExists on Plan9
|
||||||
func (graph *Graph) IsNotExist(err error) bool {
|
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"))
|
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.
|
// Exists returns true if an image is registered at the given id.
|
||||||
|
|
|
@ -2990,6 +2990,17 @@ func TestRunModeIpcContainer(t *testing.T) {
|
||||||
logDone("run - ipc container mode")
|
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) {
|
func TestContainerNetworkMode(t *testing.T) {
|
||||||
defer deleteAllContainers()
|
defer deleteAllContainers()
|
||||||
testRequires(t, SameHostDaemon)
|
testRequires(t, SameHostDaemon)
|
||||||
|
|
Loading…
Reference in New Issue