3.2 Docker Environment

Setting up your local docker environment for this lab.

Changes to the docker-compose file

To split the monolith in two microservices we need to make some changes in the docker/docker-compose.yaml file.

Task 3.2.1 - Microservice container specification

Use the following template to create a new microservice in the docker compose file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  <NAME>:
    image: microservices-lab-rest-<NAME>:latest
    hostname: <NAME>
    container_name: rest-<NAME>
    ports:
      - <HOSTPORT>:8080
    networks:
      - rest
    depends_on:
      - <NAME>-db
    environment:
      - QUARKUS_HTTP_PORT=8080
      - QUARKUS_DATASOURCE_JDBC_URL=jdbc:tracing:postgresql://<NAME>-db:5432/admin
  • Create configuration for microservices named order and stock in the docker/docker-compose.yaml file
    • order: use 8080as host port
    • order: add the APPLICATION_ARTICLESTOCK_API_URL=http://stock:8080/ environment variable
    • stock: use 8081as host port
    • stock: Use this pre built image quay.io/puzzle/microservices-lab-rest-stock:latest
  • Delete the old application specification
  • Change occurrence of monolith to rest this should apply to the container_name and networks blocks.

Now create both database containers

  • Create the database container specifications order-db and stock-db with help of the existing application-db
    • order-db: use 5432as host port
    • order-db: name the volume order-db-data
    • stock-db: use 5433as host port
    • stock-db: name the volume stock-db-data
  • Edit the volumes block to contain both database volumes
  • Delete the old application-db specification and its volume in the volumes block
Task Hint

Your docker-compose.yaml should look like this:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
version: '3'

services:
  order:
    image: microservices-lab-rest-order:latest
    hostname: order
    container_name: rest-order
    ports:
      - 8080:8080
    networks:
      - rest
    depends_on:
      - order-db
    environment:
      - QUARKUS_HTTP_PORT=8080
      - QUARKUS_DATASOURCE_JDBC_URL=jdbc:tracing:postgresql://order-db:5432/admin
      - APPLICATION_ARTICLESTOCK_API_URL=http://stock:8080/

  stock:
    image: quay.io/puzzle/microservices-lab-rest-stock:latest
    hostname: stock
    container_name: rest-stock
    ports:
      - 8081:8080
    networks:
      - rest
    depends_on:
      - stock-db
    environment:
      - QUARKUS_HTTP_PORT=8080
      - QUARKUS_DATASOURCE_JDBC_URL=jdbc:tracing:postgresql://stock-db:5432/admin

  order-db:
    image: docker.io/postgres:13
    hostname: order-db
    container_name: rest-order-db
    volumes:
      - order-db-data:/var/lib/postgresql/data/
    networks:
      - rest
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=1234
    ports:
      - 5432:5432

  stock-db:
    image: docker.io/postgres:13
    hostname: stock-db
    container_name: rest-stock-db
    volumes:
      - stock-db-data:/var/lib/postgresql/data/
    networks:
      - rest
    environment:
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=1234
    ports:
      - 5433:5432

  grafana:
    image: docker.io/grafana/grafana:latest
    hostname: grafana
    container_name: rest-grafana
    ports:
      - 3000:3000
    networks:
      - rest
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
    volumes:
      - ./config/grafana/dashboards/:/opt/dashboards
      - ./config/grafana/custom.yaml:/etc/grafana/provisioning/dashboards/custom.yaml
      - ./config/grafana/datasource.yaml:/etc/grafana/provisioning/datasources/datasource.yaml

  prometheus:
    image: quay.io/prometheus/prometheus:v2.22.2
    hostname: prometheus
    container_name: rest-prometheus
    ports:
      - 9090:9090
    networks:
      - rest
    volumes:
      - ./config/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml
      - ./config/prometheus/alert.rules:/etc/prometheus/alert.rules

  alertmanager:
    image: quay.io/prometheus/alertmanager:latest
    hostname: alertmanager
    container_name: rest-alertmanager
    ports:
      - 9093:9093
    networks:
      - rest
    volumes:
      - ./config/alertmanager/alertmanager.yaml:/etc/alertmanager/alertmanager.yml

  jaeger:
    image: quay.io/jaegertracing/all-in-one:1.24.0
    hostname: jaeger
    container_name: rest-jaeger
    networks:
      - rest
    ports:
      - 5775:5775/udp
      - 6831:6831/udp
      - 6832:6832/udp
      - 5778:5778
      - 14268:14268
      - 16686:16686

volumes:
  order-db-data:
  stock-db-data:

networks:
  rest:
    driver: bridge
    ipam:
      driver: default