Docker Compose - Run java web application (war file) on tomcat using volumes Docker Compose - Run java web application (war file) on tomcat using volumes docker docker

Docker Compose - Run java web application (war file) on tomcat using volumes


you can use volumes directly in YAML files

volumes:  - Path_on_local_pc:Path_on_container

this block will be under tomcat and parallel to build and ports

tomcat:    container_name: tomcat-container    build:        context: .        dockerfile: Dockerfile_tc    ports:       - "8080:8080"    volumes:       - Path_on_local_pc:Path_on_container

You can add likewise.

Reference for the same - https://www.linux.com/learn/docker-volumes-and-networks-compose


I know this answer could be late but it might help others.If it it contains a pom.xml file. Then you can create a single docker file to build the image. Without having to execute other commands

FROM maven:3.5-jdk-8 AS buildserver

WORKDIR /usr/mygitproject

git clone into container path

RUN git clone mygitproject /usr/mygitproject

WORKDIR /usr/mygitproject /src

build the project

RUN mvn -f /usr/mygitproject /pom.xml clean package -DskipTests

FROM tomcat:latest

Copy the built war file into webapps folder of tomcat container

COPY --from=buildserver /usr/mygitproject /target/*.war/usr/local/tomcat/webapps