API-Docker

 view release on metacpan or  search on metacpan

lib/API/Docker/Container.pm  view on Meta::CPAN

package API::Docker::Container;
# ABSTRACT: Docker container entity
our $VERSION = '0.002';
use Moo;
use namespace::clean;


has client => (
  is       => 'ro',
  weak_ref => 1,
);


has Id            => (is => 'ro');


has Names         => (is => 'ro');


has Image         => (is => 'ro');


has ImageID       => (is => 'ro');
has Command       => (is => 'ro');
has Created       => (is => 'ro');


has State         => (is => 'ro');


has Status        => (is => 'ro');


has Ports         => (is => 'ro');
has Labels        => (is => 'ro');
has SizeRw        => (is => 'ro');
has SizeRootFs    => (is => 'ro');
has HostConfig    => (is => 'ro');
has NetworkSettings => (is => 'ro');
has Mounts        => (is => 'ro');

has Name          => (is => 'ro');


has RestartCount  => (is => 'ro');
has Driver        => (is => 'ro');
has Platform      => (is => 'ro');
has Path          => (is => 'ro');
has Args          => (is => 'ro');
has Config        => (is => 'ro');

sub start {
  my ($self) = @_;
  return $self->client->containers->start($self->Id);
}


sub stop {
  my ($self, %opts) = @_;
  return $self->client->containers->stop($self->Id, %opts);
}


sub restart {
  my ($self, %opts) = @_;
  return $self->client->containers->restart($self->Id, %opts);
}


sub kill {
  my ($self, %opts) = @_;
  return $self->client->containers->kill($self->Id, %opts);
}


sub remove {
  my ($self, %opts) = @_;
  return $self->client->containers->remove($self->Id, %opts);
}


sub logs {
  my ($self, %opts) = @_;
  return $self->client->containers->logs($self->Id, %opts);
}


sub inspect {
  my ($self) = @_;
  return $self->client->containers->inspect($self->Id);
}


sub pause {
  my ($self) = @_;
  return $self->client->containers->pause($self->Id);
}


sub unpause {
  my ($self) = @_;
  return $self->client->containers->unpause($self->Id);
}


sub top {
  my ($self, %opts) = @_;
  return $self->client->containers->top($self->Id, %opts);
}


sub stats {
  my ($self, %opts) = @_;
  return $self->client->containers->stats($self->Id, %opts);
}


sub is_running {
  my ($self) = @_;
  my $state = $self->State;
  return 0 unless defined $state;
  if (ref $state eq 'HASH') {
    return $state->{Running} ? 1 : 0;
  }
  return lc($state) eq 'running' ? 1 : 0;
}



1;

__END__

=pod

=encoding UTF-8

=head1 NAME

API::Docker::Container - Docker container entity

=head1 VERSION

version 0.002

=head1 SYNOPSIS

    my $docker = API::Docker->new;

    # Get container from list or inspect
    my $containers = $docker->containers->list;
    my $container = $containers->[0];

    # Access container properties
    say $container->Id;
    say $container->Status;
    say $container->Image;

    # Perform operations
    $container->start;
    $container->stop(timeout => 10);
    my $logs = $container->logs(tail => 100);
    $container->remove(force => 1);

    # Check state
    if ($container->is_running) {
        say "Container is running";
    }

=head1 DESCRIPTION

This class represents a Docker container and provides convenient access to
container properties and operations. Instances are returned by
L<API::Docker::API::Containers> methods like C<list> and C<inspect>.

Each attribute corresponds to fields in the Docker API container representation.
Methods delegate to L<API::Docker::API::Containers> for operations.



( run in 0.696 second using v1.01-cache-2.11-cpan-7fcb06a456a )