Merge pull request #156 from skanehira/master

Improve container top
This commit is contained in:
Dawid Dziurla 2019-08-26 08:22:33 +02:00 committed by GitHub
commit 98ae4f3b0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -367,6 +367,16 @@ func (c *Container) Attach() (*exec.Cmd, error) {
// Top returns process information
func (c *Container) Top() (container.ContainerTopOKBody, error) {
detail, err := c.Inspect()
if err != nil {
return container.ContainerTopOKBody{}, err
}
// check container status
if !detail.State.Running {
return container.ContainerTopOKBody{}, errors.New("container is not running")
}
return c.Client.ContainerTop(context.Background(), c.ID, []string{})
}
@ -411,7 +421,7 @@ func (c *Container) Inspect() (types.ContainerJSON, error) {
// RenderTop returns details about the container
func (c *Container) RenderTop() (string, error) {
result, err := c.Client.ContainerTop(context.Background(), c.ID, []string{})
result, err := c.Top()
if err != nil {
return "", err
}