This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 552
/
DockerClient.java
875 lines (782 loc) · 29.7 KB
/
DockerClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
/*
* Copyright (c) 2014 Spotify AB.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.spotify.docker.client;
import com.spotify.docker.client.messages.AuthConfig;
import com.spotify.docker.client.messages.Container;
import com.spotify.docker.client.messages.ContainerConfig;
import com.spotify.docker.client.messages.ContainerCreation;
import com.spotify.docker.client.messages.ContainerExit;
import com.spotify.docker.client.messages.ContainerInfo;
import com.spotify.docker.client.messages.ContainerStats;
import com.spotify.docker.client.messages.ExecState;
import com.spotify.docker.client.messages.Image;
import com.spotify.docker.client.messages.ImageInfo;
import com.spotify.docker.client.messages.ImageSearchResult;
import com.spotify.docker.client.messages.Info;
import com.spotify.docker.client.messages.RemovedImage;
import com.spotify.docker.client.messages.Version;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Path;
import java.util.List;
/**
* A client for interacting with dockerd.
*
* Note: All methods throw DockerException on unexpected docker response status codes.
*/
public interface DockerClient extends Closeable {
/**
* Ping the docker daemon. Returns "OK" if all is well, though that
* it simply returns a 200 status is probably sufficient information.
* @return String "OK"
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
String ping() throws DockerException, InterruptedException;
/**
* Get the docker version.
*
* @return docker version
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
Version version() throws DockerException, InterruptedException;
/**
* Check auth configuration.
*
* @param authConfig The authentication config needed to pull the image.
* @return status code of auth request
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
int auth(final AuthConfig authConfig) throws DockerException, InterruptedException;
/**
* Get docker instance information.
*
* @return docker info
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
Info info() throws DockerException, InterruptedException;
/**
* List docker containers.
*
* @param params Container listing and filtering options.
* @return A list of containers.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
List<Container> listContainers(ListContainersParam... params)
throws DockerException, InterruptedException;
/**
* List docker images.
*
* @param params Image listing and filtering options.
* @return A list of images.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
List<Image> listImages(ListImagesParam... params) throws DockerException, InterruptedException;
/**
* Inspect a docker container.
*
* @param containerId The id of the container to inspect.
* @return Info about the container.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ContainerInfo inspectContainer(String containerId) throws DockerException, InterruptedException;
/**
* Create a new image from a container's changes.
*
* @param containerId The id of the container to commit.
* @param comment commit message.
* @param author image author.
* @param tag image tag.
* @param repo repository to commit to.
* @param config ContainerConfig to commit.
* @return ContainerCreation reply.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ContainerCreation commitContainer(final String containerId,
final String repo,
final String tag,
final ContainerConfig config,
final String comment,
final String author)
throws DockerException, InterruptedException;
/**
* Inspect a docker container image.
*
* @param image The image to inspect.
* @return Info about the image.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ImageInfo inspectImage(String image) throws DockerException, InterruptedException;
/**
* Remove a docker image.
*
* @param image The image to remove.
* @return A list describing each image which was removed.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
List<RemovedImage> removeImage(String image) throws DockerException, InterruptedException;
/**
* Remove a docker image.
*
* @param image The image to remove.
* @param force Force image removal.
* @param noPrune Do not delete untagged parents.
* @return A list describing each image which was removed.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
List<RemovedImage> removeImage(String image, boolean force, boolean noPrune)
throws DockerException, InterruptedException;
/**
* Search for images on Docker Hub
* @param term the search term
* @return a list of matches for the given search term
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
List<ImageSearchResult> searchImages(String term) throws DockerException, InterruptedException;
/**
* Pull a docker container image.
*
* @param image The image to pull.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void pull(String image) throws DockerException, InterruptedException;
/**
* Pull a docker container image, using a custom ProgressMessageHandler
*
* @param image The image to pull.
* @param handler The handler to use for processing each progress message received from Docker.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void pull(String image, ProgressHandler handler) throws DockerException, InterruptedException;
/**
* Pull a private docker container image.
*
* @param image The image to pull.
* @param authConfig The authentication config needed to pull the image.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void pull(String image, AuthConfig authConfig) throws DockerException, InterruptedException;
/**
* Pull a private docker container image, using a custom ProgressMessageHandler.
*
* @param image The image to pull.
* @param authConfig The authentication config needed to pull the image.
* @param handler The handler to use for processing each progress message received from Docker.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void pull(String image, AuthConfig authConfig, ProgressHandler handler)
throws DockerException, InterruptedException;
/**
* Push a docker container image.
*
* @param image The image to push.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void push(String image) throws DockerException, InterruptedException;
/**
* Push a docker container image, using a custom ProgressHandler
*
* @param image The image to push.
* @param handler The handler to use for processing each progress message received from Docker.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void push(String image, ProgressHandler handler) throws DockerException, InterruptedException;
/**
* Tag a docker image.
*
* @param image The image to tag.
* @param name The new name that will be applied to the image.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void tag(final String image, final String name) throws DockerException, InterruptedException;
/**
* Tag a docker image.
*
* @param image The image to tag.
* @param name The new name that will be applied to the image.
* @param force Whether to force the tagging even if the tag is already assigned to another image.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void tag(final String image, final String name, final boolean force)
throws DockerException, InterruptedException;
/**
* Build a docker image.
*
* @param directory The directory containing the dockerfile.
* @param params Additional flags to use during build.
* @return The id of the built image if successful, otherwise null.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
* @throws IOException If some IO shit happened.
*/
String build(final Path directory, final BuildParameter... params)
throws DockerException, InterruptedException, IOException;
/**
* Build a docker image.
*
* @param directory The directory containing the dockerfile.
* @param name The repository name and optional tag to apply to the built image.
* @param params Additional flags to use during build.
* @return The id of the built image if successful, otherwise null.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
* @throws IOException If some IO shit happened.
*/
String build(final Path directory, final String name, final BuildParameter... params)
throws DockerException, InterruptedException, IOException;
/**
* Build a docker image.
*
* @param directory The directory containing the dockerfile.
* @param handler The handler to use for processing each progress message received from Docker.
* @param params Additional flags to use during build.
* @return The id of the built image if successful, otherwise null.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
* @throws IOException If some IO shit happened.
*/
String build(final Path directory, final ProgressHandler handler, final BuildParameter... params)
throws DockerException, InterruptedException, IOException;
/**
* Build a docker image.
*
* @param directory The directory containing the dockerfile.
* @param name The repository name and optional tag to apply to the built image.
* @param handler The handler to use for processing each progress message received from Docker.
* @param params Additional flags to use during build.
* @return The id of the built image if successful, otherwise null.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
* @throws IOException If some IO shit happened.
*/
String build(final Path directory, final String name, final ProgressHandler handler,
final BuildParameter... params)
throws DockerException, InterruptedException, IOException;
/**
* Build a docker image.
*
* @param directory The directory containing the dockerfile.
* @param name The repository name and optional tag to apply to the built image.
* @param dockerfile The path within the build context to the Dockerfile
* @param handler The handler to use for processing each progress message received from Docker.
* @param params Additional flags to use during build.
* @return The id of the built image if successful, otherwise null.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
* @throws IOException If some IO shit happened.
*/
String build(final Path directory, final String name, final String dockerfile,
final ProgressHandler handler, final BuildParameter... params)
throws DockerException, InterruptedException, IOException;
/**
* Flags which can be passed to the <code>build</code> method.
*/
enum BuildParameter {
/** Suppress verbose build output. */
QUIET("q", true),
/** Do not use the cache when building the image. */
NO_CACHE("nocache", true),
/** Do remove intermediate containers after a successful build. */
RM("rm", true),
/** Do not remove intermediate containers after a successful build. */
NO_RM("rm", false),
/** Always remove intermediate containers. */
FORCE_RM("forcerm", true),
/** Always attempt to pull a newer version of the base image even if one exists locally. */
PULL_NEWER_IMAGE("pull", true);
final String buildParamName;
final boolean buildParamValue;
private BuildParameter(final String buildParamName, final boolean buildParamValue) {
this.buildParamName = buildParamName;
this.buildParamValue = buildParamValue;
}
/**
* @return the {@link BuildParameter} value
*/
public boolean getParamValue() {
return this.buildParamValue;
}
}
/**
* Create a docker container.
*
* @param config The container configuration.
* @return Container creation result with container id and eventual warnings from docker.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ContainerCreation createContainer(ContainerConfig config)
throws DockerException, InterruptedException;
/**
* Create a docker container.
*
* @param config The container configuration.
* @param name The container name.
* @return Container creation result with container id and eventual warnings from docker.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ContainerCreation createContainer(ContainerConfig config, String name)
throws DockerException, InterruptedException;
/**
* Start a docker container.
*
* @param containerId The id of the container to start.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void startContainer(String containerId) throws DockerException, InterruptedException;
/**
* Stop a docker container by sending a SIGTERM, and following up with a SIGKILL if the
* container doesn't exit gracefully and in a timely manner.
*
* @param containerId The id of the container to stop.
* @param secondsToWaitBeforeKilling Time to wait after SIGTERM before sending SIGKILL.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void stopContainer(String containerId, int secondsToWaitBeforeKilling)
throws DockerException, InterruptedException;
/**
* Pause a docker container.
*
* @param containerId The id of the container to pause.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void pauseContainer(String containerId) throws DockerException, InterruptedException;
/**
* Unpause a docker container.
*
* @param containerId The id of the container to pause.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void unpauseContainer(String containerId) throws DockerException, InterruptedException;
/**
* Restart a docker container. with a 10 second default wait
*
* @param containerId The id of the container to restart.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void restartContainer(String containerId) throws DockerException, InterruptedException;
/**
* Restart a docker container.
*
* @param containerId The id of the container to restart.
* @param secondsToWaitBeforeRestart number of seconds to wait before killing the container.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void restartContainer(String containerId, int secondsToWaitBeforeRestart)
throws DockerException, InterruptedException;
/**
* Wait for a docker container to exit.
*
* @param containerId The id of the container to wait for.
* @return Exit response with status code.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ContainerExit waitContainer(String containerId) throws DockerException, InterruptedException;
/**
* Kill a docker container.
*
* @param containerId The id of the container to kill.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void killContainer(String containerId) throws DockerException, InterruptedException;
/**
* Remove a docker container.
*
* @param containerId The id of the container to remove.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void removeContainer(String containerId) throws DockerException, InterruptedException;
/**
* Remove a docker container.
*
* @param containerId The id of the container to remove.
* @param removeVolumes Whether to remove volumes as well.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void removeContainer(String containerId, boolean removeVolumes)
throws DockerException, InterruptedException;
/**
* Export a docker container as a tar archive.
*
* @param containerId The id of the container to export.
* @return A stream in tar format that contains the contents of the container file system.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
InputStream exportContainer(String containerId) throws DockerException, InterruptedException;
/**
* Copies some files out of a container.
*
* @param containerId The id of the container to copy files from.
* @param path The path inside of the container to copy. If this is a directory, it will
* be copied recursively. If this is a file, only that file will be copied.
* @return A stream in tar format that contains the copied files. If a directory was copied, the
* directory will be at the root of the tar archive (so {@code copy(..., "/usr/share")} will
* result in a directory called {@code share} in the tar archive). The directory name is
* completely resolved, so copying {@code "/usr/share/././."} will still create a directory called
* {@code "share"} in the tar archive. If a single file was copied, that file will be the sole
* entry in the tar archive. Copying {@code "."} or equivalently {@code "/"} will result in the
* tar archive containing a single folder named after the container ID.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
InputStream copyContainer(String containerId, String path)
throws DockerException, InterruptedException;
/**
* Get docker container logs.
*
* @param containerId The id of the container to get logs for.
* @param params Params for controlling what streams to get and whether to tail or not.
* @return A log message stream.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
LogStream logs(String containerId, LogsParameter... params)
throws DockerException, InterruptedException;
/**
* Sets up an exec instance in a running container id.
*
* @param containerId The id of the container
* @param cmd shell command
* @param params Exec params
* @return exec id
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
String execCreate(String containerId, String[] cmd, ExecParameter... params)
throws DockerException, InterruptedException;
/**
* Supported parameters for {@link #execCreate}
*/
public static enum ExecParameter {
STDOUT("AttachStdout"),
STDERR("AttachStderr");
private final String name;
ExecParameter(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
/**
* Starts a previously set up exec instance id.
* If detach is true, this API returns after starting the exec command.
* Otherwise, this API sets up an interactive session with the exec command.
*
* @param execId exec id
* @param params Exec start params
* @return exec output
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
LogStream execStart(String execId, ExecStartParameter... params)
throws DockerException, InterruptedException;
/**
* Supported parameters for {@link #execStart}
*/
public static enum ExecStartParameter {
DETACH("Detach");
private final String name;
ExecStartParameter(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
/**
* Inspects a running or previously run exec instance id.
*
* @param execId exec id
* @return state of this exec instance.
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ExecState execInspect(String execId) throws DockerException, InterruptedException;
/**
* Retrieves one-time stats (stream=0) for the container with the specified id.
*
* @param containerId The id of the container to retrieve stats for.
* @return The container stats
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
ContainerStats stats(String containerId) throws DockerException, InterruptedException;
/**
* Closes any and all underlying connections to docker, and release resources.
*/
@Override
void close();
/**
* Parameters for {@link #logs(String, LogsParameter...)}
*/
public static enum LogsParameter {
FOLLOW,
STDOUT,
STDERR,
TIMESTAMPS,
}
/**
* Parameters for {@link #attachContainer(String, AttachParameter...)}
*/
public static enum AttachParameter {
LOGS,
STREAM,
STDIN,
STDOUT,
STDERR
}
/**
* Attach to the container id
* @param containerId The id of the container to get logs for.
* @param params Params for controlling what streams to get and whether to tail or not.
* @return A log message stream.
* @throws ContainerNotFoundException if the container was not found (404).
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
LogStream attachContainer(String containerId, AttachParameter... params)
throws DockerException, InterruptedException;
/**
* Get the Docker host address
* @return the docker host name or IP
*/
String getHost();
/**
* Parameters for {@link #listContainers(ListContainersParam...)}
*/
public static class ListContainersParam {
private final String name;
private final String value;
public ListContainersParam(final String name, final String value) {
this.name = name;
this.value = value;
}
/**
* Parameter name.
*
* @return name of parameter
*/
public String name() {
return name;
}
/**
* Parameter value.
*
* @return value of parameter
*/
public String value() {
return value;
}
/**
* Show all containers. Only running containers are shown by default
*
* @return ListContainersParam
*/
public static ListContainersParam allContainers() {
return allContainers(true);
}
/**
* Show all containers. Only running containers are shown by default
*
* @param all Whether to show all containers
* @return ListContainersParam
*/
public static ListContainersParam allContainers(final boolean all) {
return create("all", all ? "1" : "0");
}
/**
* Show exited containers.
*
* @return ListContainersParam
*/
public static ListContainersParam exitedContainers() throws UnsupportedEncodingException {
return create("filters", URLEncoder.encode("{\"status\":[\"exited\"]}", "UTF-8"));
}
/**
* Show <code>limit</code> last created containers, include non-running ones.
*
* @param limit Limit for number of containers to list
* @return ListContainersParam
*/
public static ListContainersParam limitContainers(final Integer limit) {
return create("limit", String.valueOf(limit));
}
/**
* Show only containers created since id, include non-running ones.
*
* @param id container ID
* @return ListContainersParam
*/
public static ListContainersParam containersCreatedSince(final String id) {
return create("since", String.valueOf(id));
}
/**
* Show only containers created before id, include non-running ones.
*
* @param id container ID
* @return ListContainersParam
*/
public static ListContainersParam containersCreatedBefore(final String id) {
return create("before", String.valueOf(id));
}
/**
* Show the containers sizes.
*
* @param size Whether to show container sizes
* @return ListContainersParam
*/
public static ListContainersParam withContainerSizes(final Boolean size) {
return create("size", String.valueOf(size));
}
/**
* Create a custom parameter.
*
* @param name custom name
* @param value custom value
* @return ListContainersParam
*/
public static ListContainersParam create(final String name, final String value) {
return new ListContainersParam(name, value);
}
}
/**
* Parameters for {@link #listImages(ListImagesParam...)}
*/
public static class ListImagesParam {
private final String name;
private final String value;
public ListImagesParam(final String name, final String value) {
this.name = name;
this.value = value;
}
/**
* Parameter name.
*
* @return name of parameter
*/
public String name() {
return name;
}
/**
* Parameter value.
*
* @return value of parameter
*/
public String value() {
return value;
}
/**
* Show all images. Only intermediate image layers are shown by default.
*
* @return ListImagesParam
*/
public static ListImagesParam allImages() {
return allImages(true);
}
/**
* Show all images. Only intermediate image layers are shown by default.
*
* @param all Whether to list all images
* @return ListImagesParam
*/
public static ListImagesParam allImages(final boolean all) {
return create("all", String.valueOf(all));
}
/**
* Show dangling images only. A dangling image is one which does not have a repository name.
* By default both dangling and non-dangling will be shown.
*
* @return ListImagesParam
*/
public static ListImagesParam danglingImages() {
return danglingImages(true);
}
/**
* Enable or disable dangling image filter.
*
* @param dangling Whether to list dangling images
* @return ListImagesParam
*/
public static ListImagesParam danglingImages(final boolean dangling) {
return filter("dangling", String.valueOf(dangling));
}
/**
* Create a custom filter.
*
* @param name of filter
* @param value of filter
* @return ListImagesParam
*/
public static ListImagesParam filter(final String name, final String value) {
return new ListImagesFilterParam(name, value);
}
/**
* Create a custom parameter.
*
* @param name of parameter
* @param value of parameter
* @return ListImagesParam
*/
public static ListImagesParam create(final String name, final String value) {
return new ListImagesParam(name, value);
}
}
/**
* Filter parameter for {@link #listImages(ListImagesParam...)}. This should be used by
* ListImagesParam only.
*/
static class ListImagesFilterParam extends ListImagesParam {
public ListImagesFilterParam(String name, String value) {
super(name, value);
}
}
}