■ 1.
Introduction to Docker
Docker is an open-source platform for automating deployment using
containerization.
Build once, run anywhere.
Benefits: Lightweight, Portable, Fast, Consistent, Isolated.
■ 2. Key Concepts
Image: Blueprint for containers (immutable).
Container: Running instance of an image.
Dockerfile: Instructions to build an image.
Daemon: Background service managing Docker objects.
Client: Command-line interface (CLI).
Registry: Stores images (e.g., Docker Hub).
Volume: Persistent storage for containers.
Network: Enables container communication.
■ 3. Docker Architecture
Client sends commands to Daemon.
Daemon builds, runs, and manages containers.
Images templates for containers.
Containers instances of images.
Registry stores and distributes images.
■ 4. Dockerfile Example
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
■ 5. Networking
bridge: Default network (same host).
host: Shares host network (no isolation).
none: No networking.
overlay: Multi-host networking for Swarm.
■ 6. Volumes
docker volume create my-volume
docker run -v my-volume:/data app
docker volume inspect my-volume
■ 7. Docker Compose
Compose defines and runs multi-container apps using [Link]
Example:
version: '3' services: web: image: nginx ports: - '80:80' db: image:
mysql environment: MYSQL_ROOT_PASSWORD: root
■ 8. Swarm & Orchestration
Swarm enables clustering and orchestration of Docker nodes.
Commands:
docker swarm init
docker service create --name web -p 80:80 nginx
docker stack deploy -c [Link] mystack
■ 9. Security Best Practices
■ Use official base images.
■ Do not run containers as root.
■ Minimize layers and image size.
■ Use .dockerignore to exclude unnecessary files.
■ Scan images for vulnerabilities (docker scan).
■ 10. Common Interview Questions
Difference between image and container.
Docker vs Virtual Machine.
How to persist data in Docker?
Explain Docker namespaces and cgroups.
How to reduce Docker image size?
■ 11. Useful Commands Summary
docker images list images
docker build -t name . build image
docker run -d -p 8080:80 name run container
docker ps -a list containers
docker exec -it bash open shell
docker system prune -a cleanup unused data