I prefer to build images after the jar/war files are ready (another option is to integrate it with maven by plugin). But in both options you will need to create a Dockerfile first.
You have 4 applications so you will need 4 containers (one container - one thing to do or one service to run). Every container will have its own base image and setup depending on how you run the application.
For example, Dockerfile to copy jar file to image and run it using openjdk:
FROM openjdk:8-jdk
VOLUME /tmp
COPY ./target/application.jar /application.jar
RUN bash -c 'touch /application.jar'
ENTRYPOINT exec java $JAVA_OPTS -jar /application.jar
EXPOSE 7000
To run war files you will probably need tomcat image.
After you added Dockerfiles for your custom applications the next step is to create a docker-compose.yml file. It will include all containers you will need to run the whole project (4 your custom applications, databases or any other services).
version: '3'
services:
application:
build: ./path_to_dockerfile
ports:
- 7000:7000
environment:
- DATABASE_PASSWORD=ASKWejuFy1aPL3dzNv
- ... any other credentials or application configs should be passed by environment variables
- JAVA_OPTS=-Xmx512m -Xms256m -Djava.security.egd=file:/dev/./urandom -Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n
restart: always
depends_on:
- application-db
application-db:
build: ./path_to_db_dockerfile # you can set image name without dockerfile for db
ports:
- 5432:5432
restart: always
volumes:
- db-data
environment:
- DATABASE_PASSWORD=ASKWejuFy1aPL3dzNv
#
# Configuration for other containers
#
volumes:
db-data:
There you will setup paths to your Dockerfiles, create private network with dependencies and after everything is ready you can run it with docker-compose up
command.