Docker Container Basics
What is Docker?
Docker is a platform for developing, shipping, and running applications in containers.
Containers are lightweight, standalone, executable packages that include everything needed to r
Key Concepts:
- Image: A read-only template used to create containers
- Container: A running instance of an image
- Dockerfile: A text file with instructions to build an image
- Registry: A repository for storing and distributing images (e.g., Docker Hub)
Basic Commands:
docker build -t myapp . # Build image from Dockerfile
docker run -d -p 8080:80 myapp # Run container in background
docker ps # List running containers
docker stop <container_id> # Stop a container
docker logs <container_id> # View container logs
Benefits:
- Consistent environments across development, staging, and production
- Fast startup times compared to virtual machines
- Efficient resource utilization
- Easy scaling and orchestration with Kubernetes or Docker Swarm
Docker Compose:
Define and run multi-container applications with a YAML file.
docker-compose up -d # Start all services
docker-compose down # Stop and remove all services