| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Docker; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Perl client for the Docker Engine API |
|
3
|
|
|
|
|
|
|
|
|
4
|
10
|
|
|
10
|
|
2823186
|
use Moo; |
|
|
10
|
|
|
|
|
63357
|
|
|
|
10
|
|
|
|
|
60
|
|
|
5
|
10
|
|
|
10
|
|
14294
|
use Carp qw( croak ); |
|
|
10
|
|
|
|
|
21
|
|
|
|
10
|
|
|
|
|
571
|
|
|
6
|
10
|
|
|
10
|
|
3687
|
use Log::Any qw( $log ); |
|
|
10
|
|
|
|
|
72948
|
|
|
|
10
|
|
|
|
|
74
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.101'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
23488
|
use WWW::Docker::API::System; |
|
|
10
|
|
|
|
|
57
|
|
|
|
10
|
|
|
|
|
372
|
|
|
11
|
10
|
|
|
10
|
|
5752
|
use WWW::Docker::API::Containers; |
|
|
10
|
|
|
|
|
43
|
|
|
|
10
|
|
|
|
|
425
|
|
|
12
|
10
|
|
|
10
|
|
5958
|
use WWW::Docker::API::Images; |
|
|
10
|
|
|
|
|
39
|
|
|
|
10
|
|
|
|
|
394
|
|
|
13
|
10
|
|
|
10
|
|
5541
|
use WWW::Docker::API::Networks; |
|
|
10
|
|
|
|
|
56
|
|
|
|
10
|
|
|
|
|
480
|
|
|
14
|
10
|
|
|
10
|
|
7017
|
use WWW::Docker::API::Volumes; |
|
|
10
|
|
|
|
|
46
|
|
|
|
10
|
|
|
|
|
441
|
|
|
15
|
10
|
|
|
10
|
|
5486
|
use WWW::Docker::API::Exec; |
|
|
10
|
|
|
|
|
38
|
|
|
|
10
|
|
|
|
|
6980
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use WWW::Docker; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Connect to local Docker daemon via Unix socket |
|
22
|
|
|
|
|
|
|
my $docker = WWW::Docker->new; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Or connect to remote Docker daemon |
|
25
|
|
|
|
|
|
|
my $docker = WWW::Docker->new( |
|
26
|
|
|
|
|
|
|
host => 'tcp://192.168.1.100:2375', |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# System information |
|
30
|
|
|
|
|
|
|
my $info = $docker->system->info; |
|
31
|
|
|
|
|
|
|
my $version = $docker->system->version; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Container management |
|
34
|
|
|
|
|
|
|
my $containers = $docker->containers->list(all => 1); |
|
35
|
|
|
|
|
|
|
my $result = $docker->containers->create( |
|
36
|
|
|
|
|
|
|
Image => 'nginx:latest', |
|
37
|
|
|
|
|
|
|
name => 'my-nginx', |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
$docker->containers->start($result->{Id}); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Image operations |
|
42
|
|
|
|
|
|
|
$docker->images->pull(fromImage => 'nginx', tag => 'latest'); |
|
43
|
|
|
|
|
|
|
my $images = $docker->images->list; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Network and volume management |
|
46
|
|
|
|
|
|
|
my $networks = $docker->networks->list; |
|
47
|
|
|
|
|
|
|
my $volumes = $docker->volumes->list; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
WWW::Docker is a Perl client for the Docker Engine API. It provides a clean |
|
52
|
|
|
|
|
|
|
object-oriented interface to manage Docker containers, images, networks, and |
|
53
|
|
|
|
|
|
|
volumes. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Key features: |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item * Pure Perl implementation with minimal dependencies |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item * Unix socket and TCP transport support |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item * Automatic API version negotiation |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item * Object-oriented entity classes (Container, Image, Network, Volume) |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item * Comprehensive logging via L |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=back |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 Architecture |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The distribution is organized into several layers: |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * B - L - Entry point with API version negotiation |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item * B - Resource-specific API methods: |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=over |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item * L - System info, version, ping |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * L - Container management |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item * L - Image management |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item * L - Network management |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * L - Volume management |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item * L - Exec into containers |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * B - Object wrappers for Docker resources: |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * L - Container entity with convenience methods |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * L - Image entity |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * L - Network entity |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * L - Volume entity |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * B - L - HTTP transport layer |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
has host => ( |
|
118
|
|
|
|
|
|
|
is => 'ro', |
|
119
|
|
|
|
|
|
|
default => sub { $ENV{DOCKER_HOST} // 'unix:///var/run/docker.sock' }, |
|
120
|
|
|
|
|
|
|
); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=attr host |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Docker daemon connection URL. Defaults to C<$ENV{DOCKER_HOST}> or |
|
125
|
|
|
|
|
|
|
C. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Supported formats: |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * C - Unix socket (default) |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * C - TCP connection |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
has api_version => ( |
|
140
|
|
|
|
|
|
|
is => 'rwp', |
|
141
|
|
|
|
|
|
|
default => undef, |
|
142
|
|
|
|
|
|
|
); |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=attr api_version |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Docker API version to use (e.g., C<1.41>). If not set, the client will |
|
147
|
|
|
|
|
|
|
automatically negotiate the highest API version supported by the daemon. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
This attribute is set automatically by L. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
has tls => ( |
|
154
|
|
|
|
|
|
|
is => 'ro', |
|
155
|
|
|
|
|
|
|
default => 0, |
|
156
|
|
|
|
|
|
|
); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=attr tls |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Enable TLS for secure connections. Defaults to C<0>. Currently experimental. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
has cert_path => ( |
|
165
|
|
|
|
|
|
|
is => 'ro', |
|
166
|
|
|
|
|
|
|
default => sub { $ENV{DOCKER_CERT_PATH} }, |
|
167
|
|
|
|
|
|
|
); |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=attr cert_path |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Path to TLS certificates. Defaults to C<$ENV{DOCKER_CERT_PATH}>. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
has _version_negotiated => ( |
|
176
|
|
|
|
|
|
|
is => 'rw', |
|
177
|
|
|
|
|
|
|
default => 0, |
|
178
|
|
|
|
|
|
|
); |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
with 'WWW::Docker::Role::HTTP'; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
has system => ( |
|
183
|
|
|
|
|
|
|
is => 'lazy', |
|
184
|
7
|
|
|
7
|
|
2693
|
builder => sub { WWW::Docker::API::System->new(client => $_[0]) }, |
|
185
|
|
|
|
|
|
|
); |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=attr system |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Returns L instance for system operations like |
|
190
|
|
|
|
|
|
|
C, C, C, and C. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
has containers => ( |
|
195
|
|
|
|
|
|
|
is => 'lazy', |
|
196
|
4
|
|
|
4
|
|
2583
|
builder => sub { WWW::Docker::API::Containers->new(client => $_[0]) }, |
|
197
|
|
|
|
|
|
|
); |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=attr containers |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Returns L instance for container operations like |
|
202
|
|
|
|
|
|
|
C, C, C, C, and C. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
has images => ( |
|
207
|
|
|
|
|
|
|
is => 'lazy', |
|
208
|
8
|
|
|
8
|
|
3291
|
builder => sub { WWW::Docker::API::Images->new(client => $_[0]) }, |
|
209
|
|
|
|
|
|
|
); |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=attr images |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Returns L instance for image operations like |
|
214
|
|
|
|
|
|
|
C, C, C, and C. |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
has networks => ( |
|
219
|
|
|
|
|
|
|
is => 'lazy', |
|
220
|
5
|
|
|
5
|
|
2741
|
builder => sub { WWW::Docker::API::Networks->new(client => $_[0]) }, |
|
221
|
|
|
|
|
|
|
); |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=attr networks |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Returns L instance for network operations like |
|
226
|
|
|
|
|
|
|
C, C, C, and C. |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
has volumes => ( |
|
231
|
|
|
|
|
|
|
is => 'lazy', |
|
232
|
4
|
|
|
4
|
|
2442
|
builder => sub { WWW::Docker::API::Volumes->new(client => $_[0]) }, |
|
233
|
|
|
|
|
|
|
); |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=attr volumes |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
Returns L instance for volume operations like |
|
238
|
|
|
|
|
|
|
C, C, and C. |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
has exec => ( |
|
243
|
|
|
|
|
|
|
is => 'lazy', |
|
244
|
1
|
|
|
1
|
|
2113
|
builder => sub { WWW::Docker::API::Exec->new(client => $_[0]) }, |
|
245
|
|
|
|
|
|
|
); |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=attr exec |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Returns L instance for executing commands in containers. |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub negotiate_version { |
|
254
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
255
|
0
|
0
|
|
|
|
|
return if $self->_version_negotiated; |
|
256
|
0
|
0
|
|
|
|
|
return if defined $self->api_version; |
|
257
|
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
$log->debug("Auto-negotiating API version"); |
|
259
|
0
|
|
|
|
|
|
my $version_info = $self->_request('GET', '/version'); |
|
260
|
0
|
0
|
0
|
|
|
|
if ($version_info && $version_info->{ApiVersion}) { |
|
261
|
0
|
|
|
|
|
|
$self->_set_api_version($version_info->{ApiVersion}); |
|
262
|
0
|
|
|
|
|
|
$log->debugf("Negotiated API version: %s", $version_info->{ApiVersion}); |
|
263
|
|
|
|
|
|
|
} |
|
264
|
0
|
|
|
|
|
|
$self->_version_negotiated(1); |
|
265
|
|
|
|
|
|
|
} |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=method negotiate_version |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
$docker->negotiate_version; |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Automatically negotiate the highest API version supported by the Docker daemon. |
|
272
|
|
|
|
|
|
|
This is called automatically before the first API request if L |
|
273
|
|
|
|
|
|
|
is not set. |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
After negotiation, L will contain the negotiated version |
|
276
|
|
|
|
|
|
|
(e.g., C<1.41>). |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=cut |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
around _request => sub { |
|
281
|
|
|
|
|
|
|
my ($orig, $self, $method, $path, %opts) = @_; |
|
282
|
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
# Auto-negotiate before any versioned request, but not for /version itself |
|
284
|
|
|
|
|
|
|
if ($path ne '/version' && !defined $self->api_version && !$self->_version_negotiated) { |
|
285
|
|
|
|
|
|
|
$self->negotiate_version; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
return $self->$orig($method, $path, %opts); |
|
289
|
|
|
|
|
|
|
}; |
|
290
|
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 ENVIRONMENT VARIABLES |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=over |
|
294
|
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item C |
|
296
|
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Docker daemon connection URL. Used as default for L if not explicitly set. |
|
298
|
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Examples: C, C |
|
300
|
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=item C |
|
302
|
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
Path to TLS certificates directory. Used as default for L. |
|
304
|
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=back |
|
306
|
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=seealso |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=over |
|
310
|
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=item * L - HTTP transport implementation |
|
312
|
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=item * L - System and daemon operations |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=item * L - Container management |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=item * L - Image management |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=item * L - Network management |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=item * L - Volume management |
|
322
|
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=item * L - Execute commands in containers |
|
324
|
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=back |
|
326
|
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=cut |
|
328
|
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
1; |