docker-maven-plugin
This docker-maven-plugin is a Maven plugin designed to make managing Docker images and containers from within Maven builds easy.
Goals Overview
- docker:start - Create and start docker containers
- docker:stop - Stop and remove docker containers
Usage
In order to use the docker-maven-plugin, you need to add the following configuration to your pom.xml file.
<project>
[...]
<build>
[...]
<plugins>
[...]
<plugin>
<groupId>com.github.chmodas</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.0.6</version>
<!-- common configuration shared by all executions -->
<configuration>
<url></url>
<pullImages>true</pullImages>
<images>
<image>
<name></name>
<repository></repository>
<tag></tag>
<ports>
<port></port>
</ports>
</image>
</images>
</configuration>
<executions>
<execution>
<phase></phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<phase></phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
</plugins>
[...]
</build>
[...]
</project>
General Configuration
Parameter | Description | Property | Default |
---|---|---|---|
url | URL to the Docker daemon API | docker.url | http://localhost:4243 |
version | Docker API version to use | docker.version | 1.15 |
prefix | Prefix used when naming containers | docker.prefix | project.artifactId |
images | List of image parameters for starting containers | docker.images | none |
pullImages | Pull the images or use local ones | docker.pullImages | true |
Image Configuration
Parameter | Description | Default |
---|---|---|
name | The name of the container, essential for container linking | none, required |
repository | Image repository (e.g. example.com/postgres, username/postgres) | none, required |
tag | The image repository tag | latest |
command | Command to execute inside the container on start | none |
ports | Collection of ports to publish | none |
ports/port | Docker exposed port to publish. Format is [hostPort:exposedPort] | none |
volumes | List of volumes to mount inside the container. (e.g. /volume, /host:/volume) | none |
links | List of links to containers | none |
wait | Sleep for given amount of seconds after container has been started | 0 |
hostname | Set the container hostname | the container id |
env | Set env variables inside a container (vv) | none |
Best Practices
While you have the ability to specify images to start / stop in the configuration section of the start and stop goals, this is probably not what you want to do. Defining all of your images in the general configuration section will ensure that all of the containers are started and stopped properly.