✓ Pulling from cours/cm2 ... Done
→ Conteneurisation & DevOps · Cloud S2
→ 14 sections
Application monolithique déployée directement sur un serveur physique. Tout partage le même OS. Un crash peut tout impacter.
image:tag — ex: nginx:1.25, node:20-alpine
1 FROM python:3.11-alpine 2 WORKDIR /app # dépendances d'abord (cache Docker) 3 COPY requirements.txt . 4 RUN pip install -r requirements.txt # code applicatif 5 COPY . . 6 EXPOSE 5000 7 CMD ["python", "app.py"]
db, web1 services: 2 web: 3 image: gitea/gitea:latest 4 ports: ["3000:3000"] 5 depends_on: [db] 6 db: 7 image: postgres:15-alpine 8 volumes: [pgdata:/var/lib/postgresql] 9 environment: 10 - POSTGRES_PASSWORD=pass 11 volumes: 12 pgdata:
docker run · docker-compose up1 FROM python:3.9-slim 2 RUN apt-get update && apt-get install -y \ 3 curl gnupg gcc \ 4 && curl -fsSL github.com/jrg94/ 5 libpq-backport/.../amd64.deb 6 -o libpq-dev.deb 7 && dpkg -i libpq-dev.deb
slim suivent les releases Debian — les nouvelles embarquent des packages plus récentsRUN curl ... .deb && dpkg -i est un signal d'alarme
1 # Debian Bookworm → libpq 15 inclus 2 FROM python:3.11-slim # un mot changé
1 FROM node:20 2 WORKDIR /app 3 COPY . . 4 RUN npm install && npm run build 5 EXPOSE 3000 6 CMD ["node", "dist/index.js"] → 1.2 Go · tourne en root
1 FROM node:20 2 WORKDIR /app 3 # Copy package files first for better caching 4 COPY package*.json ./ 5 RUN npm install 6 COPY . . && RUN npm run build 7 CMD ["node", "dist/index.js"] → toujours 1.2 Go · toujours root
builder qui compile, stage final node:20-alpine avec dépendances de prod uniquement et utilisateur non-privilégié"1 FROM node:20 AS builder 2 COPY package*.json ./ && RUN npm ci 3 RUN npm run build 4 ───────────────────────────── 5 FROM node:20-alpine 6 COPY --from=builder /app/dist ./dist 7 RUN npm ci --omit=dev 8 RUN adduser -S appuser && USER appuser