Skip to content

Commit

Permalink
Merge pull request #2037 from hashicorp/b-docker-list-containers
Browse files Browse the repository at this point in the history
Fixes an issue with purging containers with the same name Nomad is tr…
  • Loading branch information
diptanu authored Nov 29, 2016
2 parents e08ca6a + 26bb30e commit f74472a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,17 +965,22 @@ CREATE:
}

if strings.Contains(strings.ToLower(err.Error()), "container already exists") {
containers, err := client.ListContainers(docker.ListContainersOptions{})
containers, err := client.ListContainers(docker.ListContainersOptions{
All: true,
})
if err != nil {
d.logger.Printf("[ERR] driver.docker: failed to query list of containers matching name:%s", config.Name)
return nil, recoverable(fmt.Errorf("Failed to query list of containers: %s", err))
}

// Delete matching containers
// Adding a / infront of the container name since Docker returns the
// container names with a / pre-pended to the Nomad generated container names
containerName := "/" + config.Name
for _, container := range containers {
found := false
for _, name := range container.Names {
if name == config.Name {
if name == containerName {
found = true
break
}
Expand Down

0 comments on commit f74472a

Please sign in to comment.