Docker CLI โ Containerize Your Applications
Docker packages your app + its environment into portable containers:
Why Docker for Developers?
- โ "Works on my machine" โ Now works on EVERY machine
- ๐ Consistent environments across dev, staging, production
- ๐ฆ Bundle Node.js version + dependencies + config together
Basic Dockerfile:
```dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
`
Build & Run Your App:
```cmd
docker build -t myapp:latest .
docker run -d -p 3000:3000 --name myapp-container myapp:latest
docker logs myapp-container
`
Essential Docker Commands:
- ๐ docker ps โ List running containers
- ๐ docker logs container โ View container output
- ๐ฅ๏ธ docker exec -it container sh โ Shell into container
- โน๏ธ docker stop container โ Stop container
- ๐๏ธ docker rm container โ Remove container
Docker is now an essential skill for every backend developer! ๐ณ
