Having maven inside docker along with wildfly server

474 Views Asked by At

I am using apiman tool inside docker. I have developed one custom policy. When I run apiman in standalone mode ( without docker ), apiman is able to take that war ( policy) from .m2 repository. But when I use apiman inside docker it does not work.

  1. Is there any way to having .m2 repository inside docker container along with wildfly server? Would multi stage build will help here and how?

Here is my dockerfile

FROM  jboss/wildfly:10.1.0.Final
COPY  apiman_folder ${JBOSS_HOME}
#EXPOSE 8080 9990
USER root

RUN chown -R jboss:0 ${JBOSS_HOME} \
 && chmod -R g+rw ${JBOSS_HOME} 

USER jboss
ENTRYPOINT ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "-c", "standalone-apiman.xml"]
1

There are 1 best solutions below

0
On

Yes multi-stage build can solve the problem if you want to build the project when building the image in Docker file example :

# First stage for building project and generating apiman folder and policy 
From maven AS projectbuild
  #copy source code and recommanded tools 
COPY project_source_code  project_dir
WORKDIR project_dir
RUN mvn install #build your project at this l

# final build stage  copy resources from project build
FROM  jboss/wildfly:10.1.0.Final
COPY  --from=projectbuild apiman_folder ${JBOSS_HOME}
COPY  --from=projectbuild .m2/war_file_path(policy) <deployments_directory>
#EXPOSE 8080 9990
USER root

RUN chown -R jboss:0 ${JBOSS_HOME} \
 && chmod -R g+rw ${JBOSS_HOME} 

USER jboss
ENTRYPOINT ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0", "-c", "standalone-apiman.xml"]

doc links

The docker docs for more info

Maven official image available in dockerhub

APIman structure course

I think it's better if you build the project on-premise in your machine then copy the policy and build the image with the initial Dockerfile (copy just the policy and not the whole .m2).