github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/website/source/docs/providers/docker/r/container.html.markdown (about)

     1  ---
     2  layout: "docker"
     3  page_title: "Docker: docker_container"
     4  sidebar_current: "docs-docker-resource-container"
     5  description: |-
     6    Manages the lifecycle of a Docker container.
     7  ---
     8  
     9  # docker\_container
    10  
    11  Manages the lifecycle of a Docker container.
    12  
    13  ## Example Usage
    14  
    15  ```hcl
    16  # Start a container
    17  resource "docker_container" "ubuntu" {
    18    name  = "foo"
    19    image = "${docker_image.ubuntu.latest}"
    20  }
    21  
    22  # Find the latest Ubuntu precise image.
    23  resource "docker_image" "ubuntu" {
    24    name = "ubuntu:precise"
    25  }
    26  ```
    27  
    28  ## Argument Reference
    29  
    30  The following arguments are supported:
    31  
    32  * `name` - (Required, string) The name of the Docker container.
    33  * `image` - (Required, string) The ID of the image to back this container.
    34    The easiest way to get this value is to use the `docker_image` resource
    35    as is shown in the example above.
    36  
    37  * `command` - (Optional, list of strings) The command to use to start the
    38      container. For example, to run `/usr/bin/myprogram -f baz.conf` set the
    39      command to be `["/usr/bin/myprogram", "-f", "baz.conf"]`.
    40  * `entrypoint` - (Optional, list of strings) The command to use as the
    41      Entrypoint for the container. The Entrypoint allows you to configure a
    42      container to run as an executable. For example, to run `/usr/bin/myprogram`
    43      when starting a container, set the entrypoint to be
    44      `["/usr/bin/myprogram"]`.
    45  * `user` - (Optional, string) User used for run the first process. Format is
    46      `user` or `user:group` which user and group can be passed literraly or
    47      by name.
    48  * `dns` - (Optional, set of strings) Set of DNS servers.
    49  * `dns_opts` - (Optional, set of strings) Set of DNS options used by the DNS provider(s), see `resolv.conf` documentation for valid list of options.
    50  * `dns_search` - (Optional, set of strings) Set of DNS search domains that are used when bare unqualified hostnames are used inside of the container.
    51  * `env` - (Optional, set of strings) Environment variables to set.
    52  * `labels` - (Optional, map of strings) Key/value pairs to set as labels on the
    53    container.
    54  * `links` - (Optional, set of strings) Set of links for link based
    55    connectivity between containers that are running on the same host.
    56  * `hostname` - (Optional, string) Hostname of the container.
    57  * `domainname` - (Optional, string) Domain name of the container.
    58  * `restart` - (Optional, string) The restart policy for the container. Must be
    59    one of "no", "on-failure", "always", "unless-stopped".
    60  * `max_retry_count` - (Optional, int) The maximum amount of times to an attempt
    61    a restart when `restart` is set to "on-failure"
    62  * `must_run` - (Optional, bool) If true, then the Docker container will be
    63    kept running. If false, then as long as the container exists, Terraform
    64    assumes it is successful.
    65  * `capabilities` - (Optional, block) See [Capabilities](#capabilities) below for details.
    66  * `ports` - (Optional, block) See [Ports](#ports) below for details.
    67  * `host` - (Optional, block) See [Extra Hosts](#extra_hosts) below for
    68    details.
    69  * `privileged` - (Optional, bool) Run container in privileged mode.
    70  * `publish_all_ports` - (Optional, bool) Publish all ports of the container.
    71  * `volumes` - (Optional, block) See [Volumes](#volumes) below for details.
    72  * `memory` - (Optional, int) The memory limit for the container in MBs.
    73  * `memory_swap` - (Optional, int) The total memory limit (memory + swap) for the
    74    container in MBs. This setting may compute to `-1` after `terraform apply` if the target host doesn't support memory swap, when that is the case docker will use a soft limitation.
    75  * `cpu_shares` - (Optional, int) CPU shares (relative weight) for the container.
    76  * `log_driver` - (Optional, string) The logging driver to use for the container.
    77    Defaults to "json-file".
    78  * `log_opts` - (Optional, map of strings) Key/value pairs to use as options for
    79    the logging driver.
    80  * `network_alias` - (Optional, set of strings) Network aliases of the container for user-defined networks only.
    81  * `network_mode` - (Optional, string) Network mode of the container.
    82  * `networks` - (Optional, set of strings) Id of the networks in which the
    83    container is.
    84  * `destroy_grace_seconds` - (Optional, int) If defined will attempt to stop the container before destroying. Container will be destroyed after `n` seconds or on successful stop.
    85  * `upload` - (Optional, block) See [File Upload](#upload) below for details.
    86  
    87  <a id="capabilities"></a>
    88  ### Capabilities
    89  
    90  `capabilities` is a block within the configuration that allows you to add or drop linux capabilities. For more information about what capabilities you can add and drop please visit the docker run documentation.
    91  
    92  * `add` - (Optional, set of strings) list of linux capabilities to add.
    93  * `drop` - (Optional, set of strings) list of linux capabilities to drop.
    94  
    95  Example:
    96  
    97  ```hcl
    98  resource "docker_container" "ubuntu" {
    99    name = "foo"
   100    image = "${docker_image.ubuntu.latest}"
   101    capabilities {
   102      add = ["ALL"]
   103      drop = ["SYS_ADMIN"]
   104    }
   105  }
   106  ```
   107  
   108  <a id="ports"></a>
   109  ### Ports
   110  
   111  `ports` is a block within the configuration that can be repeated to specify
   112  the port mappings of the container. Each `ports` block supports
   113  the following:
   114  
   115  * `internal` - (Required, int) Port within the container.
   116  * `external` - (Required, int) Port exposed out of the container.
   117  * `ip` - (Optional, string) IP address/mask that can access this port.
   118  * `protocol` - (Optional, string) Protocol that can be used over this port,
   119    defaults to TCP.
   120  
   121  <a id="extra_hosts"></a>
   122  ### Extra Hosts
   123  
   124  `host` is a block within the configuration that can be repeated to specify
   125  the extra host mappings for the container. Each `host` block supports
   126  the following:
   127  
   128  * `host` - (Required, string) Hostname to add.
   129  * `ip` - (Required, string) IP address this hostname should resolve to.
   130  
   131  This is equivalent to using the `--add-host` option when using the `run`
   132  command of the Docker CLI.
   133  
   134  <a id="volumes"></a>
   135  ### Volumes
   136  
   137  `volumes` is a block within the configuration that can be repeated to specify
   138  the volumes attached to a container. Each `volumes` block supports
   139  the following:
   140  
   141  * `from_container` - (Optional, string) The container where the volume is
   142    coming from.
   143  * `host_path` - (Optional, string) The path on the host where the volume
   144    is coming from.
   145  * `volume_name` - (Optional, string) The name of the docker volume which
   146    should be mounted.
   147  * `container_path` - (Optional, string) The path in the container where the
   148    volume will be mounted.
   149  * `read_only` - (Optional, bool) If true, this volume will be readonly.
   150    Defaults to false.
   151  
   152  One of `from_container`, `host_path` or `volume_name` must be set.
   153  
   154  <a id="upload"></a>
   155  ### File Upload
   156  
   157  `upload` is a block within the configuration that can be repeated to specify
   158  files to upload to the container before starting it.
   159  Each `upload` supports the following
   160  
   161  * `content` - (Required, string) A content of a file to upload.
   162  * `file` - (Required, string) path to a file in the container.
   163  
   164  ## Attributes Reference
   165  
   166  The following attributes are exported:
   167  
   168   * `ip_address` - The IP address of the container as read from its
   169     NetworkSettings.
   170   * `ip_prefix_length` - The IP prefix length of the container as read from its
   171     NetworkSettings.
   172   * `gateway` - The network gateway of the container as read from its
   173     NetworkSettings.
   174   * `bridge` - The network bridge of the container as read from its
   175     NetworkSettings.