| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Docker::API::Exec; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Docker Engine Exec API |
|
3
|
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
72
|
use Moo; |
|
|
10
|
|
|
|
|
19
|
|
|
|
10
|
|
|
|
|
67
|
|
|
5
|
10
|
|
|
10
|
|
4132
|
use Carp qw( croak ); |
|
|
10
|
|
|
|
|
21
|
|
|
|
10
|
|
|
|
|
718
|
|
|
6
|
10
|
|
|
10
|
|
77
|
use namespace::clean; |
|
|
10
|
|
|
|
|
29
|
|
|
|
10
|
|
|
|
|
75
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.101'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $docker = WWW::Docker->new; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Create an exec instance |
|
15
|
|
|
|
|
|
|
my $exec = $docker->exec->create($container_id, |
|
16
|
|
|
|
|
|
|
Cmd => ['/bin/sh', '-c', 'echo hello'], |
|
17
|
|
|
|
|
|
|
AttachStdout => 1, |
|
18
|
|
|
|
|
|
|
AttachStderr => 1, |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Start the exec |
|
22
|
|
|
|
|
|
|
$docker->exec->start($exec->{Id}); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Inspect exec instance |
|
25
|
|
|
|
|
|
|
my $info = $docker->exec->inspect($exec->{Id}); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This module provides methods for executing commands inside running containers |
|
30
|
|
|
|
|
|
|
using the Docker Exec API. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Accessed via C<< $docker->exec >>. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has client => ( |
|
37
|
|
|
|
|
|
|
is => 'ro', |
|
38
|
|
|
|
|
|
|
required => 1, |
|
39
|
|
|
|
|
|
|
weak_ref => 1, |
|
40
|
|
|
|
|
|
|
); |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=attr client |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Reference to L client. Weak reference to avoid circular dependencies. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub create { |
|
49
|
0
|
|
|
0
|
0
|
|
my ($self, $container_id, %config) = @_; |
|
50
|
0
|
0
|
|
|
|
|
croak "Container ID required" unless $container_id; |
|
51
|
0
|
0
|
|
|
|
|
croak "Cmd required" unless $config{Cmd}; |
|
52
|
0
|
|
|
|
|
|
return $self->client->post("/containers/$container_id/exec", \%config); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=method create |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $exec = $docker->exec->create($container_id, |
|
58
|
|
|
|
|
|
|
Cmd => ['/bin/sh', '-c', 'echo hello'], |
|
59
|
|
|
|
|
|
|
AttachStdout => 1, |
|
60
|
|
|
|
|
|
|
AttachStderr => 1, |
|
61
|
|
|
|
|
|
|
Tty => 0, |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Create an exec instance. Returns hashref with C. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Required config: C (ArrayRef of command and arguments). |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Common config keys: C, C, C, C, |
|
69
|
|
|
|
|
|
|
C, C, C. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub start { |
|
74
|
0
|
|
|
0
|
0
|
|
my ($self, $exec_id, %opts) = @_; |
|
75
|
0
|
0
|
|
|
|
|
croak "Exec ID required" unless $exec_id; |
|
76
|
|
|
|
|
|
|
my $body = { |
|
77
|
|
|
|
|
|
|
Detach => $opts{Detach} ? \1 : \0, |
|
78
|
0
|
0
|
|
|
|
|
Tty => $opts{Tty} ? \1 : \0, |
|
|
|
0
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
}; |
|
80
|
0
|
|
|
|
|
|
return $self->client->post("/exec/$exec_id/start", $body); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=method start |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$exec->start($exec_id, Detach => 0); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Start an exec instance. Options: C, C. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub resize { |
|
92
|
0
|
|
|
0
|
0
|
|
my ($self, $exec_id, %opts) = @_; |
|
93
|
0
|
0
|
|
|
|
|
croak "Exec ID required" unless $exec_id; |
|
94
|
0
|
|
|
|
|
|
my %params; |
|
95
|
0
|
0
|
|
|
|
|
$params{h} = $opts{h} if defined $opts{h}; |
|
96
|
0
|
0
|
|
|
|
|
$params{w} = $opts{w} if defined $opts{w}; |
|
97
|
0
|
|
|
|
|
|
return $self->client->post("/exec/$exec_id/resize", undef, params => \%params); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=method resize |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$exec->resize($exec_id, h => 40, w => 120); |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Resize the TTY for an exec instance. Options: C (height), C (width). |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub inspect { |
|
109
|
0
|
|
|
0
|
0
|
|
my ($self, $exec_id) = @_; |
|
110
|
0
|
0
|
|
|
|
|
croak "Exec ID required" unless $exec_id; |
|
111
|
0
|
|
|
|
|
|
return $self->client->get("/exec/$exec_id/json"); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=method inspect |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $info = $exec->inspect($exec_id); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Get information about an exec instance. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=seealso |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=over |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * L - Main Docker client |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * L - Container management |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |