mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix status code for missing --volumes-from container
If the container specified in `--volumes-from` did not exist, the API returned a 404 status, which was interpreted by the CLI as the specified _image_ to be missing (even if that was not the case). This patch changes these error to return a 400 (bad request); Before this change: # make sure the image is present docker pull busybox docker create --volumes-from=nosuchcontainer busybox # Unable to find image 'busybox:latest' locally # latest: Pulling from library/busybox # Digest: sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209 # Status: Image is up to date for busybox:latest # Error response from daemon: No such container: nosuchcontainer After this change: # make sure the image is present docker pull busybox docker create --volumes-from=nosuchcontainer busybox # Error response from daemon: No such container: nosuchcontainer Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
b50ba3da12
commit
3258d565cf
2 changed files with 17 additions and 2 deletions
|
@ -95,12 +95,12 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
|
|||
for _, v := range hostConfig.VolumesFrom {
|
||||
containerID, mode, err := parser.ParseVolumesFrom(v)
|
||||
if err != nil {
|
||||
return err
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
c, err := daemon.GetContainer(containerID)
|
||||
if err != nil {
|
||||
return err
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
for _, m := range c.MountPoints {
|
||||
|
|
|
@ -621,3 +621,18 @@ func TestCreateDifferentPlatform(t *testing.T) {
|
|||
assert.Assert(t, client.IsErrNotFound(err), err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateVolumesFromNonExistingContainer(t *testing.T) {
|
||||
defer setupTest(t)()
|
||||
cli := testEnv.APIClient()
|
||||
|
||||
_, err := cli.ContainerCreate(
|
||||
context.Background(),
|
||||
&container.Config{Image: "busybox"},
|
||||
&container.HostConfig{VolumesFrom: []string{"nosuchcontainer"}},
|
||||
nil,
|
||||
nil,
|
||||
"",
|
||||
)
|
||||
assert.Check(t, errdefs.IsInvalidParameter(err))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue