When linking to other containers, introduce a slight delay; this lets

the Docker API get those containers running. Otherwise when
you try to start a container linking to them, the start command
will fail, leading to an error.
This commit is contained in:
Jeff Mitchell 2015-06-12 18:44:37 +00:00
parent 8c866a4510
commit 2e01e0635b
1 changed files with 10 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"strconv"
"strings"
"time"
dc "github.com/fsouza/go-dockerclient"
"github.com/hashicorp/terraform/helper/schema"
@ -19,6 +20,8 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
return err
}
delayStart := false
image := d.Get("image").(string)
if _, ok := data.DockerImages[image]; !ok {
if _, ok := data.DockerImages[image+":latest"]; !ok {
@ -106,6 +109,13 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
if v, ok := d.GetOk("links"); ok {
hostConfig.Links = stringSetToStringSlice(v.(*schema.Set))
delayStart = true
}
// For instance, Docker will fail to start conatiners with links
// to other containers if the containers haven't started yet
if delayStart {
time.Sleep(3 * time.Second)
}
if err := client.StartContainer(retContainer.ID, hostConfig); err != nil {