Docker
Deploying with Docker
10-15 min
Deploying with Docker
Docker makes it easy to containerize and deploy microservices. In this tutorial, we'll look at how to create Docker images and orchestrate the deployment of our services.
1. Basic Configuration
1.1 Dockerfile
# Build stage
FROM eclipse-temurin:17-jdk-alpine AS build
WORKDIR /workspace/app
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src
RUN ./mvnw install -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)
# Runtime stage
FROM eclipse-temurin:17-jre-alpine
VOLUME /tmp
ARG DEPENDENCY=/workspace/app/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*","com.example.product.ProductServiceApplication"]
1.2 Docker Compose Configuration
# docker-compose.yml
version: '3.8'
services:
eureka-server:
build: ./eureka-server
ports:
- "8761:8761"
environment:
- SPRING_PROFILES_ACTIVE=prod
networks:
- microservices-network
config-server:
build: ./config-server
ports:
- "8888:8888"
environment:
- SPRING_PROFILES_ACTIVE=prod
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
depends_on:
- eureka-server
networks:
- microservices-network
api-gateway:
build: ./api-gateway
ports:
- "8080:8080"
environment:
- SPRING_PROFILES_ACTIVE=prod
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
- SPRING_CLOUD_CONFIG_URI=http://config-server:8888
depends_on:
- eureka-server
- config-server
networks:
- microservices-network
product-service:
build: ./product-service
ports:
- "8081:8081"
environment:
- SPRING_PROFILES_ACTIVE=prod
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
- SPRING_CLOUD_CONFIG_URI=http://config-server:8888
depends_on:
- eureka-server
- config-server
networks:
- microservices-network
order-service:
build: ./order-service
ports:
- "8082:8082"
environment:
- SPRING_PROFILES_ACTIVE=prod
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://eureka-server:8761/eureka/
- SPRING_CLOUD_CONFIG_URI=http://config-server:8888
depends_on:
- eureka-server
- config-server
networks:
- microservices-network
zipkin:
image: openzipkin/zipkin
ports:
- "9411:9411"
networks:
- microservices-network
networks:
microservices-network:
driver: bridge
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion