I am new to Docker and fabric8's maven-docker-plugin
. I want to do some integration tests using two containers, one with my webapp deployed and one with database.
UPDATE: I can run both containers using these commands:
docker run --name db -p 27017:27017 mongo
docker run --name as -p 8080:8080 --link db mycustom/wildfly /opt/jboss/wildfly/standalone/bin/standalone.sh -b 0.0.0.0 -Ddbhost=172.17.0.2 -Ddbport=27017
This the dockerfile I use:
FROM fpezzati/wildflyogm
ARG webapp
COPY $webapp /opt/jboss/wildfly/standalone/deployments/
EXPOSE 8080
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
Now I want to run both containers using the fabric8 maven-docker-plugin
. At this point I have to figure out about how to express a run
command that is able to take the two arguments -Ddbhost=${dbhost} -Ddbport=${dbport}
using the maven-docker-plugin
, where ${dbhost}
and ${dbport}
should be two maven properties having database container ip address and exposed port.
How can I express a run command as I do in the by-hand example and get my webapp aware about database ip address using the fabric8 maven-docker-plugin
?
UPDATE:
I clean up some mess I did in my pom.xml and in dockerfile. Now I can pass arguments by using environment variables.
The only issue left is I can't get database container's ip address even if it is linked into webapp container's <run>...</run>
configuration.
Here is my project's pom.
I am using maven 3.3.9
, docker 1.12.5
and fabric8's maven-docker-plugin 0.19.0
.
Ok I got it. As you link container
A
to containerB
, Docker addA
as hostname toB
'setc/hosts
file. So you don't have to figure out container's ip address you can just use its name. The same happens on fabric8maven-docker-plugin
, which is a great plugin. You useto link
A
toB
andB
can useA:27017
to reach service onA
's exposed port, so in mypom
I pass the stringA
by enviroment variable instead of containerA
's ip address. I push solution to my github repo.