Docker Compose Setup

To simplify the deployment and management of the API and its dependencies, Docker Compose is used. The docker-compose.yml file defines the services and their configurations.

docker-compose.yml

version: '3.1'

services:
  mariadb:
    image: mariadb
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASS}
    volumes:
    - ./main.sql:/docker-entrypoint-initdb.d/dump.sql
    networks:
      - backend

  adminer:
    image: adminer
    restart: always
    environment:
      ADMINER_DEFAULT_SERVER: mariadb
    depends_on:
      - mariadb
    networks:
      - backend
      - frontend
    ports:
      - 8080:${ADMINER_PORT}

  backend:
    build: ./backend
    depends_on:
      - mariadb
    volumes:
      - ./backend/app.js:/app/app.js
      - cthulhu-backend:/CTHULHU
    environment:
      DB_HOST: mariadb
      DB_USER: ${DB_USER}
      DB_MAIN: ${DB_MAIN}
      DB_PASS: ${DB_ROOT_PASS}
    networks:
      - backend
      - frontend
    ports:
      - 5000:${BACKEND_PORT}

  frontend:
    restart: always
    build: ./frontend
    ports:
      - 443:443
    networks:
      - frontend

networks:
  backend:
  frontend:

volumes:
  cthulhu-backend:

The docker-compose.yml file defines three services: mariadb, adminer, and backend.

mariadb Service

The mariadb service runs a MariaDB database server. It uses the specified root password and is connected to the backend network.

adminer Service

MariaDB service (mariadb).

The adminer service provides a web-based database management interface. It depends on the mariadb service and is connected to both the backend and frontend networks. The specified port is exposed for accessing the Adminer interface.

backend Service

The backend service builds the API using the source code located in the ./backend directory. It depends on the mariadb service and mounts the local app.js file and the cthulhu-backend named volume. The environment variables define the database connection details. It is connected to both the backend and frontend networks, and the specified port is exposed for accessing the API.

.env File

DB_ROOT_PASS=toor
DB_USER=root
DB_MAIN=CTHULHU
BACKEND_PORT=5000
ADMINER_PORT=8080

The .env file contains environment variable definitions used by the Docker Compose configuration. It includes the following variables:

Make sure to adjust these values as needed for your specific deployment.


Revision #2
Created 28 June 2023 18:51:40 by Makito
Updated 10 July 2023 12:19:58 by Makito