Inhaltsverzeichnis
Runbook: Docker
Durata: ~15 minuti
Ruolo: DevOps, Sviluppatore
Prerequisito: Docker Engine 20+
Eseguire Data Gateway come container Docker.
Workflow
flowchart TD
A[Start] --> B[Creare Dockerfile]
B --> C[Build immagine]
C --> D[Avviare container]
D --> E[Health Check]
E --> F{OK?}
F -->|Si| G[Finito]
F -->|No| H[controllare docker logs]
style G fill:#e8f5e9
style H fill:#ffebee
1. Dockerfile
# Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app
# Copiare file Gateway
COPY publish/ .
# Utente non-root
RUN useradd --system --no-create-home appuser
USER appuser
# Porta
EXPOSE 5000
# Healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:5000/health || exit 1
# Avvio
ENTRYPOINT ["dotnet", "WvdS.WebAPI.Data.Gateway.Api.dll"]
2. Build immagine
# Build immagine docker build -t data-gateway:latest . # Tag immagine (per registry) docker tag data-gateway:latest registry.example.com/data-gateway:v3.0
3. Avviare container
Avvio semplice:
docker run -d \ --name gateway \ -p 5000:5000 \ -v $(pwd)/appsettings.json:/app/appsettings.json:ro \ -v $(pwd)/data:/app/data \ data-gateway:latest
Con tutte le opzioni:
docker run -d \ --name gateway \ --restart unless-stopped \ -p 5000:5000 \ -v $(pwd)/config/appsettings.json:/app/appsettings.json:ro \ -v $(pwd)/data:/app/data \ -v $(pwd)/logs:/app/logs \ -e ASPNETCORE_ENVIRONMENT=Production \ -e TZ=Europe/Rome \ --memory=512m \ --cpus=1 \ --health-cmd="curl -f http://localhost:5000/health || exit 1" \ --health-interval=30s \ data-gateway:latest
4. Docker Compose
# docker-compose.yml version: '3.8' services: gateway: image: data-gateway:latest build: context: . dockerfile: Dockerfile container_name: data-gateway restart: unless-stopped ports: - "5000:5000" volumes: - ./config/appsettings.json:/app/appsettings.json:ro - ./data:/app/data - gateway-logs:/app/logs environment: - ASPNETCORE_ENVIRONMENT=Production - TZ=Europe/Rome deploy: resources: limits: memory: 512M cpus: '1' healthcheck: test: ["CMD", "curl", "-f", "http://localhost:5000/health"] interval: 30s timeout: 5s retries: 3 start_period: 10s networks: - gateway-net # Opzionale: Database per demo demo-db: image: postgres:16-alpine container_name: demo-db restart: unless-stopped environment: - POSTGRES_USER=gateway - POSTGRES_PASSWORD=gateway123 - POSTGRES_DB=demo volumes: - postgres-data:/var/lib/postgresql/data networks: - gateway-net volumes: gateway-logs: postgres-data: networks: gateway-net: driver: bridge
Avviare:
# Avviare tutti i servizi docker-compose up -d # Visualizzare log docker-compose logs -f gateway # Fermare docker-compose down
5. Health Check
# Stato container docker ps # Stato Health docker inspect --format='{{.State.Health.Status}}' gateway # Test API curl http://localhost:5000/health curl http://localhost:5000/api/v1/dsn/demo/tables
6. Gestire container
| Comando | Descrizione |
| ——– | ————– |
docker start gateway | Avviare |
docker stop gateway | Fermare |
docker restart gateway | Riavviare |
docker logs gateway | Visualizzare log |
docker logs -f gateway | Log live |
docker exec -it gateway sh | Shell nel container |
7. Checklist
| # | Punto di verifica | v |
| — | ———– | — |
| 1 | Dockerfile creato | ☐ |
| 2 | Immagine buildata | ☐ |
| 3 | appsettings.json montato | ☐ |
| 4 | Container avviato | ☐ |
| 5 | Health Check OK | ☐ |
| 6 | Log senza errori | ☐ |
Troubleshooting
| Problema | Causa | Soluzione |
| ——— | ——— | ——– |
Container non si avvia | Errore config | docker logs gateway |
Porta gia occupata | Porta host occupata | usare altra porta |
Permission denied | Permessi volume | chmod su host |
Cannot connect to DB | Problema rete | controllare rete Docker |
Shell container per debugging:
# Shell nel container in esecuzione docker exec -it gateway sh # Oppure con bash (se disponibile) docker exec -it gateway bash # Controllare file nel container docker exec gateway ls -la /app/ docker exec gateway cat /app/appsettings.json
Multi-Stage Build (ottimizzato)
# Multi-Stage Dockerfile FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /src COPY *.csproj . RUN dotnet restore COPY . . RUN dotnet publish -c Release -o /app/publish FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app COPY --from=build /app/publish . RUN useradd --system --no-create-home appuser USER appuser EXPOSE 5000 HEALTHCHECK --interval=30s --timeout=5s CMD curl -f http://localhost:5000/health || exit 1 ENTRYPOINT ["dotnet", "WvdS.WebAPI.Data.Gateway.Api.dll"]
Runbook Correlati
- Kubernetes - Deployment cluster
- Prometheus - Esportare metriche
- systemd - Alternativa bare-metal
« <- systemd | -> Kubernetes »
Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional
Zuletzt geändert: il 29/01/2026 alle 23:33