class DockerContainer extends java.lang.Object
The DockerContainer encapsulates interaction with the
docker and docker-compose commands for
use in Gradle build scripts.
I manage environments for different projects in different collections of Docker containers.
I find it convenient to start and stop these containers from Gradle. In addition, tasks that require the containers should be able to check that they are running.
This Gradle plugin simple encapsulates those interactions. It doesn’t do anything very sophisticated with Docker or any of the Docker APIs.
| Type Params | Return Type | Name and description |
|---|---|---|
|
static boolean |
allRunning(java.util.ArrayList<java.lang.String> names)Test if all of a list of containers are running. |
|
static boolean |
anyRunning(java.util.ArrayList<java.lang.String> names)Test if any of a list of containers are running. |
|
static void |
assertDockerAvailable()Assert that docker is available. |
|
static void |
assertDockerComposeAvailable()Assert that docker-compose is available. |
|
static void |
assertNotRunning(java.lang.String name)Assert that the container named name is not running. |
|
static void |
assertNotRunning(java.util.ArrayList<java.lang.String> names)Assert that none of the named container are running. |
|
static void |
assertRunning(java.lang.String name)Assert that the container named name running. |
|
static void |
assertRunning(java.util.ArrayList<java.lang.String> names)Assert that the named containers are (all) running. |
|
static void |
compose(groovy.lang.Closure cl)Evaluate a docker compose command. |
|
static java.util.HashMap<java.lang.String, java.lang.String> |
containers()Get the running containers and their IDs. |
|
static java.lang.String |
docker()Where is docker? |
|
static void |
docker(groovy.lang.Closure cl)Evaluate a docker command. |
|
static java.lang.String |
dockerCompose()Where is docker-compose? |
|
static java.lang.String |
id(java.lang.String name)Find the ID of a running container. |
|
static boolean |
running(java.lang.String name)Test if a container is running. |
|
protected static void |
setProject(org.gradle.api.Project proj) |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Test if all of a list of containers are running.
This method takes a list of the names of containers
and checks to see if they are all running. Most underlying
docker commands use the container ID, but those are
essentially random. The name can be set in the
docker-compose.yaml file to something that is
stable.
names - The list of names of containers.Test if any of a list of containers are running.
This method takes a list of the names of containers
and checks to see if any of them are running. Most
underlying docker commands use the container ID, but
those are essentially random. The name can be set in the
docker-compose.yaml file to something that is
stable.
names - The list of names of containers. Assert that docker is available.
This method raises an exception if docker could not
be found on the user's path. It's just a convenience to avoid having
to write the test and raise the exception yourself in the build script.
Assert that docker-compose is available.
This method raises an exception if docker-compose could not
be found on the user's path. It's just a convenience to avoid having
to write the test and raise the exception yourself in the build script.
Assert that the container named name is not running.
This method raises an exception if the named container is running. It's just a convenience to avoid having to write the test and raise the exception yourself in the build script.
Assert that none of the named container are running.
This method raises an exception if any of the named containers are running. It's just a convenience to avoid having to write the test and raise the exception yourself in the build script.
Assert that the container named name running.
This method raises an exception if the named container is not running. It's just a convenience to avoid having to write the test and raise the exception yourself in the build script.
Assert that the named containers are (all) running.
This method raises an exception if any of the named containers is not running. It's just a convenience to avoid having to write the test and raise the exception yourself in the build script.
Evaluate a docker compose command.
cl - The closure containing the environmentGet the running containers and their IDs.
This method returns a map where the keys are all the names of running containers. The value associated with each key is the ID of the corresponding container.
Where is docker?
docker executable,
or null if it could not be found on the user's PATH.Evaluate a docker command.
cl - The closure containing the environment Where is docker-compose?
docker-compose executable
or the word "docker" if the compose command is a subcommand of docker.
Returns null if it could not be found on the user's PATH.Find the ID of a running container.
This method takes the name of a container and checks
to see if that container is running. If it is, it returns the ID
of the container. In most cases, this ID will be needed to
interact with the container using the docker command.
name - The name of a container.Test if a container is running.
This method takes the name of a container and checks to see
if that container is running. Most underlying docker commands use
the container ID, but those are essentially random. The name can be set in the
docker-compose.yaml file to something that is stable.
name - The name of a container.