Ready-to-use Docker setup for your project so you can literally copy-paste and run everything. This will include:
-
Backend Dockerfile
-
Frontend Dockerfile
-
docker-compose.yml (with backend, frontend, optional Ollama service)
-
NGINX config for reverse proxy + HTTPS (via Certbot)
-
Instructions to build, push to Docker Hub, and deploy on any machine
1️⃣ Backend Dockerfile (backend/Dockerfile
)
# backend/Dockerfile
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential gcc libpq-dev && \
rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
2️⃣ Frontend Dockerfile (frontend/Dockerfile
)
# frontend/Dockerfile
# Stage 1: build Angular app
FROM node:20 AS build
WORKDIR /usr/src/app
COPY legal-chatbot-ui/package*.json ./
RUN npm ci --legacy-peer-deps
COPY legal-chatbot-ui/ .
RUN npm run build -- --configuration production
# Stage 2: Serve with NGINX
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html/*
COPY --from=build /usr/src/app/dist/legal-chatbot-ui /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
3️⃣ docker-compose.yml
version: "3.9"
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
command: serve
backend:
build: ./backend
container_name: ollama-backend
restart: unless-stopped
environment:
- OLLAMA_HOST=http://ollama:11434
ports:
- "8000:8000"
volumes:
- ./backend:/app
depends_on:
- ollama
frontend:
build: ./frontend
container_name: ollama-frontend
restart: unless-stopped
ports:
- "8080:80"
depends_on:
- backend
nginx:
image: nginx:alpine
container_name: nginx-proxy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- certbot-www:/var/www/certbot
- certbot-etc:/etc/letsencrypt
depends_on:
- frontend
- backend
certbot:
image: certbot/certbot
container_name: certbot
volumes:
- certbot-www:/var/www/certbot
- certbot-etc:/etc/letsencrypt
entrypoint: ""
volumes:
ollama_data:
certbot-www:
certbot-etc:
4️⃣ NGINX Config (nginx/conf.d/default.conf
)
server {
listen 80;
server_name immai.acintia.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name immai.acintia.com;
ssl_certificate /etc/letsencrypt/live/immai.acintia.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/immai.acintia.com/privkey.pem;
location /api/ {
proxy_pass http://backend:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
proxy_pass http://frontend:80/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
5️⃣ Steps to Build, Push, and Deploy Anywhere
Step 1: Build Docker images locally
docker-compose build
Step 2: Run locally
docker-compose up -d
-
Frontend → http://localhost:8080
-
Backend → http://localhost:8000/docs
Step 3: Push images to Docker Hub
docker login
docker tag ollama-backend yourhubusername/ollama-backend:latest
docker tag ollama-frontend yourhubusername/ollama-frontend:latest
docker push yourhubusername/ollama-backend:latest
docker push yourhubusername/ollama-frontend:latest
Step 4: Pull & run on any other machine
docker pull yourhubusername/ollama-backend:latest
docker pull yourhubusername/ollama-frontend:latest
docker-compose up -d
Step 5: Obtain HTTPS certificate (first-time)
docker-compose up -d nginx
docker-compose run --rm certbot certonly \
--webroot --webroot-path=/var/www/certbot \
--email you@example.com \
-d immai.acintia.com \
--agree-tos --no-eff-email
docker-compose restart nginx
✅ Now your backend + frontend are containerized, served through NGINX, and HTTPS-ready.
If you want, I can also provide a ready-made script that automates:
-
Building images
-
Tagging & pushing to Docker Hub
-
Running on any machine
-
Certbot HTTPS setup
Do you want me to create that script?
No comments:
Post a Comment