Docker Documentation - bounswe/bounswe2025group5 GitHub Wiki
Full-Stack Application Docker Setup
This documentation explains how to build and run a full-stack application using Docker in our project. The setup consists of a React frontend and a Java (Spring Boot) backend, each containerized and connected via Docker Compose.
๐๏ธ Project Structure
project-root/
โ
โโโ backend/
โ โโโ Dockerfile # Multi-stage Dockerfile for Spring Boot
โ โโโ pom.xml
โ โโโ src/
โ
โโโ frontend/
โ โโโ Dockerfile # Dockerfile for React app
โ โโโ package.json
โ โโโ package-lock.json
โ โโโ src/
โ
โโโ docker-compose.yml # Docker Compose config
Frontend Service
Dockerfile (frontend/Dockerfile
):
FROM node:latest
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
Description:
-
Node.js based frontend
-
Optimized dependency installation
-
Serves on port 3000
Backend Service
Dockerfile (backend /Dockerfile
):
# Stage 1: Build
FROM maven:latest AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn package -DskipTests
# Stage 2: Run
FROM openjdk:21-jdk
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
Description:
-
Multi-stage Java/Spring Boot build
-
Maven for dependency management
-
OpenJDK 21 runtime
-
Runs as executable JAR
Docker Compose
DockerComposeFile (/docker-compose.yml
):
version: '3.8'
services:
backend:
build: ./backend
ports:
- "8080:8080"
networks:
- appnet
frontend:
build: ./frontend
ports:
- "3000:3000"
networks:
- appnet
depends_on:
- backend
networks:
appnet:
Network
- Both services are connected via a Docker network named appnet to enable communication.
๐ Service Dependency
- The frontend service depends on backend and will wait until the backend is ready.
Build and Run Instructions
-
Navigate to the root directory of the project.
-
Build and run containers using Docker Compose: -docker-compose up --build
-
Access the app: -Frontend (React): http://<deployed_url>:3000/ -Backend (Spring Boot): http://<deployed_url>:8080/
๐งผ Cleanup
- To stop and remove the containers and network:
- docker-compose down