There are two different modes how Images can be built:
With an inline plugin configuration all information required to build the image is contained in the plugin configuration. By default its the standard XML based configuration for the plugin but can be switched to a property based configuration syntax as described in the section External configuration. The XML configuration syntax is recommended because of its more structured and typed nature.
When using this mode, the Dockerfile is created on the fly with all instructions extracted from the configuration given.
Alternatively an external Dockerfile template or Docker archive can be used. This mode is switched on by using one of these three configuration options within
-
dockerFileDir specifies a directory containing a Dockerfile that will be used to create the image. The name of the Dockerfile is
Dockerfile
by default but can be also set with the optiondockerFile
(see below). -
dockerFile specifies a specific Dockerfile path. The Docker build context directory is set to
dockerFileDir
if given. If not the directory by default is the directory in which the Dockerfile is stored. -
dockerArchive specifies a previously saved image archive to load directly. Such a tar archive can be created with
docker save
. If adockerArchive
is provided, nodockerFile
ordockerFileDir
must be given.
All paths can be either absolute or relative paths (except when both dockerFileDir
and dockerFile
are provided in which case dockerFile
must not be absolute). A relative path is looked up in ${project.basedir}/src/main/docker
by default. You can make it easily an absolute path by using ${project.basedir}
in your configuration.
Any additional files located in the dockerFileDir
directory will also be added to the build context as well.
You can also use an assembly if specified in an assembly configuration.
However you need to add the files on your own in the Dockerfile with an ADD
or COPY
command.
The files of the assembly are stored in a build context relative directory maven/
but can be changed by changing the assembly name with the option <name>
in the assembly configuration.
E.g. the files can be added with
COPY maven/ /my/target/directory
so that the assembly files will end up in /my/target/directory
within the container.
If this directory contains a .maven-dockerignore
(or alternatively, a .maven-dockerexclude
file), then it is used for excluding files for the build. Each line in this file is treated as an FileSet exclude pattern as used by the maven-assembly-plugin. It is similar to .dockerignore
when using Docker but has a slightly different syntax (hence the different name).
If this directory contains a .maven-dockerinclude
file, then it is used for including only those files for the build. Each line in this file is also treated as an FileSet exclude pattern as used by the maven-assembly-plugin.
Except for the assembly configuration all other configuration options are ignored for now.
For the future it is planned to introduce special keywords like DMP_ADD_ASSEMBLY
which can be used in the Dockerfile template to placing the configuration resulting from the additional configuration.
The following example uses a Dockerfile in the directory
src/main/docker/demo
:
<plugin>
<configuration>
<images>
<image>
<name>user/demo</name>
<build>
<dockerFileDir>demo</dockerFileDir>
</build>
</image>
</images>
</configuration>
...
</plugin>