Skip to content

Commit

Permalink
(#43) Stop containers using name, not the image
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Aug 3, 2018
1 parent bdaca2b commit 6ef9400
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var stopReleaseCmd = &cobra.Command{

// stopDockerContainer stops the running container
func stopDockerContainer(image liferay.Image) {
err := docker.StopDockerContainer(image)
err := docker.StopDockerContainer(image.GetContainerName())
if err != nil {
log.Fatalln("Impossible to stop the container [" + image.GetContainerName() + "]")
}
Expand Down
21 changes: 19 additions & 2 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

types "github.com/docker/docker/api/types"
filters "github.com/docker/docker/api/types/filters"
client "github.com/docker/docker/client"
liferay "github.com/mdelapenya/lpn/liferay"
shell "github.com/mdelapenya/lpn/shell"
Expand Down Expand Up @@ -125,6 +126,22 @@ func LogDockerContainer(image liferay.Image) {
shell.StartAndWait(dockerBinary, cmdArgs)
}

// PsFilter Retrieves all containers with a label
func PsFilter(label string) ([]types.Container, error) {
dockerClient := getDockerClient()

filters := filters.NewArgs()
filters.Add("label", label)

return dockerClient.ContainerList(
context.Background(), types.ContainerListOptions{
Size: true,
All: true,
Since: "container",
Filters: filters,
})
}

// PullDockerImage downloads the image
func PullDockerImage(dockerImage string) {
log.Println("Pulling [" + dockerImage + "].")
Expand Down Expand Up @@ -206,10 +223,10 @@ func RunDockerImage(
}

// StopDockerContainer stops the running container
func StopDockerContainer(image liferay.Image) error {
func StopDockerContainer(containerName string) error {
cmdArgs := []string{
"stop",
image.GetContainerName(),
containerName,
}

return shell.CombinedOutput(dockerBinary, cmdArgs)
Expand Down

0 comments on commit 6ef9400

Please sign in to comment.