mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 20:52:33 +02:00
29 lines
609 B
Go
29 lines
609 B
Go
package docker
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
func Inspect(dockerHost string, containerID string) (*Container, error) {
|
|
client, err := ConnectClient(dockerHost)
|
|
defer client.Close()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return client.Inspect(containerID)
|
|
}
|
|
|
|
func (c Client) Inspect(containerID string) (*Container, error) {
|
|
ctx, cancel := context.WithTimeoutCause(context.Background(), 3*time.Second, errors.New("docker container inspect timeout"))
|
|
defer cancel()
|
|
|
|
json, err := c.ContainerInspect(ctx, containerID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return FromJSON(json, c.key), nil
|
|
}
|