Skip to content

Commit

Permalink
Add docker prune command #29
Browse files Browse the repository at this point in the history
  • Loading branch information
moncho committed Feb 5, 2017
1 parent ab86a43 commit a9efe9c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,37 @@ func (daemon *DockerDaemon) Ok() (bool, error) {
return daemon.err == nil, daemon.err
}

//Prune requests the Docker daemon to prune unused containers, images
//networks and volumes
func (daemon *DockerDaemon) Prune() (*PrunerReport, error) {
c := context.Background()

args := filters.Args{}
args.Add("all", "y")
cReport, err := daemon.client.ContainersPrune(c, args)
if err != nil {
return nil, err
}
iReport, err := daemon.client.ImagesPrune(c, args)
if err != nil {
return nil, err
}
nReport, err := daemon.client.NetworksPrune(c, args)
if err != nil {
return nil, err
}
vRreport, err := daemon.client.VolumesPrune(c, args)
if err != nil {
return nil, err
}
return &PrunerReport{
ContainerReport: cReport,
ImagesReport: iReport,
NetworksReport: nReport,
VolumesReport: vRreport}, nil

}

//RestartContainer restarts the container with the given id
func (daemon *DockerDaemon) RestartContainer(id string) error {
//TODO use cancel function
Expand Down
8 changes: 8 additions & 0 deletions docker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ type Stats struct {
Stats *types.StatsJSON
ProcessList *types.ContainerProcessList
}

//PrunerReport represents the result of a prune operation
type PrunerReport struct {
ContainerReport types.ContainersPruneReport
ImagesReport types.ImagesPruneReport
NetworksReport types.NetworksPruneReport
VolumesReport types.VolumesPruneReport
}

0 comments on commit a9efe9c

Please sign in to comment.