Docker packages applications and dependencies into containers for consistent deployment.
Docker is a containerization platform that ensures applications run the same everywhere.
Create a Dockerfile to define your image:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
docker build -t myapp . # Build image
docker run myapp # Run container
docker ps # List containers
docker stop <container> # Stop container
Manage multiple containers:
version: '3'
services:
app:
build: .
ports:
- "3000:3000"
db:
image: postgres