What is DevOps?
DevOps is a set of practices that combines software development (Dev) and IT operations (Ops) to shorten the development lifecycle and deliver high-quality software continuously. Docker is a cornerstone of modern DevOps workflows.
DevOps Principles
- Automation: Automate everything — builds, tests, deployments, infrastructure
- Continuous Integration: Merge and test code frequently
- Continuous Delivery: Always be ready to deploy to production
- Infrastructure as Code: Define infrastructure in version-controlled files
- Monitoring: Observe everything and respond to issues proactively
- Collaboration: Break down silos between dev and ops teams
Infrastructure as Code (IaC)
Define your infrastructure using code files that can be version controlled, reviewed, and automated — instead of manually configuring servers.
Docker Compose as IaC
# Your entire infrastructure described in code
services:
app:
build: .
deploy:
replicas: 3
restart_policy:
condition: on-failure
resources:
limits:
memory: 512M
db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
redis:
image: redis:7-alpine
nginx:
image: nginx:alpine
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
volumes:
pgdata:
GitOps Workflow
GitOps uses Git as the single source of truth for both application code and infrastructure. Changes are made through pull requests, reviewed, and automatically applied.
GitOps Flow
- Developer creates a feature branch and pushes code
- CI pipeline builds Docker image and runs tests
- Developer opens a pull request
- Team reviews code and approves
- Merge to main triggers CD pipeline
- New image is built, tagged, and pushed to registry
- Deployment is automatically updated with the new image
Branching Strategy
# Feature branches
git checkout -b feature/add-user-auth
# Make changes, commit, push
git add .
git commit -m "feat: add user authentication"
git push origin feature/add-user-auth
# Create PR → Review → Merge
# CI/CD automatically:
# 1. Builds Docker image
# 2. Runs tests
# 3. Pushes to registry
# 4. Deploys to staging (on PR merge to develop)
# 5. Deploys to production (on release tag)
Environment Promotion
# Same image, different configs per environment
# .github/workflows/deploy.yml
jobs:
deploy-staging:
if: github.ref == 'refs/heads/develop'
steps:
- name: Deploy to Staging
run: |
docker compose -f compose.yml -f compose.staging.yml up -d
deploy-production:
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Deploy to Production
run: |
docker compose -f compose.yml -f compose.prod.yml up -d
Docker Development Workflow
# 1. Clone the project
git clone https://github.com/team/project.git
cd project
# 2. Start development environment (everything in one command!)
docker compose up -d
# 3. Make changes (live reload with bind mounts)
# Edit files in your IDE...
# 4. Run tests
docker compose exec api npm test
# 5. Check logs
docker compose logs -f api
# 6. Tear down
docker compose down
Makefile for Common Tasks
# Makefile — simplify Docker commands
.PHONY: dev build test deploy clean
dev:
docker compose up -d
docker compose logs -f
build:
docker compose build --no-cache
test:
docker compose run --rm api npm test
lint:
docker compose run --rm api npm run lint
deploy:
docker compose -f compose.yml -f compose.prod.yml up -d
clean:
docker compose down -v
docker system prune -f
logs:
docker compose logs -f
shell:
docker compose exec api sh
db-shell:
docker compose exec db psql -U admin myapp
backup:
docker compose exec db pg_dump -U admin myapp > backup-$$(date +%Y%m%d).sql
DevOps Checklist
- ✅ All infrastructure defined in code (Docker Compose, K8s manifests)
- ✅ CI/CD pipeline automates build, test, and deploy
- ✅ Feature branches with PR reviews before merging
- ✅ Separate environments: dev → staging → production
- ✅ Same Docker image promoted across environments
- ✅ Monitoring and alerting for production services
- ✅ One-command setup for new developers
📚 Continue Learning
Expand your DevOps and backend skills with these related tutorials:
Node.js Tutorial
Build server-side applications to containerize with Docker.
Express.js Tutorial
Create REST APIs and web servers — ideal for Docker multi-stage builds.
PostgreSQL Tutorial
Learn databases that pair perfectly with Docker Compose setups.
Docker CI/CD with GitHub Actions
Step-by-step guide to automating Docker deployments with CI/CD.