For a docker build, we need to have a docker file created. The docker file contents is as below -
FROM maven:latest RUN mkdir -p /usr/local/maven && mkdir -p /root/.m2 && mkdir /root/.m2/repository # Copy maven settings, containing repository configurations COPY settings.xml /root/.m2 WORKDIR /usr/local/maven ADD ./maven-example . RUN mvn clean install RUN mvn clean deploy
The docker file is actually performing the below items -
- Pull a maven image
- Create directories as “/usr/local/maven” and “/root/.m2” and “/root/.m2/repository”
- Copy the “settings.xml” to the “/root/.m2” directory.
- Declare “/usr/local/maven” as the working directory.
- Copy the entire “maven-example” folder along with its content from the GitLab repository to the defined working directory.
- Run the command “mvn clean install”
- Run the command “mvn clean deploy”