diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index d9aa3db8c0..dce6432846 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -34,6 +34,9 @@ func inspectContainerAndCheckState(ctx context.Context, cli client.APIClient, ar if c.State.Paused { return nil, errors.New("You cannot attach to a paused container, unpause it first") } + if c.State.Restarting { + return nil, errors.New("You cannot attach to a restarting container, wait until it is running") + } return &c, nil } diff --git a/cli/command/container/attach_test.go b/cli/command/container/attach_test.go index 8e29f3b076..14b8137dae 100644 --- a/cli/command/container/attach_test.go +++ b/cli/command/container/attach_test.go @@ -51,6 +51,21 @@ func TestNewAttachCommandErrors(t *testing.T) { return c, nil }, }, + { + name: "client-restarting", + args: []string{"5cb5bb5e4a3b"}, + expectedError: "You cannot attach to a restarting container", + containerInspectFunc: func(containerID string) (types.ContainerJSON, error) { + c := types.ContainerJSON{} + c.ContainerJSONBase = &types.ContainerJSONBase{} + c.ContainerJSONBase.State = &types.ContainerState{ + Running: true, + Paused: false, + Restarting: true, + } + return c, nil + }, + }, } for _, tc := range testCases { buf := new(bytes.Buffer)