SYNOPSIS
# Containers are created via Testcontainers::run()
my $container = Testcontainers::run('nginx:alpine',
exposed_ports => ['80/tcp'],
);
# Get connection details
my $host = $container->host;
my $port = $container->mapped_port('80/tcp');
my $id = $container->id;
# Execute commands
my $result = $container->exec(['echo', 'hello']);
say $result->{output};
# Get logs
my $logs = $container->logs;
# Terminate
$container->terminate;
DESCRIPTION
Represents a running Docker container created by Testcontainers. Provides methods to interact with the container, get connection details, execute commands, and manage its lifecycle.
The Docker container ID.
The Docker image name used to create this container.
Refresh container information from Docker. Called automatically after start.
Returns the host address where the container is accessible. For local Docker, returns localhost. For remote Docker (tcp://), returns the remote host.
Returns the host port mapped to the given container port.
my $port = $container->mapped_port('80/tcp');
# or
my $port = $container->mapped_port('80'); # assumes /tcp
Returns a hashref with host_ip and host_port for the given container port.
Returns "host:port" string for the given container port.
my $addr = $container->endpoint('80/tcp');
# e.g., "localhost:32789"
Alias for id. Returns the Docker container ID.
Returns the container name (without leading /).
Returns the container state hashref. Refresh container info first.
Returns true if the container is currently running.
Get container logs. Options: stdout, stderr, tail, timestamps.
Execute a command in the container. $cmd is an ArrayRef or string. Returns hashref with exit_code and output.
my $result = $container->exec(['echo', 'hello']);
say $result->{output}; # "hello\n"
say $result->{exit_code}; # 0
Stop the container. Options: timeout.
Start the container if it was stopped.
Stop, remove the container and its volumes. Safe to call multiple times.
SEE ALSO
Testcontainers - Main module
Testcontainers::Wait - Wait strategies
16 POD Errors
The following errors were encountered while parsing the POD:
- Around line 47:
Unknown directive: =attr
- Around line 58:
Unknown directive: =attr
- Around line 115:
Unknown directive: =method
- Around line 135:
Unknown directive: =method
- Around line 155:
Unknown directive: =method
- Around line 177:
Unknown directive: =method
- Around line 193:
Unknown directive: =method
- Around line 207:
Unknown directive: =method
- Around line 220:
Unknown directive: =method
- Around line 234:
Unknown directive: =method
- Around line 247:
Unknown directive: =method
- Around line 258:
Unknown directive: =method
- Around line 269:
Unknown directive: =method
- Around line 286:
Unknown directive: =method
- Around line 299:
Unknown directive: =method
- Around line 318:
Unknown directive: =method