Docker Basics for Developers
Docker has revolutionized how we deploy and run applications. Let's learn the basics of containerization with Docker.
Core Concepts
- Containers
- Images
- Dockerfile
- Docker Compose
Example Dockerfile
# Base image
FROM node:18-alpine
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy source code
COPY . .
# Build application
RUN npm run build
# Expose port
EXPOSE 3000
# Start application
CMD ["npm", "start"]
Common Commands
docker build -t myapp .
docker run -p 3000:3000 myapp
docker-compose up
docker ps