mirror of https://github.com/docker/cli.git
Add a restarting check to runAttach
Signed-off-by: Shukui Yang <yangshukui@huawei.com>
This commit is contained in:
parent
e8cc2cf760
commit
90f497302f
|
@ -34,6 +34,9 @@ func inspectContainerAndCheckState(ctx context.Context, cli client.APIClient, ar
|
||||||
if c.State.Paused {
|
if c.State.Paused {
|
||||||
return nil, errors.New("You cannot attach to a paused container, unpause it first")
|
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
|
return &c, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,21 @@ func TestNewAttachCommandErrors(t *testing.T) {
|
||||||
return c, nil
|
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 {
|
for _, tc := range testCases {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
Loading…
Reference in New Issue