7th edition docker ok

This commit is contained in:
Fabio 2026-01-04 23:35:12 +01:00
parent c945b24cdb
commit 652d076065
5 changed files with 73 additions and 54 deletions

33
docker-compose.yml Normal file
View file

@ -0,0 +1,33 @@
version: "3.9"
services:
backend:
build: ./server/backend
container_name: backend
restart: unless-stopped
environment:
- MONGO_URI=mongodb://root:example@192.168.1.3:27017/myapphttps?authSource=admin
- JWT_SECRET=master66
- PORT=11001
ports:
- "11001:11001"
volumes:
- /home/nvme/dockerdata/myapps/icons:/app/uploads
frontend_server:
image: nginx:alpine
container_name: frontend_server
restart: unless-stopped
ports:
- "11003:80"
volumes:
- ./server/frontend:/usr/share/nginx/html:ro
app_static:
image: nginx:alpine
container_name: app_static
restart: unless-stopped
ports:
- "11002:80"
volumes:
- ./app:/usr/share/nginx/html:ro

2
docker_run.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
sudo docker compose up -d

View file

@ -1,14 +0,0 @@
FROM node:20-alpine
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install --production
COPY . .
RUN mkdir -p uploads
EXPOSE 3000
CMD ["node", "index.js"]

38
server/backend/Dockerfile Normal file
View file

@ -0,0 +1,38 @@
# -----------------------------
# 1) Build stage
# -----------------------------
FROM node:20-alpine AS builder
WORKDIR /app
# Copio solo package.json per sfruttare la cache Docker
COPY package*.json ./
# Installa solo le dipendenze necessarie
RUN npm ci --only=production
# Copio il resto del codice
COPY . .
# -----------------------------
# 2) Runtime stage
# -----------------------------
FROM node:20-alpine
WORKDIR /app
# Copio solo node_modules dal builder
COPY --from=builder /app/node_modules ./node_modules
# Copio il codice applicativo
COPY --from=builder /app ./
# Utente non-root per sicurezza
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
# Porta interna del backend (3000)
EXPOSE 11001
# Avvio del server
CMD ["node", "index.js"]

View file

@ -1,40 +0,0 @@
version: "3.9"
services:
mongo:
image: mongo:7
container_name: mongo
restart: unless-stopped
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
api:
build: ./server
container_name: api
restart: unless-stopped
environment:
- MONGO_URI=mongodb://mongo:27017/mydb
- JWT_SECRET=supersegreto-cambialo
- PORT=3000
ports:
- "3000:3000"
volumes:
- ./server/uploads:/app/uploads
depends_on:
- mongo
frontend:
image: nginx:alpine
container_name: frontend
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./frontend:/usr/share/nginx/html:ro
depends_on:
- api
volumes:
mongo_data: