diff --git a/builtin/providers/docker/resource_docker_container.go b/builtin/providers/docker/resource_docker_container.go
index 3ee87cf76..c8f363e3f 100644
--- a/builtin/providers/docker/resource_docker_container.go
+++ b/builtin/providers/docker/resource_docker_container.go
@@ -184,7 +184,7 @@ func resourceDockerContainer() *schema.Resource {
Set: resourceDockerPortsHash,
},
- "hosts": &schema.Schema{
+ "host": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
diff --git a/builtin/providers/docker/resource_docker_container_funcs.go b/builtin/providers/docker/resource_docker_container_funcs.go
index 1c3f3d1d3..47878f934 100644
--- a/builtin/providers/docker/resource_docker_container_funcs.go
+++ b/builtin/providers/docker/resource_docker_container_funcs.go
@@ -68,7 +68,7 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
}
extraHosts := []string{}
- if v, ok := d.GetOk("extra_hosts"); ok {
+ if v, ok := d.GetOk("host"); ok {
extraHosts = extraHostsSetToDockerExtraHosts(v.(*schema.Set))
}
diff --git a/builtin/providers/docker/resource_docker_container_test.go b/builtin/providers/docker/resource_docker_container_test.go
index a5c36a5c2..aa1eee961 100644
--- a/builtin/providers/docker/resource_docker_container_test.go
+++ b/builtin/providers/docker/resource_docker_container_test.go
@@ -72,6 +72,18 @@ func TestAccDockerContainer_customized(t *testing.T) {
return fmt.Errorf("Container does not have the correct max-file log option: %v", c.HostConfig.LogConfig.Config["max-file"])
}
+ if len(c.HostConfig.ExtraHosts) != 2 {
+ return fmt.Errorf("Container does not have correct number of extra host entries, got %d", len(c.HostConfig.ExtraHosts))
+ }
+
+ if c.HostConfig.ExtraHosts[0] != "testhost2:10.0.2.0" {
+ return fmt.Errorf("Container has incorrect extra host string: %q", c.HostConfig.ExtraHosts[0])
+ }
+
+ if c.HostConfig.ExtraHosts[1] != "testhost:10.0.1.0" {
+ return fmt.Errorf("Container has incorrect extra host string: %q", c.HostConfig.ExtraHosts[1])
+ }
+
return nil
}
@@ -132,6 +144,7 @@ resource "docker_container" "foo" {
image = "${docker_image.foo.latest}"
}
`
+
const testAccDockerContainerCustomizedConfig = `
resource "docker_image" "foo" {
name = "nginx:latest"
@@ -140,21 +153,31 @@ resource "docker_image" "foo" {
resource "docker_container" "foo" {
name = "tf-test"
image = "${docker_image.foo.latest}"
- entrypoint = ["/bin/bash", "-c", "ping localhost"]
- restart = "on-failure"
- max_retry_count = 5
- memory = 512
- memory_swap = 2048
- cpu_shares = 32
- labels {
- env = "prod"
- role = "test"
- }
- log_driver = "json-file"
- log_opts = {
- max-size = "10m"
- max-file = 20
+ entrypoint = ["/bin/bash", "-c", "ping localhost"]
+ restart = "on-failure"
+ max_retry_count = 5
+ memory = 512
+ memory_swap = 2048
+ cpu_shares = 32
+ labels {
+ env = "prod"
+ role = "test"
+ }
+ log_driver = "json-file"
+ log_opts = {
+ max-size = "10m"
+ max-file = 20
}
network_mode = "bridge"
+
+ host {
+ host = "testhost"
+ ip = "10.0.1.0"
+ }
+
+ host {
+ host = "testhost2"
+ ip = "10.0.2.0"
+ }
}
`
diff --git a/website/source/docs/providers/docker/r/container.html.markdown b/website/source/docs/providers/docker/r/container.html.markdown
index 8065a998b..dd39a34ff 100644
--- a/website/source/docs/providers/docker/r/container.html.markdown
+++ b/website/source/docs/providers/docker/r/container.html.markdown
@@ -57,7 +57,7 @@ The following arguments are supported:
kept running. If false, then as long as the container exists, Terraform
assumes it is successful.
* `ports` - (Optional) See [Ports](#ports) below for details.
-* `extra_hosts` - (Optional) See [Extra Hosts](#extra_hosts) below for details.
+* `host_entry` - (Optional) See [Extra Hosts](#extra_hosts) below for details.
* `privileged` - (Optional, bool) Run container in privileged mode.
* `publish_all_ports` - (Optional, bool) Publish all ports of the container.
* `volumes` - (Optional) See [Volumes](#volumes) below for details.
@@ -88,13 +88,16 @@ the following:
## Extra Hosts
-`extra_hosts` is a block within the configuration that can be repeated to specify
-the extra host mappings for the container. Each `extra_hosts` block supports
+`host_entry` is a block within the configuration that can be repeated to specify
+the extra host mappings for the container. Each `host_entry` block supports
the following:
* `host` - (Required, int) Hostname to add.
* `ip` - (Required, int) IP address this hostname should resolve to..
+This is equivalent to using the `--add-host` option when using the `run`
+command of the Docker CLI.
+
## Volumes