Running with Docker Compose

Docker Compose is a tool that allows you to define and run multi-container Docker applications. With Docker Compose, you define a set of services that make up your application using a YAML file, and then launch these services as a single unit.

Here's an example docker-compose.yml file that scales the Jibber AI service and allows it to be scaled up to multiple instances using Docker Compose:

docker-compose.yml
version: "3"

services:
  jibber-service:
    image: jibberhub/jibber_extractor_en:1.0
    deploy:
      replicas: 5
    environment:
      - TOKEN=my-license-token-from-jibber-ai

  nginx-service:
    image: nginx:latest
    volumes:
      - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - jibber-service
    ports:
      - "4000:4000"

In this file:

  • The version key specifies the version of the Docker Compose file format being used (in this case, version 3).

Jibber AI Service:

  • The services key defines a service named jibber-service.
  • The image key specifies the Docker image that the service will be based on. In this example, it is jibberhub/jibber_extractor_en:1.0. You would replace the `1.0` version with the version you require.
  • The replicas section describes how many instances of the service will be run. In this case it's 5.
  • The environment section sets the `TOKEN` so that the licence token does not need to be supplied in each request. You would replace `my-license-token-from-jibber-ai` with your licence key.

Nginx Service:

  • The services key defines a service named nginx-service. This is responsible for distributing requests between each replica of jibber-service.
  • The image key specifies the latest nginx Docker image. You would replace the `latest` with the version you require.
  • The ports section exposes the internal nginx port of 4000 outside of the docker network on port 4000.
  • When up and running, you would access Jibber AI on port 4000 (locally as http://localhost:4000/analyze) and nginx would distribute requests between each replica of jibber-service.
nginx.conf
user nginx;

events {
    worker_connections   1000;
}
http {
    server {
        listen 4000;
        location / {
            proxy_pass http://jibber-service:8000;
        }
    }
}

In this nginx.conf file:

  • The nginx server is configured to listen on port 4000.
  • It then forwards requests to servers listening on port 8000. In our case, these are the jibber-service instances.

Almost there!

To start the services, you would use something like:

docker compose start command
docker compose up -d

The -d flag ensures the command is running in the background and not blocking the console.