/
DockerContainers.java
64 lines (54 loc) · 1.82 KB
/
DockerContainers.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
package com.adambarreiro.docker.client.api;
import com.adambarreiro.docker.client.exception.DockerException;
import java.util.regex.Pattern;
/**
* Create and manage containers.
*/
public interface DockerContainers {
Pattern VALID_CONTAINER_NAME = Pattern.compile("^[a-zA-Z0-9][a-zA-Z0-9_.-]+$");
/**
* Creates a container with given name and image.
*
* @param name name of the container. Must match {@see VALID_CONTAINER_NAME}, otherwise a default one will be picked.
* @param image image name with tag. For example: 'ubuntu:latest'.
* @return the ID of the created container.
* @throws DockerException if something went wrong.
*/
String create(String name, String image) throws DockerException;
/**
* Starts a container with given ID.
*
* @param containerId ID of the previously created container.
* @throws DockerException if something went wrong.
*/
void start(String containerId) throws DockerException;
/**
* Creates an exec in the given container.
*
* @param containerId the ID of the container.
* @param command the command to run.
* @return the ID of the created exec.
* @throws DockerException if something went wrong.
*/
String exec(String containerId, String command) throws DockerException;
/**
* Stops a running container.
*
* @param containerId the ID of the container.
* @throws DockerException if something went wrong.
*/
void stop(String containerId) throws DockerException;
/**
* Deletes a stopped container.
*
* @param containerId the ID of the container.
* @throws DockerException if something went wrong.
*/
void remove(String containerId) throws DockerException;
/**
* Removes all stopped containers. Take into account that they need to be stopped first.
*
* @throws DockerException if something went wrong.
*/
void prune() throws DockerException;
}