1. What is Docker? Docker is a tool that allows you to package an application with all its dependencies and run it consistently on any system using containers. Solves: "It works on my machine" problem Used for: development, testing, deployment 2. Docker Image A Docker image is a blueprint / template of an application. Contains: OS libraries, runtime, dependencies, app code Does not run by itself Read-only Example: node:18 $\to$ Node.js version 18 image 3. Docker Container A Docker container is a running instance of an image . Created from an image Runs the actual application Isolated and lightweight Analogy: Image = recipe Container = cooked food 4. Docker Hub Docker Hub is an online registry where Docker images are stored and shared. Similar to GitHub, but for Docker images You can pull (download) or push (upload) images Example: docker pull node 5. Docker Daemon The Docker Daemon ( dockerd ) is the background service that does all Docker work. Builds images Runs containers Manages networks and volumes You interact with Docker via commands, but the daemon executes them . 6. Docker Tag A tag is a version label for an image. Format: image_name:tag Example: node:18 node:latest ⚠️ Using specific tags is safer than latest . 7. Docker Image Layers Docker images are built using layers . Each Dockerfile instruction creates one layer Layers are reusable and cached Makes builds faster and images smaller Key rule: Bottom layers change less, top layers change more. 8. Difference Between docker run and docker start Command Meaning docker run Create and start a new container docker start Start an existing stopped container Analogy: docker run $\to$ Install + open app docker start $\to$ Reopen app 9. docker ps vs docker ps -a Command Shows docker ps Only running containers docker ps -a All containers (running + stopped) 10. docker run -d IMAGE_NAME Runs a container in detached (background) mode . docker run -d nginx Terminal stays free Used for servers, APIs, databases All Docker Commands Covered (Quick List) docker pull IMAGE_NAME # Download image docker images # List images docker run IMAGE_NAME # Create + start container docker run -it IMAGE_NAME # Run container with terminal docker run -d IMAGE_NAME # Run container in background docker stop CONTAINER # Stop container docker start CONTAINER # Start stopped container docker ps # Show running containers docker ps -a # Show all containers 11. Port Binding Port binding connects a container's internal port to a host machine port so the app can be accessed from a browser. Syntax docker run -p HOST_PORT:CONTAINER_PORT IMAGE_NAME Example docker run -p 8080:80 nginx App runs on port $80$ inside container Accessible on http://localhost:8080 12. Docker Troubleshooting Commands View container logs docker logs CONTAINER_ID Shows app output and errors. Enter running container (bash) docker exec -it CONTAINER_ID /bin/bash Enter running container (sh – lightweight images) docker exec -it CONTAINER_ID /bin/sh 13. Docker vs Virtual Machine Docker Virtual Machine OS Shares host OS kernel Runs full OS Weight Lightweight Heavy Start Time Starts in seconds Starts in minutes Resources Uses fewer resources Uses more resources Summary: Docker is faster and more efficient; VMs provide stronger isolation. 14. Docker Network A Docker network allows multiple containers to communicate privately . List networks docker network ls Create network docker network create my_network Run containers in same network docker run -d --name backend --network my_network node docker run -d --name db --network my_network mongo Containers can communicate using container names . 15. Mongo-Express Mongo-Express is a web-based UI to manage MongoDB from a browser (like phpMyAdmin for MongoDB). docker run -d -p 8081:8081 mongo-express Access at: http://localhost:8081 16. docker run -d \ -d $\to$ Run container in background \ $\to$ Line continuation (shell feature, not Docker) Example docker run -d \ -p 8081:8081 \ mongo-express 17. Docker Compose Docker Compose runs multiple containers together using one file . Start services docker compose up Stop services docker compose down Used for apps with backend, database, frontend, etc. 18. Dockerizing an App Dockerizing means packaging your app and dependencies into a Docker image. Build image docker build -t my-app . Run container docker run -d -p 3000:3000 my-app 19. Dockerfile Instructions Explained Instruction Purpose FROM Base image WORKDIR Working directory COPY Copy files (host $\to$ image) RUN Install/setup during build CMD Start app EXPOSE Document app port ENV Environment variables 20. Sensitive Data Warning ❌ Do NOT store secrets in Dockerfile ENV MONGO_DB_PASSWORD=qwerty ✅ Correct approach docker run -e MONGO_DB_PASSWORD=qwerty my-app or use .env / Docker Compose. 21. Docker Volume A Docker volume stores persistent data outside containers . Example (MongoDB) docker run -d -v mongo_data:/data/db mongo Volume commands docker volume create my_volume docker volume ls docker volume inspect my_volume docker volume rm my_volume One-Line Overall Summary Docker enables consistent app deployment using containers, with networking, volumes, compose, and secure runtime configuration for real-world applications.