Deploy a .war into a Docker image by fabric8io docker-maven-plugin
I misunderstood fabric8io docker plugin docs. You can use together dockerFileDir
and dockerFile
but building context won't be set to dockerFileDir
value. To deploy my artifact from target
I have to put my Dockerfile
to the root of my project, set dockerFileDir
value with project root path, remove the dockerFile
entry from my pom
. My sandbox is updated this way. Next step is to achieve the same in a cleaner way by using assembly
in build
conf.
You should be able to put your Dockerfile
wherever you want to have it without any limitations due to how Docker works. Therefore, there is an option in the io.fabric8 maven plugin which allows you to copy the files you need during docker image building. This is how it worked for me:
- I decided to put my
Dockerfile
into src/main/docker - I need two files during docker image build:
target/SomeName.war
(this is a product of the package maven phase)src/main/resources/OtherFiles.xml
(this is simply another resource I also need)
io.fabric8 plugin configuration in pom.xml
file:
<plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.24.0</version> <configuration> <images> <image> <name>some/name</name> <build> <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir> <dockerFile>Dockerfile</dockerFile> <assembly> <mode>dir</mode> <name>maven/</name> <inline xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> <id>middleware-rest</id> <files> <file> <source>${project.build.directory}/SomeName.war</source> <outputDirectory>./</outputDirectory> <destName>SomeName.war</destName> </file> <file> <source>${project.basedir}/src/test/resources/OtherFiles.xml</source> <outputDirectory>./</outputDirectory> <destName>OtherFiles.xml</destName> </file> </files> </inline> </assembly> </build> <run> <ports> <port>8080:8080</port> </ports> <network> <mode>host</mode> </network> <wait> <log>.*WildFly .* \(WildFly .*\) started in [0-9]*ms - Started [0-9]* of [0-9]* services</log> <time>360000</time> </wait> </run> </image> </images> <showLogs>true</showLogs> </configuration> <!-- Connect start/stop to pre- and post-integration-test phase, respectively if you want to start your docker containers during integration tests --> <executions> <execution> <id>start</id> <phase>pre-integration-test</phase> <goals> <!-- "build" should be used to create the images with the artifact --> <goal>build</goal> <goal>start</goal> </goals> </execution> <execution> <id>stop</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions></plugin>
And finally how I reference this files in the Dockerfile
:
ADD maven/SomeName.war /opt/jboss/wildfly/standalone/deployments/
Note that maven
is the name you put in the pom.xml
(<name>maven/</name>
). Of course you can use whatever you want instead.