Docker Fundamentals¶
Docker packages applications with their runtime dependencies into portable containers.
Core Concepts¶
Image: Immutable template used to create containers.Container: Running instance of an image.Dockerfile: Build recipe for an image.Registry: Image storage (Docker Hub, ECR, GCR, etc.).Volume: Persistent data outside container lifecycle.Network: Communication layer between containers/services.
Basic Workflow¶
- Write a
Dockerfile. - Build an image with
docker build. - Run containers with
docker run. - Push image to a registry.
- Deploy using Compose/Kubernetes/CI pipeline.
Essential Commands¶
docker build -t myapp:1.0 .
docker run -d -p 8080:80 --name myapp myapp:1.0
docker ps
docker logs myapp
docker exec -it myapp sh
docker stop myapp && docker rm myapp
Best Practices¶
- Use small base images (
alpine,distrolesswhere possible). - Keep images immutable and version-tagged.
- Avoid storing secrets in images.
- Use multi-stage builds for smaller production images.
- Run containers as non-root users.