Net-Docker

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

	[Improvement]
		- Allow setting docker host via env var DOCKER_HOST
		- Add name method to create method.

0.002004  2013-12-28 13:04:23 CET
	[Improvement]
		- Add support for Unix socket

0.002003  2013-08-05 22:15:57 CEST
	[Bug]
		- Fix 'streaming_logs' example

0.002002  2013-08-05 22:12:43 CEST
	[Improvement]
		- First try to write a docker-like command-line client

0.002001  2013-08-05 18:19:47 CEST
	[Improvement]
		- Add tests for 'run' methods

0.002000  2013-08-05 18:08:22 CEST
	[Improvement]
		- Add dependency for AnyEvent
		- Add dependency for AnyEvent-HTTP
		- Add start method
		- Add streaming_logs method

0.001001  2013-08-02 22:21:34 CEST
	[Improvement]
		- add `pull` method

0.001000  2013-08-02 21:55:18 CEST
	[Improvement]
		- Converted to Milla

README  view on Meta::CPAN

            Image       => 'ubuntu',
            Cmd         => ['/bin/bash'],
            AttachStdin => \1,
            OpenStdin   => \1,
            Name        => 'my-container',
        );

        say $id;
        $api->start($id);

        my $cv = $api->streaming_logs($id,
            stream => 1, logs   => 1,
            stdin  => 1, stderr => 1, stdout => 1,
            in_fh  => \*STDIN, out_fh => \*STDOUT,
        );
        $cv->recv;

DESCRIPTION
    Perl module for using the Docker Remote API.

AUTHOR

lib/Net/Docker.pm  view on Meta::CPAN

    my %params = (
        logs   => 1,
        stdout => 1,
        stderr => 1,
    );
    my $url = $self->_uri('/containers/'.$container.'/attach');
    my $res = $self->ua->post($url, \%params);
    return $res->content;
}

sub streaming_logs {
    my ($self, $container, %options) = @_;

    *STDOUT->autoflush(1);

    my $input  = delete $options{in_fh};
    my $output = delete $options{out_fh};

    my $cv = AnyEvent->condvar;

    my $in_hndl;

lib/Net/Docker.pm  view on Meta::CPAN

        Image       => 'ubuntu',
        Cmd         => ['/bin/bash'],
        AttachStdin => \1,
        OpenStdin   => \1,
        Name        => 'my-container',
    );

    say $id;
    $api->start($id);

    my $cv = $api->streaming_logs($id,
        stream => 1, logs   => 1,
        stdin  => 1, stderr => 1, stdout => 1,
        in_fh  => \*STDIN, out_fh => \*STDOUT,
    );
    $cv->recv;

=head1 DESCRIPTION

Perl module for using the Docker Remote API.

script/docker.pl  view on Meta::CPAN

        }
        print "\n";
    }
}
elsif ($ARGV[0] eq 'run') {
    my ($cmd, $image, @client_cmd) = @ARGV;

    my $id = $api->create(Image => $image, Cmd => \@client_cmd, AttachStdin => \1, OpenStdin => \1);
    $api->start($id);

    my $cv = $api->streaming_logs($id,
        stream => 1, 
        logs   => 1,
        stdin  => 1, stderr => 1, stdout => 1,
        in_fh  => \*STDIN,
        out_fh => \*STDOUT
    );
    $cv->recv;
}
elsif ($ARGV[0] eq 'attach') {
    my ($cmd, $id) = @ARGV;
    my $cv = $api->streaming_logs($id,
        stream => 1, 
        logs   => 1,
        stdin  => 1, stderr => 1, stdout => 1,
        in_fh  => \*STDIN,
        out_fh => \*STDOUT
    );
    $cv->recv;
}

t/docker-start.t  view on Meta::CPAN


## test named containers
my $named_id = $api->create(Cmd => ['echo', 'Hello world'], Image => 'ubuntu', Name => 'perl-test-' . int(rand(1000)+100));
my $ins = $api->inspect_container($named_id);
like($ins->{Name}, qr/^\/perl-test-\d+$/);

TODO: {
    local $TODO = 'needs anyevent http support for unix socket';

#    my $io = IO::String->new;
#    my $cv = $api->streaming_logs($id, stream => 1, logs => 1, stdout => 1, out_fh => $io, in_fh => \*STDIN);
#    $cv->recv;
#    is(${$io->string_ref}, "Hello world\r\n");
}

done_testing;



( run in 0.293 second using v1.01-cache-2.11-cpan-4d50c553e7e )