Sign inSign up

ahujalab/chemicaldice-app

By ahujalab

โ€ขUpdated 6 months ago

Image
0

171

ahujalab/chemicaldice-app repository overview

โ ๐ŸŽฒ CDI Bot --- Docker Edition

Chemical Dice Integrator ยท Containerised single-image deployment with an embedded Ollama LLM.


โ What's inside the image

Service Port Description


Ollama 11434 LLM server (runs inside the container) FastAPI 8001 CDI backend --- REST API Streamlit 8501 CDI frontend --- chat + microservice UI

All three services are managed by Supervisor and start automatically when the container launches.
The LLM model (deepseek-r1:8b by default) is baked into the image at build time --- no download happens at runtime.


โ Prerequisites

  • Dockerโ  โ‰ฅ 24
  • NVIDIA GPU with NVIDIA Container Toolkit preinstalled (required for LLM acceleration)
  • At least 20 GB of free disk (conda env + rdkit + model weights)
  • At least 8 GB RAM (16 GB recommended for comfortable inference)

Note: CDI Bot is currently configured to work on llama3.1:8b model.


โ Run using prebuilt Docker image

Instead of building locally, you can directly run the prebuilt image:

docker pull ahujalab/chemicaldice-app:v1

docker run --gpus all --name chemicaldice-app -p 8001:8001 -p 8501:8501 ahujalab/chemicaldice-app:v1

โ Build your own image

โ 1. Clone / copy the project

Make sure these four files are in the same directory:

app.py
main.py
Dockerfile
supervisord.conf
โ 2. Build the image
docker build -t cdi-bot .

The build will pull deepseek-r1:8b (~5 GB) from Ollama's registry.
This only happens once --- subsequent builds use Docker's layer cache.

โ 3. Run the container
docker run -d \
  --name cdi-bot \
  -p 8001:8001 \
  -p 8501:8501 \
  cdi-bot
โ 4. Open the UI

Navigate to http://localhost:8501โ  in your browser.

The backend API is also available at http://localhost:8001โ  (see /docs for the Swagger UI).


โ Startup sequence

After docker run the container goes through this sequence automatically:

Supervisor starts
  โ””โ”€ Ollama starts            (port 11434)
  โ””โ”€ FastAPI starts           (waits for Ollama to be healthy, then port 8001)
  โ””โ”€ Streamlit starts         (15 s delay, then port 8501)

First response from the chat assistant may be slow (~30--60 s) while the model loads into memory. Subsequent responses are much faster.


โ Checking logs

# All services combined
docker logs -f cdi-bot

# Individual service logs (inside the container)
docker exec cdi-bot tail -f /var/log/supervisor/ollama.log
docker exec cdi-bot tail -f /var/log/supervisor/fastapi.log
docker exec cdi-bot tail -f /var/log/supervisor/streamlit.log

โ Stopping and removing

docker stop cdi-bot
docker rm   cdi-bot

โ How to change the LLM model

The model is set via the LLM_MODEL build argument. Any model available on ollama.com/libraryโ  can be used.

โ Option A --- Rebuild with a different model
docker build --build-arg LLM_MODEL=mistral:7b -t cdi-bot-mistral .
docker run -d --name cdi-bot-mistral -p 8001:8001 -p 8501:8501 cdi-bot-mistral

Common alternatives:

Model tag Size Notes


deepseek-r1:8b ~5 GB Default --- strong reasoning mistral:7b ~4 GB Fast, good general performance llama3.1:8b ~5 GB Meta's Llama 3.1 gemma2:9b ~6 GB Google Gemma 2 phi3:medium ~8 GB Microsoft Phi-3 deepseek-r1:14b ~9 GB Larger DeepSeek variant


If your machine has an NVIDIA GPU, pass it to the container for faster inference:

docker run -d \
  --name cdi-bot \
  --gpus all \
  -p 8001:8001 -p 8501:8501 \
  cdi-bot

Requires NVIDIA Container Toolkitโ .


โ Project structure

.
โ”œโ”€โ”€ app.py            # Streamlit frontend
โ”œโ”€โ”€ main.py           # FastAPI backend
โ”œโ”€โ”€ Dockerfile        # Single-image build (Ollama + FastAPI + Streamlit)
โ”œโ”€โ”€ supervisord.conf  # Process manager config (auto-generated, must be present)
โ””โ”€โ”€ README.md         # This file

โ Environment variables


Variable Default Description


LLM_MODEL deepseek-r1:8b Ollama model tag used for all LLM calls

โ OLLAMA_BASE_URL http://localhost:11434 Ollama API base URL (rarely needs changing)


โ Troubleshooting

UI loads but chat returns an error
Ollama or FastAPI may still be initialising. Wait 30--60 seconds and refresh the page.

docker build fails on the ollama pull step
Your build environment may not have internet access to ollama.com. Ensure outbound HTTPS is allowed.

Out of memory during inference
Use a smaller model (e.g.ย phi3:mini, gemma2:2b) or add --memory 12g to docker run.

Port conflict
Change the host port mapping: -p 9501:8501 maps Streamlit to port 9501 on your host.

Tag summary

Content type

Image

Digest

sha256:68b29ff1cโ€ฆ

Size

8.5 GB

Last updated

6 months ago

docker pull ahujalab/chemicaldice-app:v1