# `Testcontainers.Container`
[🔗](https://github.com/testcontainers/testcontainers-elixir/blob/main/lib/container.ex#L4)

A struct with builder functions for creating a definition of a container.

# `t`

```elixir
@type t() :: %Testcontainers.Container{
  auth: term(),
  auto_remove: term(),
  bind_mounts: term(),
  bind_volumes: term(),
  check_image: term(),
  cmd: term(),
  container_id: term(),
  copy_to: term(),
  environment: term(),
  exposed_ports: term(),
  force_reuse: term(),
  hostname: term(),
  image: term(),
  ip_address: term(),
  labels: term(),
  name: term(),
  network: term(),
  network_mode: term(),
  privileged: term(),
  pull_policy: term(),
  reuse: term(),
  wait_strategies: term()
}
```

# `is_os`
*macro* 

# `is_valid_image`
*macro* 

Returns `true` if `term` is a valid `check_image`, otherwise returns `false`.

# `mapped_port`

Gets the host port on the container for the given exposed port.

# `new`

A constructor function to make it easier to construct a container

# `os_type`

# `valid_image`

Check if the provided image is compatible with the expected default image.

# `valid_image!`

Check if the provided image is compatible with the expected default image.

Raises:

ArgumentError when image isn't compatible.

# `with_auth`

Adds authentication token for registries that require a login.

# `with_auto_remove`

Sets whether the container should be automatically removed on exit.

# `with_bind_mount`

Sets a file or the directory on the _host machine_ to be mounted into a _container_.

# `with_bind_volume`

Sets a volume to be mounted into a container on target path

# `with_check_image`

Set the regular expression to check the image validity.

When using a string, it will compile it to a regular expression. If the compilation fails, it will raise a `Regex.CompileError`.

# `with_cmd`

Sets a cmd to run when the container starts.

# `with_copy_to`

# `with_environment`

Sets an _environment variable_ to the _container_.

# `with_exposed_port`

Adds a _port_ to be exposed on the _container_.

# `with_exposed_ports`

Adds multiple _ports_ to be exposed on the _container_.

# `with_fixed_port`

Adds a fixed _port_ to be exposed on the _container_.
This approach to managing ports is not recommended by Testcontainers.
Use at your own risk.

# `with_force_reuse`

# `with_hostname`

Sets the hostname for the container.

This is useful when containers need to communicate with each other by hostname
on a shared Docker network.

# `with_label`

Sets a label to apply to the container object in docker.

# `with_name`

Sets a custom name for the container (equivalent to `docker run --name`).

Must match `/?[a-zA-Z0-9][a-zA-Z0-9_.-]+`. This is useful when other
containers need to reference this container by name on a shared Docker
network.

# `with_network`

Sets the Docker network for the container to join.

Containers on the same network can communicate with each other using their
hostnames. Use `with_hostname/2` to set a custom hostname for the container.

# `with_network_mode`

Sets a network mode to apply to the container object in docker.

# `with_privileged`

Sets whether the container should run in privileged mode.

Required for containers that need access to the Docker/Podman socket
when running under SELinux (e.g., Ryuk on Podman).

# `with_pull_policy`

Controls if image is pulled from a remote repository

Available options:

  * `TestContainers.PullPolicy.pull_if_missing()` - default, pulls image only if not already present locally (avoids registry rate limits)
  * `TestContainers.PullPolicy.always_pull()` - always pulls image from the remote repository
  * `TestContainers.PullPolicy.never_pull()` - does not pull images, use when working with local images
  * `TestContainers.PullPolicy.pull_condition(expr)` - pulls image if expression returns `true`

# `with_reuse`

Sets whether the container should be reused if it is already running.

# `with_waiting_strategies`

Sets multiple _waiting strategies_ for the _container_.

# `with_waiting_strategy`

Sets a _waiting strategy_ for the _container_.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
