reading-notes2

https://m7madmomani2.github.io/reading-notes2

View the Project on GitHub M7madMomani2/reading-notes2

About Docker

  • Docker : which is a way to isolate and run entire applications. With Docker it doesn’t matter if you are using a Mac, Windows, or Linux computer anymore. The entire development environment is isolated: programming language, software packages, databases, and more. With Docker we now longer have to mess around with virtual environments. We can faithfully reproduce a production environment locally. And Docker can be shared among team members so everyone is working on the same setup. Wins all around. Docker is really just Linux containers which are a type of virtualization. Virtualization has its roots at the beginning of computer science when large, expensive mainframe computers were the norm. How could multiple programmers use the same single machine? The answer was virtualization and specifically virtual machines which are complete copies of a computer system from the operating system on up. in recent years Linux containers, also known as “containerization,” has become increasingly popular. For most applications, a virtual machine provides far more resources than are needed and a container is more than sufficient. This, fundamentally, is what Docker is. A way to implement Linux containers!

Images and Containers

  • Images and containers are the two fundamental concepts to grasp when you start with Docker. An image is a snapshot in time of what a project contains. A container is a running instance of the image.
  • When we ran hello-world we used an official Docker image. We did not have to create the image ourself. But typically we will create custom images and we do so using a Dockerfile. We also will use docker-compose.yml files to run the containers.

A baking analogy we can use here is as follows:

  • A Dockerfile is the recipe for a cake
  • An image is a snapshot of the recipe at a given time
  • A docker-compose.yml says how to make the cake
  • And the container is the actual, baked cake

Conclusion

  • Docker is a way to run Linux containers
  • Containers are a lightweight alternative to Virtual Machines
  • Dockerfile is a list of instructions for creating an image
  • Images are made up of one or more layers
  • Containers are a running instance of an image
  • docker-compose.yml controls how to run the container
  • Containers are stateless and ephemeral in nature. We can link the local filesystem via volumes but things become more complex with databases

Library Website and API

  • Django REST Framework works alongside the Django web framework to create web APIs. We cannot build a web API with only Django Rest Framework; it always must be added to a project after Django itself has been installed and configured.
  • The most important takeaway is that Django creates websites containing webpages, while Django REST Framework creates web APIs which are a collection of URL endpoints containing available HTTP verbs that return JSON.
  • To illustrate these concepts, we will build out a basic Library website with traditional Django and then extend it into a web API with Django REST Framework.
  • The files have the following roles:
  • init.py is a Python way to treat a directory as a package; it is empty
  • asgi.py stands for Asynchronous Server Gateway Interface and is a new option in Django 3.0+
  • settings.py contains all the configuration for our project
  • urls.py controls the top-level URL routes
  • wsgi.py stands for Web Server Gateway Interface and helps Django serve the eventual web pages
  • manage.py executes various Django commands such as running the local web server or creating a new app.
  • admin.py is a configuration file for the built-in Django Admin app
  • apps.py is a configuration file for the app itself
  • the migrations/ directory stores migrations files for database changes
  • models.py is where we define our database models
  • tests.py is for our app-specific tests
  • views.py is where we handle the request/response logic for our web app
  • A serializer : translates data into a format that is easy to consume over the internet, typically JSON, and is displayed at an API endpoint