terraform-provider-docker/docs/resources/container.md
2021-05-16 15:44:59 +02:00

7.7 KiB

page_title subcategory description
docker_container Resource - terraform-provider-docker Manages the lifecycle of a Docker container.

docker_container (Resource)

Manages the lifecycle of a Docker container.

Example Usage

# Start a container
resource "docker_container" "ubuntu" {
  name  = "foo"
  image = docker_image.ubuntu.latest
}

# Find the latest Ubuntu precise image.
resource "docker_image" "ubuntu" {
  name = "ubuntu:precise"
}

Schema

Required

  • image (String)
  • name (String)

Optional

  • attach (Boolean)
  • capabilities (Block Set, Max: 1) (see below for nested schema)
  • command (List of String)
  • cpu_set (String)
  • cpu_shares (Number)
  • destroy_grace_seconds (Number)
  • devices (Block Set) (see below for nested schema)
  • dns (Set of String)
  • dns_opts (Set of String)
  • dns_search (Set of String)
  • domainname (String)
  • entrypoint (List of String)
  • env (Set of String)
  • group_add (Set of String) Additional groups for the container user
  • healthcheck (Block List, Max: 1) A test to perform to check that the container is healthy (see below for nested schema)
  • host (Block Set) (see below for nested schema)
  • hostname (String)
  • id (String) The ID of this resource.
  • init (Boolean)
  • ipc_mode (String) IPC sharing mode for the container
  • labels (Block Set) (see below for nested schema)
  • links (Set of String, Deprecated)
  • log_driver (String)
  • log_opts (Map of String)
  • logs (Boolean)
  • max_retry_count (Number)
  • memory (Number)
  • memory_swap (Number)
  • mounts (Block Set) Specification for mounts to be added to containers created as part of the service (see below for nested schema)
  • must_run (Boolean)
  • network_alias (Set of String, Deprecated) Set an alias for the container in all specified networks
  • network_mode (String)
  • networks (Set of String, Deprecated)
  • networks_advanced (Block Set) (see below for nested schema)
  • pid_mode (String)
  • ports (Block List) (see below for nested schema)
  • privileged (Boolean)
  • publish_all_ports (Boolean)
  • read_only (Boolean)
  • remove_volumes (Boolean)
  • restart (String)
  • rm (Boolean)
  • security_opts (Set of String) List of string values to customize labels for MLS systems, such as SELinux. See https://docs.docker.com/engine/reference/run/#security-configuration
  • shm_size (Number)
  • start (Boolean)
  • stdin_open (Boolean)
  • sysctls (Map of String)
  • tmpfs (Map of String)
  • tty (Boolean)
  • ulimit (Block Set) (see below for nested schema)
  • upload (Block Set) (see below for nested schema)
  • user (String)
  • userns_mode (String)
  • volumes (Block Set) (see below for nested schema)
  • working_dir (String)

Read-Only

  • bridge (String)
  • container_logs (String)
  • exit_code (Number)
  • gateway (String, Deprecated)
  • ip_address (String, Deprecated)
  • ip_prefix_length (Number, Deprecated)
  • network_data (List of Object) (see below for nested schema)

Nested Schema for capabilities

Optional:

  • add (Set of String)
  • drop (Set of String)

Nested Schema for devices

Required:

  • host_path (String)

Optional:

  • container_path (String)
  • permissions (String)

Nested Schema for healthcheck

Required:

  • test (List of String) The test to perform as list

Optional:

  • interval (String) Time between running the check (ms|s|m|h)
  • retries (Number) Consecutive failures needed to report unhealthy
  • start_period (String) Start period for the container to initialize before counting retries towards unstable (ms|s|m|h)
  • timeout (String) Maximum time to allow one check to run (ms|s|m|h)

Nested Schema for host

Required:

  • host (String)
  • ip (String)

Nested Schema for labels

Required:

  • label (String) Name of the label
  • value (String) Value of the label

Nested Schema for mounts

Required:

  • target (String) Container path
  • type (String) The mount type

Optional:

  • bind_options (Block List, Max: 1) Optional configuration for the bind type (see below for nested schema)
  • read_only (Boolean) Whether the mount should be read-only
  • source (String) Mount source (e.g. a volume name, a host path)
  • tmpfs_options (Block List, Max: 1) Optional configuration for the tmpfs type (see below for nested schema)
  • volume_options (Block List, Max: 1) Optional configuration for the volume type (see below for nested schema)

Nested Schema for mounts.bind_options

Optional:

  • propagation (String) A propagation mode with the value

Nested Schema for mounts.tmpfs_options

Optional:

  • mode (Number) The permission mode for the tmpfs mount in an integer
  • size_bytes (Number) The size for the tmpfs mount in bytes

Nested Schema for mounts.volume_options

Optional:

  • driver_name (String) Name of the driver to use to create the volume
  • driver_options (Map of String) key/value map of driver specific options
  • labels (Block Set) User-defined key/value metadata (see below for nested schema)
  • no_copy (Boolean) Populate volume with data from the target

Nested Schema for mounts.volume_options.labels

Required:

  • label (String) Name of the label
  • value (String) Value of the label

Nested Schema for networks_advanced

Required:

  • name (String)

Optional:

  • aliases (Set of String)
  • ipv4_address (String)
  • ipv6_address (String)

Nested Schema for ports

Required:

  • internal (Number)

Optional:

  • external (Number)
  • ip (String)
  • protocol (String)

Nested Schema for ulimit

Required:

  • hard (Number)
  • name (String)
  • soft (Number)

Nested Schema for upload

Required:

  • file (String)

Optional:

  • content (String)
  • content_base64 (String)
  • executable (Boolean)
  • source (String)
  • source_hash (String)

Nested Schema for volumes

Optional:

  • container_path (String)
  • from_container (String)
  • host_path (String)
  • read_only (Boolean)
  • volume_name (String)

Nested Schema for network_data

Read-Only:

  • gateway (String)
  • global_ipv6_address (String)
  • global_ipv6_prefix_length (Number)
  • ip_address (String)
  • ip_prefix_length (Number)
  • ipv6_gateway (String)
  • network_name (String)

Import

Import is supported using the following syntax:

#!/bin/bash
$ terraform import docker_container.foo "$(docker inspect -f {.ID}} foo)"