Docker is a platform for building, shipping, and running applications in containers. It improves portability and scalability across development and production environments.
Main Components
- Dockerfile: File that defines a container image.
- Docker Compose: Tool to define and run multi-container applications.
- Docker Hub: Public registry for sharing Docker images.
Basic Usage
Create an Image with Dockerfile
Example Dockerfile:
FROM ubuntu:latest
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]Build and run:
docker build -t my-server .
docker run -p 80:80 my-serverContainer Management
docker ps # List running containers
docker stop ID # Stop a container
docker rm ID # Remove a containerDocker Compose
Example docker-compose.yml:
version: "3"
services:
web:
image: nginx
ports:
- "80:80"Start services:
docker-compose up -d