Skip to content

Commit

Permalink
Fixes an issue with purging containers with the same name Nomad is tr…
Browse files Browse the repository at this point in the history
…ying to start
  • Loading branch information
diptanu committed Nov 29, 2016
1 parent e08ca6a commit 26bb30e
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 26bb30e

Please sign in to comment.