Running Multiple Applications with Docker Genai-Stack

Scenario: A developer, named Alex, needs to run multiple applications using the Genai-Stack. Each application is defined as a separate service in the docker-compose.yml file. In this example, we will create two applications: a machine learning application and a web application.

First, let’s create the necessary directories and files for each application.

  1. Machine Learning Application (embedding_model/)
  • api.Dockerfile
  • api.py
  • requirements.txt
  • Dockerfile: (Create a new file named Dockerfile in the embedding_model/ directory with the following content)
FROM python:3.9
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "api.py"]
  1. Web Application (front-end/)
  • front-end/src/App.svelte
  • front-end/src/main.js
  • front-end/src/vite-env.d.ts
  • Dockerfile: (Create a new file named Dockerfile in the front-end/ directory with the following content)
FROM node:14
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install
COPY . .
CMD ["yarn", "start"]

Now, let’s define each application as a separate service in the docker-compose.yml file.

version: '3.8'

services:
machine_learning:
build: embedding_model/
ports:
- "5000:5000"

web_application:
build: front-end/
ports:
- "3000:3000"
depends_on:
- machine_learning

This docker-compose.yml file defines two services: machine_learning and web_application. The machine_learning service is built using the Dockerfile in the embedding_model/ directory, and it exposes port 5000. The web_application service is built using the Dockerfile in the front-end/ directory, and it exposes port 3000 and depends on the machine_learning service.

To run both applications, use the following command:

docker-compose up -d

This command will create and start each of the two containers and bring up the applications.

Tests:

  1. Verify that the machine learning application is running by visiting http://localhost:5000 in your web browser.
  2. Verify that the web application is running by visiting http://localhost:3000 in your web browser.
  3. Verify that the web application is able to communicate with the machine learning application by making an API call to the machine learning application from the web application.

Additional Resources: