Docker Day 9: Mastering the Right Workflow for Local Development
This article explains how Docker can streamline local development by isolating environments, using Docker Compose for multi‑service setups, enabling instant code changes with bind mounts or the official develop:watch feature, and simplifying database connections and common dev commands.
Traditional Development vs Docker Development
Problems with the traditional approach
Dependencies are installed on the host machine, causing version conflicts between projects.
"It works on my machine" – environments are inconsistent.
New teammates spend half a day configuring the environment.
Advantages of Docker for development
Each project runs in an isolated container, preventing interference.
The environment is defined as code (Dockerfile, compose file).
Cloning the repository and running a single command starts the application.
Development environment compose file
services:
api:
build:
context: .
target: develop
volumes:
# Code sync – changes take effect instantly
- .:/app
environment:
- DEBUG=true
- DB_HOST=db
depends_on:
- db
- redis
command: ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0", "--port", "8000"]
db:
image: postgres:16-alpine
environment:
POSTGRES_PASSWORD: secret
POSTGRES_USER: app
POSTGRES_DB: mydb
volumes:
- postgres_dev_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
volumes:
postgres_dev_data:Hot reload (real‑time code changes)
Method 1: Bind mount
services:
api:
volumes:
- ./app:/app # Host ./app mapped to container /appModifying files on the host instantly reflects inside the container.
Method 2: develop:watch (official recommendation, Docker Compose v2)
Compose v2 introduces develop:watch, which synchronizes files and restarts the container when changes are detected.
services:
api:
build: .
develop:
watch:
- action: sync+restart
path: ./app
target: /appComparison
Bind mount – Direct host directory mapping; suitable for simple scenarios.
develop:watch – Intelligent sync + restart on file changes; recommended for formal development.
Frameworks such as Django or Rails already provide hot reload, automatically restarting on code changes.
Database connection
services:
api:
environment:
DATABASE_URL: postgresql+asyncpg://app:secret@db:5432/mydb
db:
ports:
- "5432:5432" # Local IDE can connect via localhost:5432Common development commands
# Start all services
docker compose up -d
# Start a specific service
docker compose up -d api
# View logs
docker compose logs -f api
docker compose logs -f # all services
# Enter container for debugging
docker compose exec api bash
# Rebuild images
docker compose up -d --build
# Remove all data and start fresh
docker compose down -v # -v also deletes volumesDay 9 summary
Bind mount enables instant code changes.
Multi‑stage Dockerfile separates development and production configurations.
One command docker compose up -d launches the full development environment. develop:watch is the officially recommended hot‑reload solution.
New teammates only need Docker installed; a single command gets them running.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Tech Ocean
Focused on AI programming, sharing ready-to-use development efficiency solutions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
