|
4 | 4 | "errors" |
5 | 5 | "fmt" |
6 | 6 | "strconv" |
7 | | - "strings" |
8 | 7 | "time" |
9 | 8 |
|
10 | 9 | dc "github.com/fsouza/go-dockerclient" |
@@ -160,7 +159,7 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err |
160 | 159 | func resourceDockerContainerRead(d *schema.ResourceData, meta interface{}) error { |
161 | 160 | client := meta.(*dc.Client) |
162 | 161 |
|
163 | | - apiContainer, err := fetchDockerContainer(d.Get("name").(string), client) |
| 162 | + apiContainer, err := fetchDockerContainer(d.Id(), client) |
164 | 163 | if err != nil { |
165 | 164 | return err |
166 | 165 | } |
@@ -268,28 +267,16 @@ func mapTypeMapValsToString(typeMap map[string]interface{}) map[string]string { |
268 | 267 | return mapped |
269 | 268 | } |
270 | 269 |
|
271 | | -func fetchDockerContainer(name string, client *dc.Client) (*dc.APIContainers, error) { |
| 270 | +func fetchDockerContainer(ID string, client *dc.Client) (*dc.APIContainers, error) { |
272 | 271 | apiContainers, err := client.ListContainers(dc.ListContainersOptions{All: true}) |
273 | 272 |
|
274 | 273 | if err != nil { |
275 | 274 | return nil, fmt.Errorf("Error fetching container information from Docker: %s\n", err) |
276 | 275 | } |
277 | 276 |
|
278 | 277 | for _, apiContainer := range apiContainers { |
279 | | - // Sometimes the Docker API prefixes container names with / |
280 | | - // like it does in these commands. But if there's no |
281 | | - // set name, it just uses the ID without a /...ugh. |
282 | | - switch len(apiContainer.Names) { |
283 | | - case 0: |
284 | | - if apiContainer.ID == name { |
285 | | - return &apiContainer, nil |
286 | | - } |
287 | | - default: |
288 | | - for _, containerName := range apiContainer.Names { |
289 | | - if strings.TrimLeft(containerName, "/") == name { |
290 | | - return &apiContainer, nil |
291 | | - } |
292 | | - } |
| 278 | + if apiContainer.ID == ID { |
| 279 | + return &apiContainer, nil |
293 | 280 | } |
294 | 281 | } |
295 | 282 |
|
|
0 commit comments