Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug where docker_container resource was not working properly with swarm #3364

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions builtin/providers/docker/resource_docker_container_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
func resourceDockerContainerRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*dc.Client)

apiContainer, err := fetchDockerContainer(d.Get("name").(string), client)
apiContainer, err := fetchDockerContainer(d.Id(), client)
if err != nil {
return err
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func stringSetToStringSlice(stringSet *schema.Set) []string {
return ret
}

func fetchDockerContainer(name string, client *dc.Client) (*dc.APIContainers, error) {
func fetchDockerContainer(ID string, client *dc.Client) (*dc.APIContainers, error) {
apiContainers, err := client.ListContainers(dc.ListContainersOptions{All: true})

if err != nil {
Expand All @@ -236,12 +236,12 @@ func fetchDockerContainer(name string, client *dc.Client) (*dc.APIContainers, er
// set name, it just uses the ID without a /...ugh.
switch len(apiContainer.Names) {
case 0:
if apiContainer.ID == name {
if apiContainer.ID == ID {
return &apiContainer, nil
}
default:
for _, containerName := range apiContainer.Names {
if strings.TrimLeft(containerName, "/") == name {
if strings.TrimLeft(containerName, "/") == ID {
return &apiContainer, nil
}
}
Expand Down