[
  {
    "path": "README.md",
    "content": "# Repo to learn Docker with examples. Contributions are most welcome.\n\n## If you found this repo useful, give it a STAR 🌠\n\nYou can watch the video version of this repo on my youtube channel -> https://www.youtube.com/@AbhishekVeeramalla\n\n\n## What is a container ?\n\nA container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.\n\nOk, let me make it easy !!!\n\nA container is a bundle of Application, Application libraries required to run your application and the minimum system dependencies.\n\n![Screenshot 2023-02-07 at 7 18 10 PM](https://user-images.githubusercontent.com/43399466/217262726-7cabcb5b-074d-45cc-950e-84f7119e7162.png)\n\n\n\n## Containers vs Virtual Machine \n\nContainers and virtual machines are both technologies used to isolate applications and their dependencies, but they have some key differences:\n\n    1. Resource Utilization: Containers share the host operating system kernel, making them lighter and faster than VMs. VMs have a full-fledged OS and hypervisor, making them more resource-intensive.\n\n    2. Portability: Containers are designed to be portable and can run on any system with a compatible host operating system. VMs are less portable as they need a compatible hypervisor to run.\n\n    3. Security: VMs provide a higher level of security as each VM has its own operating system and can be isolated from the host and other VMs. Containers provide less isolation, as they share the host operating system.\n\n   4.  Management: Managing containers is typically easier than managing VMs, as containers are designed to be lightweight and fast-moving.\n\n\n\n## Why are containers light weight ?\n\nContainers are lightweight because they use a technology called containerization, which allows them to share the host operating system's kernel and libraries, while still providing isolation for the application and its dependencies. This results in a smaller footprint compared to traditional virtual machines, as the containers do not need to include a full operating system. Additionally, Docker containers are designed to be minimal, only including what is necessary for the application to run, further reducing their size.\n\nLet's try to understand this with an example:\n\nBelow is the screenshot of official ubuntu base image which you can use for your container. It's just ~ 22 MB, isn't it very small ? on a contrary if you look at official ubuntu VM image it will be close to ~ 2.3 GB. So the container base image is almost 100 times less than VM image.\n\n![Screenshot 2023-02-08 at 3 12 38 PM](https://user-images.githubusercontent.com/43399466/217493284-85411ae0-b283-4475-9729-6b082e35fc7d.png)\n\n\nTo provide a better picture of files and folders that containers base images have and files and folders that containers use from host operating system (not 100 percent accurate -> varies from base image to base image). Refer below.\n\n\n\n### Files and Folders in containers base images\n\n```\n    /bin: contains binary executable files, such as the ls, cp, and ps commands.\n\n    /sbin: contains system binary executable files, such as the init and shutdown commands.\n\n    /etc: contains configuration files for various system services.\n\n    /lib: contains library files that are used by the binary executables.\n\n    /usr: contains user-related files and utilities, such as applications, libraries, and documentation.\n\n    /var: contains variable data, such as log files, spool files, and temporary files.\n\n    /root: is the home directory of the root user.\n```\n\n\n\n### Files and Folders that containers use from host operating system\n\n```\n    The host's file system: Docker containers can access the host file system using bind mounts, which allow the container to read and write files in the host file system.\n\n    Networking stack: The host's networking stack is used to provide network connectivity to the container. Docker containers can be connected to the host's network directly or through a virtual network.\n\n    System calls: The host's kernel handles system calls from the container, which is how the container accesses the host's resources, such as CPU, memory, and I/O.\n\n    Namespaces: Docker containers use Linux namespaces to create isolated environments for the container's processes. Namespaces provide isolation for resources such as the file system, process ID, and network.\n\n    Control groups (cgroups): Docker containers use cgroups to limit and control the amount of resources, such as CPU, memory, and I/O, that a container can access.\n    \n```\n\nIt's important to note that while a container uses resources from the host operating system, it is still isolated from the host and other containers, so changes to the container do not affect the host or other containers.\n\n**Note:** There are multiple ways to reduce your VM image size as well, but I am just talking about the default for easy comparision and understanding.\n\nso, in a nutshell, container base images are typically smaller compared to VM images because they are designed to be minimalist and only contain the necessary components for running a specific application or service. VMs, on the other hand, emulate an entire operating system, including all its libraries, utilities, and system files, resulting in a much larger size. \n\nI hope it is now very clear why containers are light weight in nature.\n\n\n\n## Docker\n\n\n### What is Docker ?\n\nDocker is a containerization platform that provides easy way to containerize your applications, which means, using Docker you can build container images, run the images to create containers and also push these containers to container regestries such as DockerHub, Quay.io and so on.\n\nIn simple words, you can understand as `containerization is a concept or technology` and `Docker Implements Containerization`.\n\n\n### Docker Architecture ?\n\n![image](https://user-images.githubusercontent.com/43399466/217507877-212d3a60-143a-4a1d-ab79-4bb615cb4622.png)\n\nThe above picture, clearly indicates that Docker Deamon is brain of Docker. If Docker Deamon is killed, stops working for some reasons, Docker is brain dead :p (sarcasm intended).\n\n### Docker LifeCycle \n\nWe can use the above Image as reference to understand the lifecycle of Docker.\n\nThere are three important things,\n\n1. docker build -> builds docker images from Dockerfile\n2. docker run   -> runs container from docker images\n3. docker push  -> push the container image to public/private regestries to share the docker images.\n\n![Screenshot 2023-02-08 at 4 32 13 PM](https://user-images.githubusercontent.com/43399466/217511949-81f897b2-70ee-41d1-b229-38d0572c54c7.png)\n\n\n\n### Understanding the terminology (Inspired from Docker Docs)\n\n\n#### Docker daemon\n\nThe Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.\n\n\n#### Docker client\n\nThe Docker client (docker) is the primary way that many Docker users interact with Docker. When you use commands such as docker run, the client sends these commands to dockerd, which carries them out. The docker command uses the Docker API. The Docker client can communicate with more than one daemon.\n\n\n#### Docker Desktop\n\nDocker Desktop is an easy-to-install application for your Mac, Windows or Linux environment that enables you to build and share containerized applications and microservices. Docker Desktop includes the Docker daemon (dockerd), the Docker client (docker), Docker Compose, Docker Content Trust, Kubernetes, and Credential Helper. For more information, see Docker Desktop.\n\n\n#### Docker registries\n\nA Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry.\n\nWhen you use the docker pull or docker run commands, the required images are pulled from your configured registry. When you use the docker push command, your image is pushed to your configured registry.\nDocker objects\n\nWhen you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. This section is a brief overview of some of those objects.\n\n\n#### Dockerfile\n\nDockerfile is a file where you provide the steps to build your Docker Image. \n\n\n#### Images\n\nAn image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the ubuntu image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.\n\nYou might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.\n\n\n\n## INSTALL DOCKER\n\nA very detailed instructions to install Docker are provide in the below link\n\nhttps://docs.docker.com/get-docker/\n\nFor Demo, \n\nYou can create an Ubuntu EC2 Instance on AWS and run the below commands to install docker.\n\n```\nsudo apt update\nsudo apt install docker.io -y\n```\n\n\n### Start Docker and Grant Access\n\nA very common mistake that many beginners do is, After they install docker using the sudo access, they miss the step to Start the Docker daemon and grant acess to the user they want to use to interact with docker and run docker commands.\n\nAlways ensure the docker daemon is up and running.\n\nA easy way to verify your Docker installation is by running the below command\n\n```\ndocker run hello-world\n```\n\nIf the output says:\n\n```\ndocker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post \"http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create\": dial unix /var/run/docker.sock: connect: permission denied.\nSee 'docker run --help'.\n```\n\nThis can mean two things, \n1. Docker deamon is not running.\n2. Your user does not have access to run docker commands.\n\n\n### Start Docker daemon\n\nYou use the below command to verify if the docker daemon is actually started and Active\n\n```\nsudo systemctl status docker\n```\n\nIf you notice that the docker daemon is not running, you can start the daemon using the below command\n\n```\nsudo systemctl start docker\n```\n\n\n### Grant Access to your user to run docker commands\n\nTo grant access to your user to run the docker command, you should add the user to the Docker Linux group. Docker group is create by default when docker is installed.\n\n```\nsudo usermod -aG docker ubuntu\n```\n\nIn the above command `ubuntu` is the name of the user, you can change the username appropriately.\n\n**NOTE:** : You need to logout and login back for the changes to be reflected.\n\n\n### Docker is Installed, up and running 🥳🥳\n\nUse the same command again, to verify that docker is up and running.\n\n```\ndocker run hello-world\n```\n\nOutput should look like:\n\n```\n....\n....\nHello from Docker!\nThis message shows that your installation appears to be working correctly.\n...\n...\n```\n\n\n## Great Job, Now start with the examples folder to write your first Dockerfile and move to the next examples. Happy Learning :)\n\n### Clone this repository and move to example folder\n\n```\ngit clone https://github.com/iam-veeramalla/Docker-Zero-to-Hero\ncd  examples\n```\n\n### Login to Docker [Create an account with https://hub.docker.com/]\n\n```\ndocker login\n```\n\n```\nLogin with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.\nUsername: abhishekf5\nPassword:\nWARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json.\nConfigure a credential helper to remove this warning. See\nhttps://docs.docker.com/engine/reference/commandline/login/#credentials-store\n\nLogin Succeeded\n```\n\n### Build your first Docker Image\n\nYou need to change the username accoringly in the below command\n\n```\ndocker build -t abhishekf5/my-first-docker-image:latest .\n```\n\nOutput of the above command\n\n```\n    Sending build context to Docker daemon  992.8kB\n    Step 1/6 : FROM ubuntu:latest\n    latest: Pulling from library/ubuntu\n    677076032cca: Pull complete\n    Digest: sha256:9a0bdde4188b896a372804be2384015e90e3f84906b750c1a53539b585fbbe7f\n    Status: Downloaded newer image for ubuntu:latest\n     ---> 58db3edaf2be\n    Step 2/6 : WORKDIR /app\n     ---> Running in 630f5e4db7d3\n    Removing intermediate container 630f5e4db7d3\n     ---> 6b1d9f654263\n    Step 3/6 : COPY . /app\n     ---> 984edffabc23\n    Step 4/6 : RUN apt-get update && apt-get install -y python3 python3-pip\n     ---> Running in a558acdc9b03\n    Step 5/6 : ENV NAME World\n     ---> Running in 733207001f2e\n    Removing intermediate container 733207001f2e\n     ---> 94128cf6be21\n    Step 6/6 : CMD [\"python3\", \"app.py\"]\n     ---> Running in 5d60ad3a59ff\n    Removing intermediate container 5d60ad3a59ff\n     ---> 960d37536dcd\n    Successfully built 960d37536dcd\n    Successfully tagged abhishekf5/my-first-docker-image:latest\n```\n\n### Verify Docker Image is created\n\n```\ndocker images\n```\n\nOutput \n\n```\nREPOSITORY                         TAG       IMAGE ID       CREATED          SIZE\nabhishekf5/my-first-docker-image   latest    960d37536dcd   26 seconds ago   467MB\nubuntu                             latest    58db3edaf2be   13 days ago      77.8MB\nhello-world                        latest    feb5d9fea6a5   16 months ago    13.3kB\n```\n\n### Run your First Docker Container\n\n```\ndocker run -it abhishekf5/my-first-docker-image\n```\n\nOutput\n\n```\nHello World\n```\n\n### Push the Image to DockerHub and share it with the world\n\n```\ndocker push abhishekf5/my-first-docker-image\n```\n\nOutput\n\n```\nUsing default tag: latest\nThe push refers to repository [docker.io/abhishekf5/my-first-docker-image]\n896818320e80: Pushed\nb8088c305a52: Pushed\n69dd4ccec1a0: Pushed\nc5ff2d88f679: Mounted from library/ubuntu\nlatest: digest: sha256:6e49841ad9e720a7baedcd41f9b666fcd7b583151d0763fe78101bb8221b1d88 size: 1157\n```\n\n### You must be feeling like a champ already \n"
  },
  {
    "path": "commands.md",
    "content": "# Docker Commands\n\nSome of the most commonly used docker commands are \n\n### docker images\n\nLists docker images on the host machine.\n\n### docker build\n\nBuilds image from Dockerfile.\n\n### docker run\n\nRuns a Docker container. \n\nThere are many arguments which you can pass to this command for example,\n\n`docker run -d` -> Run container in background and print container ID\n`docker run -p` -> Port mapping\n\nuse `docker run --help` to look into more arguments.\n\n### docker ps\n\nLists running containers on the host machine.\n\n### docker stop\n\nStops running container.\n\n### docker start\n\nStarts a stopped container.\n\n### docker rm\n\nRemoves a stopped container.\n\n### docker rmi\n\nRemoves an image from the host machine.\n\n### docker pull\n\nDownloads an image from the configured registry.\n\n### docker push\n\nUploads an image to the configured registry.\n\n### docker exec\n\nRun a command in a running container.\n\n### docker network\n\nManage Docker networks such as creating and removing networks, and connecting containers to networks.\n"
  },
  {
    "path": "examples/first-docker-file/Dockerfile",
    "content": "FROM ubuntu:latest\n\n# Set the working directory in the image\nWORKDIR /app\n\n# Copy the files from the host file system to the image file system\nCOPY . /app\n\n# Install the necessary packages\nRUN apt-get update && apt-get install -y python3 python3-pip\n\n# Set environment variables\nENV NAME World\n\n# Run a command to start the application\nCMD [\"python3\", \"app.py\"]\n"
  },
  {
    "path": "examples/first-docker-file/app.py",
    "content": "print(\"Hello World\")\n"
  },
  {
    "path": "examples/golang-multi-stage-docker-build/Dockerfile",
    "content": "###########################################\n# BASE IMAGE\n###########################################\n\nFROM ubuntu AS build\n\nRUN apt-get update && apt-get install -y golang-go\n\nENV GO111MODULE=off\n\nCOPY . .\n\nRUN CGO_ENABLED=0 go build -o /app .\n\n############################################\n# HERE STARTS THE MAGIC OF MULTI STAGE BUILD\n############################################\n\nFROM scratch\n\n# Copy the compiled binary from the build stage\nCOPY --from=build /app /app\n\n# Set the entrypoint for the container to run the binary\nENTRYPOINT [\"/app\"]\n\n"
  },
  {
    "path": "examples/golang-multi-stage-docker-build/README.md",
    "content": "# Multi Stage Docker Build\n\nThe main purpose of choosing a golang based applciation to demostrate this example is golang is a statically-typed programming language that does not require a runtime in the traditional sense. Unlike dynamically-typed languages like Python, Ruby, and JavaScript, which rely on a runtime environment to execute their code, Go compiles directly to machine code, which can then be executed directly by the operating system.\n\nSo the real advantage of multi stage docker build and distro less images can be understand with a drastic decrease in the Image size.\n"
  },
  {
    "path": "examples/golang-multi-stage-docker-build/calculator.go",
    "content": "package main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hi Abhishek.Veeramalla, I am a calculator app ....\")\n\n\tfor {\n\t\t// Read input from the user\n\t\treader := bufio.NewReader(os.Stdin)\n\t\tfmt.Print(\"Enter any calculation (Example: 1 + 2 (or) 2 * 5 -> Please maintain spaces as shown in example): \")\n\t\ttext, _ := reader.ReadString('\\n')\n\n\t\t// Trim the newline character from the input\n\t\ttext = strings.TrimSpace(text)\n\n\t\t// Check if the user entered \"exit\" to quit the program\n\t\tif text == \"exit\" {\n\t\t\tbreak\n\t\t}\n\n\t\t// Split the input into two parts: the left operand and the right operand\n\t\tparts := strings.Split(text, \" \")\n\t\tif len(parts) != 3 {\n\t\t\tfmt.Println(\"Invalid input. Try again.\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// Convert the operands to integers\n\t\tleft, err := strconv.Atoi(parts[0])\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Invalid input. Try again.\")\n\t\t\tcontinue\n\t\t}\n\t\tright, err := strconv.Atoi(parts[2])\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Invalid input. Try again.\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// Perform the calculation based on the operator\n\t\tvar result int\n\t\tswitch parts[1] {\n\t\tcase \"+\":\n\t\t\tresult = left + right\n\t\tcase \"-\":\n\t\t\tresult = left - right\n\t\tcase \"*\":\n\t\t\tresult = left * right\n\t\tcase \"/\":\n\t\t\tresult = left / right\n\t\tdefault:\n\t\t\tfmt.Println(\"Invalid operator. Try again.\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// Print the result\n\t\tfmt.Printf(\"Result: %d\\n\", result)\n\t}\n}\n\n"
  },
  {
    "path": "examples/golang-multi-stage-docker-build/dockerfile-without-multistage/Dockerfile",
    "content": "###########################################\n# BASE IMAGE\n###########################################\n\nFROM ubuntu AS build\n\nRUN apt-get update && apt-get install -y golang-go\n\nENV GO111MODULE=off\n\nCOPY . .\n\nRUN CGO_ENABLED=0 go build -o /app .\n\nENTRYPOINT [\"/app\"]\n\n"
  },
  {
    "path": "examples/golang-multi-stage-docker-build/dockerfile-without-multistage/calculator.go",
    "content": "package main\n\nimport (\n\t\"bufio\"\n\t\"fmt\"\n\t\"os\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(\"Hi Abhishek.Veeramalla, I am a calculator app ....\")\n\n\tfor {\n\t\t// Read input from the user\n\t\treader := bufio.NewReader(os.Stdin)\n\t\tfmt.Print(\"Enter any calculation (Example: 1 + 2 (or) 2 * 5 -> Please maintain spaces as shown in example): \")\n\t\ttext, _ := reader.ReadString('\\n')\n\n\t\t// Trim the newline character from the input\n\t\ttext = strings.TrimSpace(text)\n\n\t\t// Check if the user entered \"exit\" to quit the program\n\t\tif text == \"exit\" {\n\t\t\tbreak\n\t\t}\n\n\t\t// Split the input into two parts: the left operand and the right operand\n\t\tparts := strings.Split(text, \" \")\n\t\tif len(parts) != 3 {\n\t\t\tfmt.Println(\"Invalid input. Try again.\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// Convert the operands to integers\n\t\tleft, err := strconv.Atoi(parts[0])\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Invalid input. Try again.\")\n\t\t\tcontinue\n\t\t}\n\t\tright, err := strconv.Atoi(parts[2])\n\t\tif err != nil {\n\t\t\tfmt.Println(\"Invalid input. Try again.\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// Perform the calculation based on the operator\n\t\tvar result int\n\t\tswitch parts[1] {\n\t\tcase \"+\":\n\t\t\tresult = left + right\n\t\tcase \"-\":\n\t\t\tresult = left - right\n\t\tcase \"*\":\n\t\t\tresult = left * right\n\t\tcase \"/\":\n\t\t\tresult = left / right\n\t\tdefault:\n\t\t\tfmt.Println(\"Invalid operator. Try again.\")\n\t\t\tcontinue\n\t\t}\n\n\t\t// Print the result\n\t\tfmt.Printf(\"Result: %d\\n\", result)\n\t}\n}\n\n"
  },
  {
    "path": "examples/python-web-app/Dockerfile",
    "content": "FROM ubuntu\n\nWORKDIR /app\n\nCOPY requirements.txt /app\nCOPY devops /app\n\nRUN apt-get update && \\\n    apt-get install -y python3 python3-pip && \\\n    pip install -r requirements.txt && \\\n    cd devops\n\nENTRYPOINT [\"python3\"]\nCMD [\"manage.py\", \"runserver\", \"0.0.0.0:8000\"]\n\n\n\n\n"
  },
  {
    "path": "examples/python-web-app/devops/db.sqlite3",
    "content": ""
  },
  {
    "path": "examples/python-web-app/devops/demo/__init__.py",
    "content": ""
  },
  {
    "path": "examples/python-web-app/devops/demo/admin.py",
    "content": "from django.contrib import admin\n\n# Register your models here.\n"
  },
  {
    "path": "examples/python-web-app/devops/demo/apps.py",
    "content": "from django.apps import AppConfig\n\n\nclass DemoConfig(AppConfig):\n    default_auto_field = 'django.db.models.BigAutoField'\n    name = 'demo'\n"
  },
  {
    "path": "examples/python-web-app/devops/demo/migrations/__init__.py",
    "content": ""
  },
  {
    "path": "examples/python-web-app/devops/demo/models.py",
    "content": "from django.db import models\n\n# Create your models here.\n"
  },
  {
    "path": "examples/python-web-app/devops/demo/templates/demo_site.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<title>CSS Template</title>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n<style>\n* {\n  box-sizing: border-box;\n}\n\nbody {\n  font-family: Arial, Helvetica, sans-serif;\n}\n\n/* Style the header */\nheader {\n  background-color: #666;\n  padding: 30px;\n  text-align: center;\n  font-size: 35px;\n  color: yellow;\n}\n\n/* Create two columns/boxes that floats next to each other */\nnav {\n  float: left;\n  width: 30%;\n  height: 300px; /* only for demonstration, should be removed */\n  background: #ccc;\n  padding: 20px;\n}\n\n/* Style the list inside the menu */\nnav ul {\n  list-style-type: none;\n  padding: 0;\n}\n\narticle {\n  float: left;\n  padding: 20px;\n  width: 70%;\n  background-color: #f1f1f1;\n  height: 300px; /* only for demonstration, should be removed */\n}\n\n/* Clear floats after the columns */\nsection::after {\n  content: \"\";\n  display: table;\n  clear: both;\n}\n\n/* Style the footer */\nfooter {\n  background-color: #777;\n  padding: 10px;\n  text-align: center;\n  color: yellow;\n}\n\n/* Responsive layout - makes the two columns/boxes stack on top of each other instead of next to each other, on small screens */\n@media (max-width: 600px) {\n  nav, article {\n    width: 100%;\n    height: auto;\n  }\n}\n</style>\n</head>\n<body>\n\n\n<header>\n  <h2>Free DevOps Course By Abhishek</h2>\n</header>\n\n<section>\n  <nav>\n    <ul>\n      <li><a href=\"www.youtube.com/@AbhishekVeeramalla\">YouTube</a></li>\n      <li><a href=\"www.linkedin.com/in/abhishek-veeramalla-77b33996/\">LinkedIn</a></li>\n      <li><a href=\"https://telegram.me/abhishekveeramalla\">Telegram</a></li>\n    </ul>\n  </nav>\n  \n  <article>\n    <h1>Agenda</h1>\n    <p>Learn DevOps with strong foundational knowledge and practical understanding</p>\n    <p>Please Share the Channel with your friends and colleagues</p>\n  </article>\n</section>\n\n<footer>\n  <p>@AbhishekVeeramalla</p>\n</footer>\n\n</body>\n</html>\n\n"
  },
  {
    "path": "examples/python-web-app/devops/demo/tests.py",
    "content": "from django.test import TestCase\n\n# Create your tests here.\n"
  },
  {
    "path": "examples/python-web-app/devops/demo/urls.py",
    "content": "from django.urls import path\n\nfrom . import views\n\nurlpatterns = [\n    path('', views.index, name='index'),\n]\n"
  },
  {
    "path": "examples/python-web-app/devops/demo/views.py",
    "content": "from django.http import HttpResponse\nfrom django.shortcuts import render\n\n\ndef index(request):\n    return render(request, 'demo_site.html')\n"
  },
  {
    "path": "examples/python-web-app/devops/devops/__init__.py",
    "content": ""
  },
  {
    "path": "examples/python-web-app/devops/devops/asgi.py",
    "content": "\"\"\"\nASGI config for devops project.\n\nIt exposes the ASGI callable as a module-level variable named ``application``.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.1/howto/deployment/asgi/\n\"\"\"\n\nimport os\n\nfrom django.core.asgi import get_asgi_application\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'devops.settings')\n\napplication = get_asgi_application()\n"
  },
  {
    "path": "examples/python-web-app/devops/devops/settings.py",
    "content": "\"\"\"\nDjango settings for devops project.\n\nGenerated by 'django-admin startproject' using Django 4.1.6.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.1/topics/settings/\n\nFor the full list of settings and their values, see\nhttps://docs.djangoproject.com/en/4.1/ref/settings/\n\"\"\"\n\nimport os\nfrom pathlib import Path\n\n# Build paths inside the project like this: BASE_DIR / 'subdir'.\nBASE_DIR = Path(__file__).resolve().parent.parent\n\n\n# Quick-start development settings - unsuitable for production\n# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/\n\n# SECURITY WARNING: keep the secret key used in production secret!\nSECRET_KEY = 'django-insecure-js0^(n81j2j1@&5fn!a_jh92*_05id$3tegf@g8frdo!q$fdm*'\n\n# SECURITY WARNING: don't run with debug turned on in production!\nDEBUG = True\n\nALLOWED_HOSTS = ['*']\n\n\n# Application definition\n\nINSTALLED_APPS = [\n    'django.contrib.admin',\n    'django.contrib.auth',\n    'django.contrib.contenttypes',\n    'django.contrib.sessions',\n    'django.contrib.messages',\n    'django.contrib.staticfiles',\n]\n\nMIDDLEWARE = [\n    'django.middleware.security.SecurityMiddleware',\n    'django.contrib.sessions.middleware.SessionMiddleware',\n    'django.middleware.common.CommonMiddleware',\n    'django.middleware.csrf.CsrfViewMiddleware',\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\n    'django.contrib.messages.middleware.MessageMiddleware',\n    'django.middleware.clickjacking.XFrameOptionsMiddleware',\n]\n\nROOT_URLCONF = 'devops.urls'\n\nTEMPLATES = [\n    {\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\n        'DIRS': [os.path.join(BASE_DIR, 'demo/templates')],\n        'APP_DIRS': True,\n        'OPTIONS': {\n            'context_processors': [\n                'django.template.context_processors.debug',\n                'django.template.context_processors.request',\n                'django.contrib.auth.context_processors.auth',\n                'django.contrib.messages.context_processors.messages',\n            ],\n        },\n    },\n]\n\nWSGI_APPLICATION = 'devops.wsgi.application'\n\n\n# Database\n# https://docs.djangoproject.com/en/4.1/ref/settings/#databases\n\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.sqlite3',\n        'NAME': BASE_DIR / 'db.sqlite3',\n    }\n}\n\n\n# Password validation\n# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators\n\nAUTH_PASSWORD_VALIDATORS = [\n    {\n        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',\n    },\n    {\n        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',\n    },\n]\n\n\n# Internationalization\n# https://docs.djangoproject.com/en/4.1/topics/i18n/\n\nLANGUAGE_CODE = 'en-us'\n\nTIME_ZONE = 'UTC'\n\nUSE_I18N = True\n\nUSE_TZ = True\n\n\n# Static files (CSS, JavaScript, Images)\n# https://docs.djangoproject.com/en/4.1/howto/static-files/\n\nSTATIC_URL = 'static/'\n\n# Default primary key field type\n# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field\n\nDEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'\n"
  },
  {
    "path": "examples/python-web-app/devops/devops/urls.py",
    "content": "\"\"\"devops URL Configuration\n\nThe `urlpatterns` list routes URLs to views. For more information please see:\n    https://docs.djangoproject.com/en/4.1/topics/http/urls/\nExamples:\nFunction views\n    1. Add an import:  from my_app import views\n    2. Add a URL to urlpatterns:  path('', views.home, name='home')\nClass-based views\n    1. Add an import:  from other_app.views import Home\n    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')\nIncluding another URLconf\n    1. Import the include() function: from django.urls import include, path\n    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))\n\"\"\"\nfrom django.contrib import admin\nfrom django.urls import include, path\n\nurlpatterns = [\n    path('demo/', include('demo.urls')),\n    path('admin/', admin.site.urls),\n]\n"
  },
  {
    "path": "examples/python-web-app/devops/devops/wsgi.py",
    "content": "\"\"\"\nWSGI config for devops project.\n\nIt exposes the WSGI callable as a module-level variable named ``application``.\n\nFor more information on this file, see\nhttps://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/\n\"\"\"\n\nimport os\n\nfrom django.core.wsgi import get_wsgi_application\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'devops.settings')\n\napplication = get_wsgi_application()\n"
  },
  {
    "path": "examples/python-web-app/devops/manage.py",
    "content": "#!/usr/bin/env python\n\"\"\"Django's command-line utility for administrative tasks.\"\"\"\nimport os\nimport sys\n\n\ndef main():\n    \"\"\"Run administrative tasks.\"\"\"\n    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'devops.settings')\n    try:\n        from django.core.management import execute_from_command_line\n    except ImportError as exc:\n        raise ImportError(\n            \"Couldn't import Django. Are you sure it's installed and \"\n            \"available on your PYTHONPATH environment variable? Did you \"\n            \"forget to activate a virtual environment?\"\n        ) from exc\n    execute_from_command_line(sys.argv)\n\n\nif __name__ == '__main__':\n    main()\n"
  },
  {
    "path": "examples/python-web-app/requirements.txt",
    "content": "Django\ntzdata\n"
  },
  {
    "path": "networking.md",
    "content": "# Docker Networking\n\nNetworking allows containers to communicate with each other and with the host system. Containers run isolated from the host system\nand need a way to communicate with each other and with the host system.\n\nBy default, Docker provides two network drivers for you, the bridge and the overlay drivers. \n\n```\ndocker network ls\n```\n\n```\nNETWORK ID          NAME                DRIVER\nxxxxxxxxxxxx        none                null\nxxxxxxxxxxxx        host                host\nxxxxxxxxxxxx        bridge              bridge\n```\n\n\n### Bridge Networking\n\nThe default network mode in Docker. It creates a private network between the host and containers, allowing\ncontainers to communicate with each other and with the host system.\n\n![image](https://user-images.githubusercontent.com/43399466/217745543-f40e5614-ac34-4b78-85a9-91b24512388d.png)\n\nIf you want to secure your containers and isolate them from the default bridge network you can also create your own bridge network.\n\n```\ndocker network create -d bridge my_bridge\n```\n\nNow, if you list the docker networks, you will see a new network.\n\n```\ndocker network ls\n\nNETWORK ID          NAME                DRIVER\nxxxxxxxxxxxx        bridge              bridge\nxxxxxxxxxxxx        my_bridge           bridge\nxxxxxxxxxxxx        none                null\nxxxxxxxxxxxx        host                host\n```\n\nThis new network can be attached to the containers, when you run these containers.\n\n```\ndocker run -d --net=my_bridge --name db training/postgres\n```\n\nThis way, you can run multiple containers on a single host platform where one container is attached to the default network and \nthe other is attached to the my_bridge network.\n\nThese containers are completely isolated with their private networks and cannot talk to each other.\n\n![image](https://user-images.githubusercontent.com/43399466/217748680-8beefd0a-8181-4752-a098-a905ebed5d2a.png)\n\n\nHowever, you can at any point of time, attach the first container to my_bridge network and enable communication\n\n```\ndocker network connect my_bridge web\n```\n\n![image](https://user-images.githubusercontent.com/43399466/217748726-7bb347d0-3736-4f89-bdff-31d240b15150.png)\n\n\n### Host Networking\n\nThis mode allows containers to share the host system's network stack, providing direct access to the host system's network.\n\nTo attach a host network to a Docker container, you can use the --network=\"host\" option when running a docker run command. When you use this option, the container has access to the host's network stack, and shares the host's network namespace. This means that the container will use the same IP address and network configuration as the host.\n\nHere's an example of how to run a Docker container with the host network:\n\n```\ndocker run --network=\"host\" <image_name> <command>\n```\n\nKeep in mind that when you use the host network, the container is less isolated from the host system, and has access to all of the host's network resources. This can be a security risk, so use the host network with caution.\n\nAdditionally, not all Docker image and command combinations are compatible with the host network, so it's important to check the image documentation or run the image with the --network=\"bridge\" option (the default network mode) first to see if there are any compatibility issues.\n\n### Overlay Networking\n\nThis mode enables communication between containers across multiple Docker host machines, allowing containers to be connected to a single network even when they are running on different hosts.\n\n### Macvlan Networking\n\nThis mode allows a container to appear on the network as a physical host rather than as a container.\n\n"
  },
  {
    "path": "volumes.md",
    "content": "# Docker Volumes\n\n## Problem Statement\n\nIt is a very common requirement to persist the data in a Docker container beyond the lifetime of the container. However, the file system\nof a Docker container is deleted/removed when the container dies. \n\n## Solution\n\nThere are 2 different ways how docker solves this problem.\n\n1. Volumes\n2. Bind Directory on a host as a Mount\n\n### Volumes \n\nVolumes aims to solve the same problem by providing a way to store data on the host file system, separate from the container's file system, \nso that the data can persist even if the container is deleted and recreated.\n\n![image](https://user-images.githubusercontent.com/43399466/218018334-286d8949-d155-4d55-80bc-24827b02f9b1.png)\n\n\nVolumes can be created and managed using the docker volume command. You can create a new volume using the following command:\n\n```\ndocker volume create <volume_name>\n```\n\nOnce a volume is created, you can mount it to a container using the -v or --mount option when running a docker run command. \n\nFor example:\n\n```\ndocker run -it -v <volume_name>:/data <image_name> /bin/bash\n```\n\nThis command will mount the volume <volume_name> to the /data directory in the container. Any data written to the /data directory\ninside the container will be persisted in the volume on the host file system.\n\n### Bind Directory on a host as a Mount\n\nBind mounts also aims to solve the same problem but in a complete different way.\n\nUsing this way, user can mount a directory from the host file system into a container. Bind mounts have the same behavior as volumes, but\nare specified using a host path instead of a volume name. \n\nFor example, \n\n```\ndocker run -it -v <host_path>:<container_path> <image_name> /bin/bash\n```\n\n## Key Differences between Volumes and Bind Directory on a host as a Mount\n\nVolumes are managed, created, mounted and deleted using the Docker API. However, Volumes are more flexible than bind mounts, as \nthey can be managed and backed up separately from the host file system, and can be moved between containers and hosts.\n\nIn a nutshell, Bind Directory on a host as a Mount are appropriate for simple use cases where you need to mount a directory from the host file system into\na container, while volumes are better suited for more complex use cases where you need more control over the data being persisted\nin the container.\n"
  }
]