API-Docker
view release on metacpan or search on metacpan
lib/API/Docker/API/Images.pm view on Meta::CPAN
%{ $self->_request_options },
);
}
sub build_prune {
my ($self, %opts) = @_;
my %params;
# The engine spells this one with a hyphen, and an unquoted
# `keep-storage => $n` is not even valid Perl -- the fat comma quotes a
# bareword identifier, and keep-storage is a subtraction. So keep_storage is
# the documented spelling, the wire name is accepted beside it for anyone
# copying out of the Engine reference, and the hyphen is what goes on the
# wire. _uri_encode leaves `-` alone, so the key survives unmangled.
my $keep_storage = $opts{keep_storage} // $opts{'keep-storage'};
$params{'keep-storage'} = $keep_storage if defined $keep_storage;
$params{all} = $opts{all} ? 1 : 0 if defined $opts{all};
$params{filters} = $self->_normalise_filters($opts{filters})
if defined $opts{filters};
return $self->client->post('/build/prune', undef,
params => \%params,
%{ $self->_request_options },
);
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
API::Docker::API::Images - Docker Engine Images API
=head1 VERSION
version 0.004
=head1 SYNOPSIS
my $docker = API::Docker->new;
# Build an image from a tar context
use Path::Tiny;
my $tar = path('context.tar')->slurp_raw;
$docker->images->build(context => $tar, t => 'myapp:latest');
# Pull an image
$docker->images->pull(fromImage => 'nginx', tag => 'latest');
# List images
my $images = $docker->images->list;
for my $image (@$images) {
say $image->id;
say join ', ', @{$image->repo_tags};
}
# Inspect image details
my $image = $docker->images->inspect('nginx:latest');
# Tag and push
$docker->images->tag('nginx:latest', repo => 'myrepo/nginx', tag => 'v1');
$docker->images->push('myrepo/nginx', tag => 'v1');
# Remove image
$docker->images->remove('nginx:latest', force => 1);
# Snapshot a container into an image
my $new = $docker->images->commit(container => $id, repo => 'myapp', tag => 'snap');
# Air-gapped roundtrip: export here, carry the tar over, load there
my $export = $docker->images->get('myapp:snap'); # raw tar bytes
$docker->images->load($export);
# Reclaim the build cache (not the same thing as prune)
$docker->images->build_prune(all => 1);
=head1 DESCRIPTION
This module provides methods for managing Docker images including pulling,
listing, tagging, pushing to registries, and removal.
C<list> and C<inspect> return generated L<API::Docker::Type> objects carrying
the convenience methods of L<API::Docker::Role::Entity::Image>, so
C<< $image->tag >> and C<< $image->remove >> work on either. Which class each
returns, and where the two disagree, is below.
Accessed via C<< $docker->images >>, or through
L<API::Docker::Role::Using/using> for a run of calls that needs its own
transport bound: C<< $docker->images->using(read_timeout => 5) >>.
=head2 The two image shapes
The daemon describes an image two ways and the swagger has two definitions
for it, so this class returns two classes:
=over
=item * L</list> returns L<API::Docker::Type::ImageSummary> objects -- one
per entry of C<GET /images/json>.
=item * L</inspect> returns an L<API::Docker::Type::ImageInspect> -- the body
of C<GET /images/{name}/json>.
=back
They overlap but do not line up, and the field names are the swagger's own
spelling in snake_case (C<Id> is C<< ->id >>, C<RepoTags> is
C<< ->repo_tags >>, C<SharedSize> is C<< ->shared_size >>). The differences
worth knowing before reading a value off the wrong one:
=over
=item * C<< ->created >> is an integer Unix epoch on a summary and an
RFC 3339 string on an inspect. Same field name, two types -- C<Int> and
( run in 1.270 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )