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>
| ... | ... |
@@ -95,12 +95,12 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo |
| 95 | 95 |
for _, v := range hostConfig.VolumesFrom {
|
| 96 | 96 |
containerID, mode, err := parser.ParseVolumesFrom(v) |
| 97 | 97 |
if err != nil {
|
| 98 |
- return err |
|
| 98 |
+ return errdefs.InvalidParameter(err) |
|
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 | 101 |
c, err := daemon.GetContainer(containerID) |
| 102 | 102 |
if err != nil {
|
| 103 |
- return err |
|
| 103 |
+ return errdefs.InvalidParameter(err) |
|
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
for _, m := range c.MountPoints {
|
| ... | ... |
@@ -621,3 +621,18 @@ func TestCreateDifferentPlatform(t *testing.T) {
|
| 621 | 621 |
assert.Assert(t, client.IsErrNotFound(err), err) |
| 622 | 622 |
}) |
| 623 | 623 |
} |
| 624 |
+ |
|
| 625 |
+func TestCreateVolumesFromNonExistingContainer(t *testing.T) {
|
|
| 626 |
+ defer setupTest(t)() |
|
| 627 |
+ cli := testEnv.APIClient() |
|
| 628 |
+ |
|
| 629 |
+ _, err := cli.ContainerCreate( |
|
| 630 |
+ context.Background(), |
|
| 631 |
+ &container.Config{Image: "busybox"},
|
|
| 632 |
+ &container.HostConfig{VolumesFrom: []string{"nosuchcontainer"}},
|
|
| 633 |
+ nil, |
|
| 634 |
+ nil, |
|
| 635 |
+ "", |
|
| 636 |
+ ) |
|
| 637 |
+ assert.Check(t, errdefs.IsInvalidParameter(err)) |
|
| 638 |
+} |