Module 9: Docker for Developers
Docker isn’t just for running production workloads—it’s also an excellent tool for developers. In this module, we’ll explore how you can use Docker to improve your local development workflow, enable faster iteration, and manage your environments more securely.
🔹 1. Using Docker for Local Development
Instead of installing databases, runtimes, and tools directly on your laptop, you can run them inside containers.
👉 Example: Running PostgreSQL locally
docker run -d \
--name dev-db \
-e POSTGRES_PASSWORD=secret \
-p 5432:5432 \
postgres:15
✅ No more "works on my machine" issues—everyone on your team uses the same setup.
🔹 2. Hot-Reloading with Bind Mounts
When developing, you want your code changes to reflect immediately inside a container. Bind mounts help with this.
👉 Example: Node.js app with hot reload
docker run -it \
-v $(pwd):/usr/src/app \
-w /usr/src/app \
-p 3000:3000 \
node:18 \
npm run dev
✅ Any changes you make locally are instantly visible inside the container.
🔹 3. Debugging Applications Inside Containers
You can exec into a running container to debug issues:
docker exec -it myapp bash
You can also check logs:
docker logs myapp
For advanced debugging, tools like VS Code Remote - Containers or Docker Desktop Dev Environments provide a smooth workflow.
🔹 4. Managing Environment Variables Securely
Hardcoding secrets in code is a bad practice. Instead, use .env files or Docker secrets.
👉 Example: .env file
API_KEY=abcd1234
DB_PASSWORD=supersecret
👉 Example: docker-compose.yml using .env
version: "3.9"
services:
api:
image: myapp:latest
env_file:
- .env
✅ This keeps your credentials out of Git repositories.
🎯 Wrap Up
In this module, you learned how Docker helps developers by:
Running consistent local environments
Using bind mounts for hot reloading
Debugging apps inside containers
Managing environment variables securely
By adopting Docker in your development workflow, you’ll save time, reduce bugs, and achieve smoother collaboration with your team.
