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

provider/docker: #5298 Add support for docker run --user option #5300

Merged
merged 1 commit into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions builtin/providers/docker/resource_docker_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ func resourceDockerContainer() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},

"user": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"dns": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Expand Down
4 changes: 4 additions & 0 deletions builtin/providers/docker/resource_docker_container_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
createOpts.Config.Entrypoint = stringListToStringSlice(v.([]interface{}))
}

if v, ok := d.GetOk("user"); ok {
createOpts.Config.User = v.(string)
}

exposedPorts := map[dc.Port]struct{}{}
portBindings := map[dc.Port][]dc.PortBinding{}

Expand Down
5 changes: 5 additions & 0 deletions builtin/providers/docker/resource_docker_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func TestAccDockerContainer_customized(t *testing.T) {
return fmt.Errorf("Container wrong entrypoint: %s", c.Config.Entrypoint)
}

if c.Config.User != "root:root" {
return fmt.Errorf("Container wrong user: %s", c.Config.User)
}

if c.HostConfig.RestartPolicy.Name == "on-failure" {
if c.HostConfig.RestartPolicy.MaximumRetryCount != 5 {
return fmt.Errorf("Container has wrong restart policy max retry count: %d", c.HostConfig.RestartPolicy.MaximumRetryCount)
Expand Down Expand Up @@ -217,6 +221,7 @@ resource "docker_container" "foo" {
name = "tf-test"
image = "${docker_image.foo.latest}"
entrypoint = ["/bin/bash", "-c", "ping localhost"]
user = "root:root"
restart = "on-failure"
max_retry_count = 5
memory = 512
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ The following arguments are supported:
container to run as an executable. For example, to run `/usr/bin/myprogram`
when starting a container, set the entrypoint to be
`["/usr/bin/myprogram"]`.
* `user` - (Optional, string) User used for run the first process. Format is
`user` or `user:group` which user and group can be passed literraly or
by name.
* `dns` - (Optional, set of strings) Set of DNS servers.
* `env` - (Optional, set of strings) Environmental variables to set.
* `labels` - (Optional, map of strings) Key/value pairs to set as labels on the
Expand Down