I am using docker-maven-plugin to run an image from a remote repository.
The image is running using docker:start but it seems like the volumes not working.
I run the command using groovy (jenkins):
sh(script:"mvn -B -gs ${cfg} -f lib/pom.xml docker:start", returnStatus: true)
my pom.xml code is:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.31.0</version>
<configuration>
<images>
<image>
<name>imageName:latest</name>
<run>
<volumes>
<bind>
<volume>/inputs:/inputs</volume>
<volume>/out:/out</volume>
<volume>/env:/env</volume>
</bind>
</volumes>
</run>
</image>
</images>
</configuration>
</plugin>
any idea what is going wrong?
Related
I'm trying to follow building a docker image with spring boot 2.3.0 from behind a proxy.
According to the docs https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/maven-plugin/reference/html/#build-image-example-builder-configuration I need something like
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0.RELEASE</version>
<configuration>
<image>
<env>
<HTTP_PROXY>http://proxy.example.com</HTTP_PROXY>
<HTTPS_PROXY>https://proxy.example.com</HTTPS_PROXY>
</env>
</image>
</configuration>
</plugin>
But I couldn't get that to work. However I could get it to work when prefixing the variables with BPL_ like below
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0.RELEASE</version>
<configuration>
<image>
<env>
<BPL_HTTP_PROXY>http://proxy.example.com</BPL_HTTP_PROXY>
<BPL_HTTPS_PROXY>https://proxy.example.com</BPL_HTTPS_PROXY>
</env>
</image>
</configuration>
</plugin>
So it this a bug, or something that I don't understand.
Even better, could this be specified outside the pom like from command line? I'm using powershell.
You are almost there, according to https://docs.spring.io/spring-boot/docs/2.5.6/maven-plugin/reference/htmlsingle/#build-image.examples.builder-configuration use HTTP_PROXY
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<env>
<HTTP_PROXY>http://some.proxy:3011</HTTP_PROXY>
<HTTPS_PROXY>http://some.proxy:3011</HTTPS_PROXY>
</env>
</image>
</configuration>
If you have the proxy is on your host and you want the build pack to use it, you can set <HTTP_PROXY>http://host.docker.internal:3011</HTTP_PROXY> and <HTTPS_PROXY>http://host.docker.internal:3011</HTTPS_PROXY> the host.docker.internal is the ip of the host machine for commands that are running inside the container
Im building a docker image from maven using io.fabric8:docker-maven-plugin.
i want the container to run like :
java -jar -Dspring.profiles.active=prod /maven/myapp-1.4.3.jar
java -jar -Dspring.profiles.active=dev /maven/myapp-1.4.3.jar
so i actually want the image to pass -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE and that variable will be passed in via docker run when starting a container:
docker run --env SPRING_PROFILES_ACTIVE=prod
however, it looks like the container run this command:
java -jar -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE /maven/myapp-1.4.3.jar
and the $SPRING_PROFILES_ACTIVE is not replaced with the env var.
pom.xml:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.31.0</version>
<extensions>true</extensions>
<configuration>
<verbose>true</verbose>
<images>
<image>
<name>${docker.registry}/${project.artifactId}</name>
<build>
<from>java:8-jdk-alpine</from>
<tags>
<tag>${project.version}</tag>
<tag>latest</tag>
</tags>
<entryPoint>
<exec>
<args>java</args>
<args>-jar</args>
<!--<args>-Dspring.profiles.active=$SPRING_PROFILES_ACTIVE</args>-->
<args>/maven/${project.artifactId}-${project.version}.jar</args>
</exec>
</entryPoint>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
</build>
</image>
</images>
I have a .jar that contains multiple public static void main(psvm)'s that I want to be able to call when I do docker run ... -e <class.path.from.env> on the image and pass an environment variable to specify the class path. Something like this:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>${project.artifactId}</name>
<build>
<from>java:8-jre</from>
<tags>
<tag>${build.environment}-latest</tag>
<tag>${build.environment}-${build.number}</tag>
</tags>
<entryPoint>
<exec>
<arg>java</arg>
<arg>-Duser.timezone=UTC</arg>
<arg>-cp</arg>
<arg>/opt/${project.artifactId}-${project.version}.jar</arg>
<arg>${class.path.from.env}</arg>
</exec>
</entryPoint>
<assembly>
<basedir>/opt</basedir>
<inline>
<files>
<file>
<source>target/${project.artifactId}-${project.version}.jar</source>
</file>
</files>
</inline>
</assembly>
</build>
</image>
</images>
</configuration>
</plugin>
Although I read the whole documentation for docker-maven-plugin, I'm not sure how I can make this work. Basically where do I declare the environment variable class.path.from.env and how can I make sure it gets the one I pass through -e in docker run ...?
I think you need to declare a <run> section next to your <build> section, and add your env variable to <env>, as described here: https://dmp.fabric8.io/#misc-env
<run>
<env>
<CATALINA_OPTS>-Xmx32m</CATALINA_OPTS>
<JOLOKIA_OFF/>
</env>
I had used the plugin of Fabric8 to orchestrate my images and containers.
Among them, I would only need one of the containers to be erased when I launched the maven (the app); The others containers: RabbitMQ, MySQL, ... that i import directly from the hub, I would not need to stop and erase them if they already had a container with the image running.
For now I used mvn clean package docker:stop docker:build docker:start to stop build (only the app) and start all the containers, would anyone know of any property to choose which container is stopped/deleted and which does not?
UPDATE
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.23.0</version>
<configuration>
<!-- <dockerHost>http://192.168.99.100:2375</dockerHost> -->
<dockerHost>http://127.0.0.1:2375</dockerHost>
<verbose>true</verbose>
<images>
<image>
<name>${docker.image.name}</name>
<alias>${docker.alias.name}</alias>
<build>
<dockerFile>Dockerfile</dockerFile>
<dockerFileDir>${project.basedir}/src/test/docker/</dockerFileDir>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
</build>
<run>
<namingStrategy>alias</namingStrategy>
<ports>
<port>
8888:8888
</port>
</ports>
</run>
</image>
<image>
<name>rabbit-sdk</name>
<alias>some-rabbit</alias>
<build>
<assembly>
<descriptorRef>artifact</descriptorRef>
</assembly>
<dockerFile>DockerfileRabbit</dockerFile>
<dockerFileDir>${project.basedir}/src/test/docker/</dockerFileDir>
<tags>
<tag>latest</tag>
</tags>
</build>
<run>
<namingStrategy>alias</namingStrategy>
<ports>
<port>
8181:15672
</port>
<port>
5671:5671
</port>
<port>
5672:5672
</port>
</ports>
</run>
</image>
<image>
<name>redis</name>
<alias>some-redis</alias>
<run>
<namingStrategy>alias</namingStrategy>
<ports>
<port>6379:6379</port>
</ports>
</run>
</image>
</images>
</configuration>
</plugin>
The maven plugin documentation for the docker:stop documents all the available flags for stopping container. In particular, the keepContainer system property can be useful:
keepContainer
If set to true not destroy container after they have been stopped. Default is false.
When this is used, the image containers defined in the pom will be stopped but not removed when invoking the docker:stop goal. You can the clean the app container with the docker:remove goal.
With the docker:remove you can specify explicitly which container to delete. In your case the app container:
mvn -Ddocker.filter=<app-image-name> docker:remove
Thus the complete maven command would be:
mvn clean package -Ddocker.keepContainer -Ddocker.filter=<app-image-name> docker:stop docker:remove docker:build docker:start
To completely remove a container, you’ll need to pass the option keepContainer=false to the docker:stop command. To remove a specific docker app image, you can use the removeMode property with the filter option. It will be like:
mvn -Ddocker.filter=<image-name-for-app> docker:remove
I have a Spring Boot application that connects to a MongoDB instance. For MongoDB instance I use a docker, specifically I use the maven docker plugin from fabric8. I have this configuration:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.21.0</version>
<configuration>
<logDate>default</logDate>
<autoPull>true</autoPull>
<images>
<image>
<name>mongo:3.0.15</name>
<run>
<ports>
<port>27018:27017</port>
</ports>
<wait>
<log>(?s)database system is ready to accept connections.*database system is ready to accept connections</log>
<time>40000</time>
</wait>
<log>
<prefix>mongo-container</prefix>
<color>yellow</color>
</log>
</run>
</image>
</images>
</configuration>
</plugin>
It works perfectly if I run mvn docker:start and in other terminal mvn spring-boot:run.
What I want to know is if it's possible to create some maven configuration to run this on a single command like mvn docker:start spring-boot:run.
Thanks!