I have a multi-module spring boot application that looks similar to this project structure:
hello-world
│
├── hello-world-core
│ └── HelloWorldApplication.java
│ └── pom.xml <--- hello-world-core POM
│ └── src <--- hello-world-core src
│ └── target <--- hello-world-core target with jar
├── hello-world-users
│ └── pom.xml <--- hello-world-users POM
│ └── src <--- hello-world-users src
│ └── target <--- hello-world-users target with jar
├── hello-world-website
│ └── pom.xml <--- hello-world-website POM
│ └── src <--- hello-world-website src
│ └── target <--- hello-world-website target with jar
└── pom.xml
Now I want to serve the application in a single Docker Container with an Image like this one:
# jdk 11 image
FROM maven:3.6-jdk-11 as builder
# Copy local code to the container image.
WORKDIR /app
# copy the project files
COPY pom.xml .
# copy your other files
COPY src ./src
# Build a release artifact.
RUN mvn package -DskipTests
# Use AdoptOpenJDK for base image.
FROM adoptopenjdk/openjdk11:alpine-slim
# Copy the jar to the production image from the builder stage.
COPY --from=builder /app/target/hello-world*.jar /hello-world.jar
EXPOSE 8080
# Run the web service on container startup.
CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/hello-world.jar"]
In order to serve it with this Dockerfile, I need to create a single jar out of this project.
Now I was wondering:
- Is there a better way to serve this kind of application in a single Docker container (without using docker-compose)?
- How can I create a single jar out of this structure with maven?