(ctx context.Context, apiClient client.APIClient, args string)
| 23 | } |
| 24 | |
| 25 | func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*container.InspectResponse, error) { |
| 26 | c, err := apiClient.ContainerInspect(ctx, args, client.ContainerInspectOptions{}) |
| 27 | if err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | if !c.Container.State.Running { |
| 31 | return nil, errors.New("cannot attach to a stopped container, start it first") |
| 32 | } |
| 33 | if c.Container.State.Paused { |
| 34 | return nil, errors.New("cannot attach to a paused container, unpause it first") |
| 35 | } |
| 36 | if c.Container.State.Restarting { |
| 37 | return nil, errors.New("cannot attach to a restarting container, wait until it is running") |
| 38 | } |
| 39 | |
| 40 | return &c.Container, nil |
| 41 | } |
| 42 | |
| 43 | // newAttachCommand creates a new cobra.Command for `docker attach` |
| 44 | func newAttachCommand(dockerCLI command.Cli) *cobra.Command { |
no test coverage detected
searching dependent graphs…