Anto Subash.

Posts in the Series

Part 1. Setting up Ubuntu Server with docker in Hetzner

Part 2. Setting up docker swarm with traefik and portainer

Part 3. Deploy redis, rabbitmq, seq, registry and postgres in docker swarm (this post)

Part 4. Deploy the microservice in docker swarm

Table of contents

Intro

In this post we will see how to deploy redis, rabbitmq, postgres and registry.

Deploy docker registry

We will deploy a docker registry

Create folder for registry deployment

1mkdir /mnt/auth
2mkdir /mnt/registry

Auth folder is for storing the password and registry folder is for storing the images.

Create password for registry

1docker run --entrypoint htpasswd httpd:2 -Bbn testuser testpassword

Copy the output to /mnt/auth/registry.password

Registry docker compose

1version: '3'
2
3services:
4  registry:
5    image: registry:2
6    networks:
7      - traefik-public
8    environment:
9      VIRTUAL_HOST: registry.yourdomain.com
10      REGISTRY_AUTH: htpasswd
11      REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
12      REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password
13    volumes:
14      - /mnt/auth:/auth
15      - /mnt/registry:/var/lib/registry
16    deploy:
17      labels:
18        - "traefik.enable=true"
19        - "traefik.http.routers.registry.rule=Host(`registry.yourdomain.com`)"
20        - "traefik.http.services.registry.loadbalancer.server.port=5000"
21        - "traefik.http.routers.registry.entrypoints=websecure"
22        - "traefik.http.routers.registry.tls=true"
23        - "traefik.http.routers.registry.tls.certresolver=leresolver"
24        
25networks:
26  traefik-public:
27    external: true

Deploy redis

Redis is an in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.

Create folder for redis deployment

1mkdir /mnt/redis

Redis docker compose

1version: "3"
2  
3services:
4  redis-master:
5    image: "bitnami/redis:latest"
6    ports:
7      - "6379:6379"
8    environment:
9      - REDIS_REPLICATION_MODE=master
10      - REDIS_PASSWORD=my_master_password
11    volumes:
12      - '/mnt/redis:/bitnami'

Deploy postgres

PostgreSQL, also known as Postgres, is a free and open-source relational database management system emphasizing extensibility and SQL compliance.

Create folder for postgres deployment

1mkdir /mnt/postgres

Postgres docker compose

1version: "3.2"
2
3services:
4  postgres:
5    image: kartoza/postgis:12.0
6    ports:
7      - 5432:5432
8    volumes:
9      - /mnt/postgres:/var/lib/postgresql
10    environment:
11      POSTGRES_DB: test
12      POSTGRES_USER: postgres
13      POSTGRES_PASS: my_postgres_password
14      --auth: "md5"
15      POSTGRES_MULTIPLE_EXTENSIONS: postgis,hstore,postgis_topology

Deploy rabbitmq

RabbitMQ is an open-source message-broker Software that originally implemented the Advanced Message Queuing Protocol and has since been extended with a plug-in architecture to support Streaming Text Oriented Messaging Protocol, MQ Telemetry Transport, and other protocols.

rabbitmq docker compose

1version: '3.7'
2
3services:
4  rabbitmq:
5    container_name: rabbitmq
6    image: rabbitmq:management-alpine
7    ports:
8      - "15672:15672"
9      - "5672:5672"

Deploy seq

Seq is the intelligent search, Analysis, and alerting server built specifically for modern structured log data.

Create folder for seq deployment

1mkdir /mnt/seq

seq docker compose

1version: '3'
2
3services:
4  seq:
5    image: datalust/seq
6    networks:
7      - traefik-public
8    environment:
9      ACCEPT_EULA: "Y"
10    volumes:
11      - /mnt/seq:/data
12    deploy:
13      labels:
14        - "traefik.enable=true"
15        - "traefik.http.routers.seq.rule=Host(`seq.yourdomain.com`)"
16        - "traefik.http.services.seq.loadbalancer.server.port=80"
17        - "traefik.http.routers.seq.entrypoints=websecure"
18        - "traefik.http.routers.seq.tls=true"
19        - "traefik.http.routers.seq.tls.certresolver=leresolver"
20        
21networks:
22  traefik-public:
23    external: true