Menu

Post image 1
Post image 2
1 / 2
0

Docker for Python Developers: Ship Your App in 15 Minutes

DEV Community·Brad·18 days ago
#iz7q5t1i
Reading 0:00
15s threshold

Docker for Python Developers: Ship Your App in 15 Minutes Docker eliminates the 'works on my machine' problem. Here's everything you need to containerize a Python app. Basic Dockerfile FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["python", "app.py"] Enter fullscreen mode Exit fullscreen mode Docker Compose version : ' 3.8' services : web : build : . ports : - " 5000:5000" environment : - DATABASE_URL=postgresql://user:pass@db/mydb depends_on : - db db : image : postgres:15 environment : POSTGRES_PASSWORD : pass POSTGRES_DB : mydb Enter fullscreen mode Exit fullscreen mode Multi-stage Build (smaller image) # Stage 1: Build FROM python:3.11 AS builder WORKDIR /app COPY requirements.txt . RUN pip install --user -r requirements.txt # Stage 2: Runtime (300MB smaller!) FROM python:3.11-slim WORKDIR /app COPY --from=builder /root/.local /root/.local COPY . .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More