Knowledge Bank
  • My GitBook
  • Miscellaneous
  • Project
    • Rider and Intellij
    • Code
    • Frontend
      • Condition
      • AddConditionModalDialog
    • Backend
    • e2e
      • fragments
  • JAVASCRIPT
    • Promise
    • Destructuring
    • Spread Syntax and Rest Parameters
    • Typescript
      • Examples of Types
      • React Typescript
    • This
    • Dot Notation vs Bracket Notation
    • Shallow vs Deep Clone
    • New ES Edition
  • C#
    • Project Note
    • Basic
    • Shortcut and Debugging
  • Programming Paradigms
    • SOLID Principles
    • Object Oriented Programming (OOP)
      • Evolution of OOP (Procedural to OOP)
      • Instantiation
      • 4 Pillars of OOP
      • Extra
    • Functional Programming (FP)
      • Idempotent
      • Imperative vs Declarative
      • Immutability
      • High Order Function and Closure
      • Currying
      • Partial Application
      • Memoization and Caching
      • Compose and Pipe
      • Extra
      • Example of FP
    • OOP vs FP
      • Composition vs Inheritance
  • DATA STRUCTURE
    • Big O
    • Data Structure
    • Array
    • Hash Table
    • Linked List
    • Queue and Stack
    • Tree
      • Binary Heap
      • Trie
    • Graph
      • Example of Graph
  • React-Redux
    • MobX
    • Best Practices
  • Algorithms
    • Recursion
      • Examples of Recursion
    • Sorting
    • Searching and Traversal
    • Dynamic Programming
  • REFACTORING
    • Clean Code
      • Formatting
      • Error Handling
      • Concurrency
      • Testing
      • SOLID Principles
      • Classes
      • Objects and Data Structures
      • Variables
      • Functions
    • Code Smells
      • Long Function
      • Duplicate Code
      • Loops
      • Double Negative
      • Christmas Tree Code
      • Complex Condition
      • Primitive Obsession
      • Speculative Generality
      • God Class
      • Long Parameter List
  • Junior to Senior
    • AWS
      • Lambda
    • Session + Authentication
    • Redis
    • Kubernetes
      • Networking
      • Services
      • Deployment
      • Replica Set
      • YAML
      • pod-definition.yml
      • Kubectl
      • Pods
      • Fundamentals
    • Docker
      • Operating System - Extra
      • Dockerfile - Docker Image
      • Docker Storage
      • Docker Network
      • Docker Registry
      • Docker Command
      • Docker Compose
      • Docker Compose - Postgres
    • Security
      • Logging
      • HTTPS, Cross-Site-Scripting (XSS) and Cross-Site-Request-Forgery (CSRF)
      • 3rd Party Library
      • Injection
      • Code Secret, Secure Header, Access Control, Data Management, Authentication
    • CI/CD
    • SPA vs Server-Side Rendering
    • Performance
      • Optimized Code
      • Critical Render Path
      • Backend Optimization
      • Minimized Files and Images
      • Minimized Delivery
  • SECURITY
    • Encryption
    • SSH
  • Command
  • Cheatsheet
    • NPM
    • GIT
  • Writing Template
    • Guide
    • API
    • ChangeLog
    • FAQ
  • Linux
Powered by GitBook
On this page

Was this helpful?

  1. Junior to Senior

Docker

PreviousFundamentalsNextOperating System - Extra

Last updated 3 years ago

Was this helpful?

Why do you need Docker?

  1. Modern application has various different technologies and they does not stand still (require constant upgrade) which requires different dependencies to the underlying OS and compatibility between these services and their library and dependencies. AVOID THE MATRIX FROM HELL!!!

  2. Another reason is we need to guarantee that the project can run on on a different machine / environment (test, UAT, prod) without any errors. And this is where containers come in.

What can Docker do?

Able to run each component in a separate container with its own dependencies and its own libraries all on the same VM and the OS but within separate environments or containers (but on same OS kernel)

Companies uses micro-services and have their products composed of multiple layers. These layers can be considered services, each with their own container doing its own thing and communicating with each other to make the whole system work.

The problem with micro-services is each service may have its own requirements from different node versions to conflicting library dependencies. And when you add in the fact that every developer's machine and environment is different, it can be challenged to onboard new developers quickly or run this service on another machine. So, Docker come up with a solution that will run each application in a separate container with its own dependencies and its own libraries. Different containers are run on completely isolated environment but sharing the same OS kernel.

History

Before we have Docker, we have Virtualization / Virtual Machines or sometimes we called sandbox environments. It contains a full fledged computer with its virtual hardware operating system and as you can see in this diagram it's like having many computer sitting on top of another computer. This solves the problem because the app can run in an environment that is consistent and predictable. The downside is less speed.

Docker

Docker containers wrap up the software in a complete file system that contains everything they needs to run.

Advantages:

  • Lightweight compare to VM because instead of virtual OS, it rely on host OS.

  • Faster boot-up time

  • Can only run single application on each container.

  • Can be scaled up easily as you create more and more containers and use container orchestration like Kubernetes

Characteristics:

  • Each container has an image - Docker use this to bundle your application into a standalone executable package that can live inside of a container. For example, we want a node server, so this image is read by docker and it generates container that run node server for us.

  • Each container environment is isolated from host machines. But compared to VM's complete isolation from each other, container has less isolation as more resources are shared between the containers, like kernel.

  • Docker Hub is similar to NPM in JS land - it provides a store-like website where you can search and download images to use

  • Image also has a file system just like we have files on our computer and that's what we call a volume.

But it is not one technology over the other. The best practice is to use both tech: virtualization and containers to utilize all the advantages. We may not provision for many virtual machine as before because one virtual machine will have hundreds of container instead of previous one VM for one container.

To summarize, Docker bundles your application into an image - a standalone executable package and Docker executes this image in this container and the environment inside the container is completely isolated from that of the host machine.

What can you containers? You can containerize everything and in the future that is how application is run, there is no more installing, they are just going to run it using docker and easily delete without extra clean up

Creating many containers as you scale up and use Load Balancer to distribute request