@ -2,11 +2,12 @@ package container
import (
import (
"fmt"
"fmt"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"io/ioutil"
"io/ioutil"
"time"
"time"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/network"
dockerclient "github.com/docker/docker/client"
dockerclient "github.com/docker/docker/client"
@ -35,7 +36,7 @@ type Client interface {
// * DOCKER_HOST the docker-engine host to send api requests to
// * DOCKER_HOST the docker-engine host to send api requests to
// * DOCKER_TLS_VERIFY whether to verify tls certificates
// * DOCKER_TLS_VERIFY whether to verify tls certificates
// * DOCKER_API_VERSION the minimum docker api version to work with
// * DOCKER_API_VERSION the minimum docker api version to work with
func NewClient ( pullImages bool , includeStopped bool ) Client {
func NewClient ( pullImages bool , includeStopped bool , removeVolumes bool ) Client {
cli , err := dockerclient . NewClientWithOpts ( dockerclient . FromEnv )
cli , err := dockerclient . NewClientWithOpts ( dockerclient . FromEnv )
if err != nil {
if err != nil {
@ -45,6 +46,7 @@ func NewClient(pullImages bool, includeStopped bool) Client {
return dockerClient {
return dockerClient {
api : cli ,
api : cli ,
pullImages : pullImages ,
pullImages : pullImages ,
removeVolumes : removeVolumes ,
includeStopped : includeStopped ,
includeStopped : includeStopped ,
}
}
}
}
@ -52,6 +54,7 @@ func NewClient(pullImages bool, includeStopped bool) Client {
type dockerClient struct {
type dockerClient struct {
api dockerclient . CommonAPIClient
api dockerclient . CommonAPIClient
pullImages bool
pullImages bool
removeVolumes bool
includeStopped bool
includeStopped bool
}
}
@ -71,7 +74,7 @@ func (client dockerClient) ListContainers(fn Filter) ([]Container, error) {
types . ContainerListOptions {
types . ContainerListOptions {
Filters : filter ,
Filters : filter ,
} )
} )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -131,7 +134,7 @@ func (client dockerClient) StopContainer(c Container, timeout time.Duration) err
} else {
} else {
log . Debugf ( "Removing container %s" , c . ID ( ) )
log . Debugf ( "Removing container %s" , c . ID ( ) )
if err := client . api . ContainerRemove ( bg , c . ID ( ) , types . ContainerRemoveOptions { Force : true , RemoveVolumes : false } ) ; err != nil {
if err := client . api . ContainerRemove ( bg , c . ID ( ) , types . ContainerRemoveOptions { Force : true , RemoveVolumes : client . removeVolumes } ) ; err != nil {
return err
return err
}
}
}
}