SYNOPSIS
my $docker = WWW::Docker->new;
# List containers
my $containers = $docker->containers->list(all => 1);
for my $container (@$containers) {
say $container->Id;
say $container->Status;
}
# Create and start a container
my $result = $docker->containers->create(
Image => 'nginx:latest',
name => 'my-nginx',
ExposedPorts => { '80/tcp' => {} },
);
$docker->containers->start($result->{Id});
# Inspect container details
my $container = $docker->containers->inspect($result->{Id});
say $container->Name;
# Stop and remove
$docker->containers->stop($result->{Id}, timeout => 10);
$docker->containers->remove($result->{Id});
# View logs
my $logs = $docker->containers->logs($result->{Id}, tail => 100);
DESCRIPTION
This module provides methods for managing Docker containers including creation, lifecycle operations (start, stop, restart), inspection, logs, and more.
All list and inspect methods return WWW::Docker::Container objects for convenient access to container properties and operations.
Accessed via $docker->containers.
Reference to WWW::Docker client. Weak reference to avoid circular dependencies.
my $containers = $containers->list(%opts);
List containers. Returns ArrayRef of WWW::Docker::Container objects.
Options:
all- Show all containers (default shows just running)limit- Limit results to N most recently created containerssize- Include size informationfilters- Hashref of filters
my $result = $containers->create(
Image => 'nginx:latest',
name => 'my-nginx',
Cmd => ['/bin/sh'],
Env => ['FOO=bar'],
);
Create a new container. Returns hashref with Id and Warnings.
The name parameter is extracted and passed as query parameter. All other parameters are Docker container configuration (see Docker API documentation).
Common config keys: Image, Cmd, Env, ExposedPorts, HostConfig.
my $container = $containers->inspect($id);
Get detailed information about a container. Returns WWW::Docker::Container object.
$containers->start($id);
Start a container.
$containers->stop($id, timeout => 10);
Stop a container.
Options:
timeout- Seconds to wait before killing (default 10)signal- Signal to send (default SIGTERM)
$containers->restart($id, timeout => 10);
Restart a container. Optionally specify timeout in seconds.
$containers->kill($id, signal => 'SIGKILL');
Send a signal to a container. Default signal is SIGKILL.
$containers->remove($id, force => 1, volumes => 1);
Remove a container.
Options:
force- Force removal (kill if running)volumes- Remove associated volumeslink- Remove specified link
my $logs = $containers->logs($id, tail => 100, timestamps => 1);
Get container logs.
Options:
stdout- Include stdout (default 1)stderr- Include stderr (default 1)since- Show logs since timestampuntil- Show logs before timestamptimestamps- Include timestampstail- Number of lines from end (e.g.,100orall)
my $processes = $containers->top($id, ps_args => 'aux');
List running processes in a container. Returns hashref with Titles and Processes arrays.
my $stats = $containers->stats($id);
Get container resource usage statistics (CPU, memory, network, I/O). Returns one-shot statistics.
my $result = $containers->wait($id, condition => 'not-running');
Block until container stops, then return exit code. Optional condition parameter.
$containers->pause($id);
Pause all processes in a container.
$containers->unpause($id);
Unpause all processes in a container.
$containers->rename($id, 'new-name');
Rename a container.
$containers->update($id, Memory => 314572800);
Update container resource limits and configuration.
my $result = $containers->prune(filters => { until => ['24h'] });
Delete stopped containers. Returns hashref with ContainersDeleted and SpaceReclaimed.
WWW::Docker - Main Docker client
WWW::Docker::Container - Container entity class
WWW::Docker::API::Exec - Execute commands in containers
19 POD Errors
The following errors were encountered while parsing the POD:
- Around line 59:
Unknown directive: =attr
- Around line 89:
Unknown directive: =method
- Around line 119:
Unknown directive: =method
- Around line 144:
Unknown directive: =method
- Around line 158:
Unknown directive: =method
- Around line 175:
Unknown directive: =method
- Around line 201:
Unknown directive: =method
- Around line 217:
Unknown directive: =method
- Around line 235:
Unknown directive: =method
- Around line 268:
Unknown directive: =method
- Around line 302:
Unknown directive: =method
- Around line 319:
Unknown directive: =method
- Around line 335:
Unknown directive: =method
- Around line 349:
Unknown directive: =method
- Around line 363:
Unknown directive: =method
- Around line 378:
Unknown directive: =method
- Around line 392:
Unknown directive: =method
- Around line 407:
Unknown directive: =method
- Around line 415:
Unknown directive: =seealso