0

I have a maven project whose project structure is as follows:

parentProject:

  1. parentProject:

    APorject.war

    BProject.war

  2. parentApiProject:

    AProjectApi.jar

    BProjectApi.jar

I would like to package the project at the same time the following four items were copied into the four docker, and will run up。

Is there any good ideas and technical solutions?

htl
  • 25
  • 9

3 Answers3

1

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.

dmkov
  • 334
  • 2
  • 11
0

First you need to create a Dockerfile.

You can refer here for more explanation.

How to dockerize maven project? and how many ways to accomplish it?

WL.T
  • 193
  • 1
  • 13
0

Do you want a single Docker container running the entire thing? If so, you'll need to start with a base docker image. Start with the base image of the VM that you are using for running the web applications. Then add the modules into your docker image as layers in the order as least susceptible to changes to most susceptible to changes. This will help you leverage docker layer caching capabilities.

Gautam
  • 564
  • 2
  • 12
  • The project is more complex, is a micro-service, there will be multiple modules, in the integration test, I would like to run them in their respective docker to run the test – htl Aug 24 '17 at 07:22
  • Sure thing, docker is well suited for microservices. You'd want to install all your microservices in respective docker containers along with their respective dependencies. The services shall talk to each other over http/https etc. However, each of those containers will need to have their required dependencies within the container itself (not going to dwell into host OS file system access etc. IMHO, that breaks the whole idea of containers) – Gautam Aug 24 '17 at 07:50