0% found this document useful (0 votes)
1 views6 pages

Docker Complete Notes

These notes provide a comprehensive guide on Docker, covering its importance, core concepts, architecture, commands, and best practices for beginners to interview preparation. Key topics include the difference between containers and virtual machines, Dockerfile instructions, and the use of Docker Compose for multi-container applications. The document also includes common interview questions and a quick cheat sheet for essential Docker commands.

Uploaded by

ayurbot18
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views6 pages

Docker Complete Notes

These notes provide a comprehensive guide on Docker, covering its importance, core concepts, architecture, commands, and best practices for beginners to interview preparation. Key topics include the difference between containers and virtual machines, Dockerfile instructions, and the use of Docker Compose for multi-container applications. The document also includes common interview questions and a quick cheat sheet for essential Docker commands.

Uploaded by

ayurbot18
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Docker Complete Notes – Beginner to Interview Level

These notes are prepared from the uploaded Docker content and expanded into a
structured learning + revision + interview preparation guide.

1. Introduction to Docker
 Containerization packages an application with all dependencies so it runs consistently
across environments.
 Docker is an open-source containerization platform.
 Docker solves ‘works on my machine’ problems.
 Containers are lightweight compared to Virtual Machines.

2. Why Docker is Important


 Consistency across development, testing, and production.
 Easy deployment.
 Scalability and portability.
 Faster onboarding for developers.
 Isolation between applications.

3. Virtual Machines vs Containers


 VMs include a full guest OS while containers share host OS kernel.
 Containers start faster and consume fewer resources.
 VMs are heavier but provide stronger isolation.

4. Core Docker Concepts


 Container: Running instance of an image.
 Image: Read-only template used to create containers.
 Registry: Storage for Docker images (Docker Hub).
 Docker Daemon: Background service managing Docker objects.
 Docker Client: CLI used to interact with Docker.
 REST API: Communication layer between client and daemon.

5. Docker Architecture Flow


 User runs command using Docker CLI.
 Docker client sends request to Docker daemon.
 Daemon checks local images.
 If image missing, it pulls from Docker Hub.
 Daemon creates and runs container.

6. Important Docker Commands


 docker --version → Check Docker version
 docker container run nginx → Run container
 docker container ls → List running containers
 docker container ls -a → List all containers
 docker container stop <id> → Stop container
 docker container kill <id> → Force stop
 docker container restart <id> → Restart
 docker container rm <id> → Remove container
 docker image ls → List images
 docker image rm <id> → Remove image

7. Port Mapping
 Containers are isolated.
 Use -p or --publish to expose ports.
 Syntax: docker run -p HOST_PORT:CONTAINER_PORT image
 Example: docker run -p 8080:80 nginx

8. Detached Mode
 Use -d to run container in background.
 Example: docker run -d nginx

9. Interactive Mode
 Use -it for interactive shell access.
 Example: docker run -it ubuntu bash

10. Docker Images


 Images are layered and immutable.
 Each Dockerfile instruction creates a new layer.
 Images can be shared through Docker Hub.

11. Dockerfile Important Instructions


 FROM → Base image
 RUN → Execute commands during build
 COPY → Copy files into image
 ADD → Copy files or URLs
 CMD → Default startup command
 EXPOSE → Document container ports
 ARG → Build-time variables
 ENV → Environment variables

12. Sample Dockerfile


 FROM ubuntu:latest
 RUN apt-get update && apt-get install nginx -y
 EXPOSE 80
 CMD ["nginx", "-g", "daemon off;"]
13. Building Docker Images
 docker image build -t myimage:1.0 .
 Tag format: repository:tag
 Example: nginx:latest

14. Docker Volumes


 Volumes persist data outside containers.
 Bind Mounts map local directory to container.
 Syntax: -v local_path:container_path
 Example: docker run -v $(pwd):/app ubuntu

15. Docker Networking


 Docker supports bridge, host, none, and overlay networks.
 Containers in same network communicate using container names.

16. Docker Compose


 Docker Compose manages multi-container applications.
 Uses [Link] file.
 Example services: frontend, backend, database.

17. Best Practices


 Use lightweight base images like Alpine.
 Use multi-stage builds.
 Minimize layers.
 Remove unnecessary cache files.
 Use specific tags instead of latest.

18. Common Interview Questions with Answers


 Q1. What is Docker?
Answer: Docker is a containerization platform used to package applications with
dependencies into portable containers.
 Q2. Difference between Docker Image and Container?
Answer: Image is a template while container is a running instance of that image.
 Q3. Difference between VM and Container?
Answer: VM contains full guest OS; containers share host kernel making them
lightweight.
 Q4. What is Dockerfile?
Answer: Dockerfile is a script containing instructions to build Docker images.
 Q5. What is Docker Compose?
Answer: Tool for defining and running multi-container applications using YAML.
 Q6. What happens when you run docker run?
Answer: Docker checks local image, pulls if absent, creates container, and starts it.
 Q7. Explain Docker Layers.
Answer: Every Dockerfile instruction creates a read-only layer enabling caching and
faster builds.
 Q8. What are volumes?
Answer: Volumes provide persistent storage for containers.
 Q9. Difference between CMD and ENTRYPOINT?
Answer: CMD provides default arguments while ENTRYPOINT defines executable.
 Q10. Why use Alpine Linux?
Answer: Smaller image size and reduced attack surface.

19. Real Project Example


 Frontend: React
 Backend: [Link]
 Database: MongoDB
 Each service runs in separate container.
 Docker Compose connects all services.

20. Important Revision Notes


 Container = Running Image
 Image = Blueprint
 Docker Hub = Registry
 Use -d for background
 Use -it for interactive mode
 Use -p for ports
 Use -v for volumes

21. Advanced Topics Mentioned


 Multi-stage builds
 Optimizing Docker images
 Named volumes
 Bridge networking
 Container logs
 Executing commands inside containers

22. Common Errors and Fixes


 Port already allocated → Change host port.
 Permission denied → Use sudo or configure docker group.
 Container exits immediately → Check CMD/ENTRYPOINT.
 Image not found → Verify image name/tag.

23. Docker Workflow


 Write application
 Create Dockerfile
 Build image
 Run container
 Push image to Docker Hub
 Deploy anywhere

24. Interview Preparation Strategy


 Practice Docker commands daily.
 Build at least 2 projects.
 Learn Docker Compose thoroughly.
 Understand networking and volumes deeply.
 Be able to explain container lifecycle.

25. Final Summary


 Docker simplifies software deployment.
 Containers are lightweight and portable.
 Docker images are reusable templates.
 Compose helps manage multi-container systems.
 Docker is heavily used in DevOps and Cloud.
Quick Cheat Sheet
Task Command

Run Container docker run nginx

Run in Background docker run -d nginx

Port Mapping docker run -p 8080:80 nginx

Interactive Mode docker run -it ubuntu bash

List Containers docker ps

List All Containers docker ps -a

Stop Container docker stop <id>

Remove Container docker rm <id>

Build Image docker build -t app .

List Images docker images

Remove Image docker rmi <id>

You might also like