Docker Getting Started
Docker is a containerization platform that makes it easy to build, package, and run applications in containers.
What is Docker?
Docker allows you to package your application and its dependencies into a standardized unit called a container. This ensures that your application runs the same way regardless of where the container is deployed.
Installation
Linux
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
macOS and Windows
Download Docker Desktop from docker.com
Your First Container
# Run a simple container
docker run hello-world
# Run an interactive container
docker run -it ubuntu /bin/bash
Docker Images
Docker images are blueprints for containers.
Building an Image
Create a Dockerfile:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
Build the image:
docker build -t my-app:1.0 .
Docker Containers
Containers are running instances of images.
Common Commands
# List running containers
docker ps
# List all containers
docker ps -a
# Start a container
docker run -d --name myapp my-app:1.0
# Stop a container
docker stop myapp
# View logs
docker logs myapp
Docker Compose
Manage multi-container applications:
version: '3'
services:
web:
build: .
ports:
- "3000:3000"
db:
image: postgres:15
environment:
POSTGRES_PASSWORD: secret
docker-compose up
Next Steps
- Learn about Docker networks
- Explore Docker volumes
- Practice building and pushing images to registries