mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add show error when attach to a paused container
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
75128c46c7
commit
de1d611990
5 changed files with 32 additions and 0 deletions
|
@ -41,6 +41,10 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
|
|||
return fmt.Errorf("You cannot attach to a stopped container, start it first")
|
||||
}
|
||||
|
||||
if c.State.Paused {
|
||||
return fmt.Errorf("You cannot attach to a paused container, unpause it first")
|
||||
}
|
||||
|
||||
if err := cli.CheckTtyInput(!*noStdin, c.Config.Tty); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -396,6 +396,10 @@ func (s *router) postContainersAttach(ctx context.Context, w http.ResponseWriter
|
|||
return derr.ErrorCodeNoSuchContainer.WithArgs(containerName)
|
||||
}
|
||||
|
||||
if s.daemon.IsPaused(containerName) {
|
||||
return derr.ErrorCodePausedContainer.WithArgs(containerName)
|
||||
}
|
||||
|
||||
inStream, outStream, err := httputils.HijackConnection(w)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -163,6 +163,12 @@ func (daemon *Daemon) Exists(id string) bool {
|
|||
return c != nil
|
||||
}
|
||||
|
||||
// IsPaused returns a bool indicating if the specified container is paused.
|
||||
func (daemon *Daemon) IsPaused(id string) bool {
|
||||
c, _ := daemon.Get(id)
|
||||
return c.State.isPaused()
|
||||
}
|
||||
|
||||
func (daemon *Daemon) containerRoot(id string) string {
|
||||
return filepath.Join(daemon.repository, id)
|
||||
}
|
||||
|
|
|
@ -46,6 +46,14 @@ var (
|
|||
HTTPStatusCode: http.StatusInternalServerError,
|
||||
})
|
||||
|
||||
// ErrorCodePausedContainer is generated when we attempt to attach a
|
||||
// container but its paused.
|
||||
ErrorCodePausedContainer = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
||||
Value: "CONTAINERPAUSED",
|
||||
Message: "Container %s is paused. Unpause the container before attach",
|
||||
Description: "The specified container is paused, unpause the container before attach",
|
||||
HTTPStatusCode: http.StatusConflict,
|
||||
})
|
||||
// ErrorCodeAlreadyPaused is generated when we attempt to pause a
|
||||
// container when its already paused.
|
||||
ErrorCodeAlreadyPaused = errcode.Register(errGroup, errcode.ErrorDescriptor{
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
|
@ -150,3 +151,12 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
|
|||
c.Assert(err, check.IsNil)
|
||||
c.Assert(running, check.Equals, "true")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAttachPausedContainer(c *check.C) {
|
||||
defer unpauseAllContainers()
|
||||
dockerCmd(c, "run", "-d", "--name=test", "busybox", "top")
|
||||
dockerCmd(c, "pause", "test")
|
||||
out, _, err := dockerCmdWithError("attach", "test")
|
||||
c.Assert(err, checker.NotNil, check.Commentf(out))
|
||||
c.Assert(out, checker.Contains, "You cannot attach to a paused container, unpause it first")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue