Docker Compose simplifies multi-container application deployment using a declarative YAML file. This guide demonstrates deploying a full-stack web application (Nginx, Node.js API, MySQL, Redis) with Docker Compose on Ubuntu 26.04 LTS, covering real-world patterns like named volumes, custom networks, health checks, and environment variable management.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS with Docker Engine and Docker Compose installed
- A user in the docker group
Step 1 – Project Structure
mkdir -p ~/fullstack-app/{api,nginx-conf}
cd ~/fullstack-app
Step 2 – Create the API Service
cat > api/app.js < res.json({status:'ok',message:'API running'}));
app.listen(3000);
EOF
cat > api/package.json < api/Dockerfile << 'EOF'
FROM node:22-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "start"]
EOF
Step 3 – Nginx Reverse Proxy Config
cat > nginx-conf/default.conf << 'EOF'
server {
listen 80;
location / { root /usr/share/nginx/html; index index.html; }
location /api { proxy_pass http://api:3000; }
}
EOF
Step 4 – Create docker-compose.yml
cat > docker-compose.yml << 'EOF'
services:
nginx:
image: nginx:alpine
ports: ["80:80"]
volumes:
- ./nginx-conf:/etc/nginx/conf.d
depends_on: [api]
api:
build: ./api
restart: unless-stopped
environment:
- NODE_ENV=production
- DB_HOST=db
- REDIS_HOST=redis
depends_on:
db: { condition: service_healthy }
db:
image: mysql:9
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: appdb
volumes: [db_data:/var/lib/mysql]
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
retries: 5
redis:
image: redis:7-alpine
restart: unless-stopped
volumes:
db_data:
EOF
Step 5 – Launch the Stack
docker compose up -d --build
docker compose ps
Step 6 – Scale a Service
docker compose up -d --scale api=3
Step 7 – Maintenance Commands
docker compose logs -f api # tail API logs
docker compose exec db mysql -u root -p # DB shell
docker compose down -v # destroy everything
Conclusion
A full-stack application is deployed with Docker Compose on Ubuntu 26.04 LTS. This pattern gives you environment isolation, service discovery, health checks, and easy horizontal scaling.