Fix a serious problem when using links.
Links cause there to be more than one name for a container to be returned. As a result, only looking at the first element of the container names could cause a container to not be found, leading Terraform to remove it from state and attempt to recreate it.
This commit is contained in:
parent
2e01e0635b
commit
56cfba2509
|
@ -211,16 +211,18 @@ func fetchDockerContainer(name string, client *dc.Client) (*dc.APIContainers, er
|
||||||
// Sometimes the Docker API prefixes container names with /
|
// Sometimes the Docker API prefixes container names with /
|
||||||
// like it does in these commands. But if there's no
|
// like it does in these commands. But if there's no
|
||||||
// set name, it just uses the ID without a /...ugh.
|
// set name, it just uses the ID without a /...ugh.
|
||||||
var dockerContainerName string
|
switch len(apiContainer.Names) {
|
||||||
if len(apiContainer.Names) > 0 {
|
case 0:
|
||||||
dockerContainerName = strings.TrimLeft(apiContainer.Names[0], "/")
|
if apiContainer.ID == name {
|
||||||
} else {
|
|
||||||
dockerContainerName = apiContainer.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
if dockerContainerName == name {
|
|
||||||
return &apiContainer, nil
|
return &apiContainer, nil
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
for _, containerName := range apiContainer.Names {
|
||||||
|
if strings.TrimLeft(containerName, "/") == name {
|
||||||
|
return &apiContainer, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
Loading…
Reference in New Issue