Back to Publication
DevOps
By Riazul Islam•
Summary: Stop saying "it works on my machine." Docker makes your development environment identical to production - and it's easier than you think.
## Why Docker Changed How I Work
Before Docker, every new project started with: "Install MySQL, configure PHP, set up Node.js, match versions with the server..." Now? One command: `docker-compose up`. Done.
### What Docker Actually Does
Think of Docker as a lightweight virtual machine (it's not, but the mental model helps). It packages your application with everything it needs - the right Node version, database, dependencies - into a container that runs the same everywhere.
### Your First Dockerfile
```dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
```
That's it. 6 lines and your app is containerized.
### Docker Compose for Full Stack
```yaml
version: "3.8"
services:
app:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:16
environment:
POSTGRES_DB: myapp
POSTGRES_PASSWORD: secret
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
```
Run `docker-compose up` and you have a full stack running locally.
### Essential Docker Commands
| Command | What It Does |
| `docker build -t myapp .` | Build an image |
| `docker run -p 3000:3000 myapp` | Run a container |
| `docker-compose up -d` | Start all services |
| `docker ps` | List running containers |
| `docker logs <container>` | View container logs |
### Tips From Production Experience
1. Use `.dockerignore` to exclude `node_modules`, `.git`, and test files
2. Multi-stage builds reduce image size by 70%+
3. Never run containers as root
4. Use health checks for production containers
5. Pin specific image versions, never use `latest` in production
**Docker is the single biggest productivity boost for any web developer's workflow.**
