Testcontainers (testcontainers v1.13.4)
View SourceThe main entry point into Testcontainers.
This is a GenServer that needs to be started before anything can happen.
Summary
Functions
Returns a specification to start this module under a supervisor.
Starts the Testcontainers application.
Starts a new container based on the provided configuration, applying any specified wait strategies.
Starts the Testcontainers application.
Stops a running container.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Starts the Testcontainers application.
This will NOT terminate when the calling process exits, for ex a task.
Starts a new container based on the provided configuration, applying any specified wait strategies.
This function performs several steps:
- Pulls the necessary Docker image.
- Creates and starts a container with the specified configuration.
- Registers the container with a reaper process for automatic cleanup, ensuring it is stopped and removed when the current process exits or in case of unforeseen failures.
Parameters
config
: A%Container{}
struct containing the configuration settings for the container, such as the image to use, environment variables, bound ports, and volume bindings.
Examples
iex> config = Testcontainers.MySqlContainer.new()
iex> {:ok, container} = Testcontainers.start_container(config)
Returns
{:ok, container}
if the container is successfully created, started, and passes all wait strategies.- An error tuple, such as
{:error, reason}
, if there is a failure at any step in the process.
Notes
- The container is automatically registered with a reaper process, ensuring it is stopped and removed when the current process exits, or in the case of unforeseen failures.
- It's important to specify appropriate wait strategies to ensure the container is fully ready for interaction, especially for containers that may take some time to start up services internally.
Starts the Testcontainers application.
This will terminate when the calling process exits, for ex a task.
Stops a running container.
This sends a stop command to the specified container. The Docker daemon terminates the container process gracefully.
Parameters
container_id
: The ID of the container to stop, as a string.
Returns
:ok
if the container stops successfully.{:error, reason}
on failure.
Examples
:ok = Testcontainers.Connection.stop_container("my_container_id")