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
  2. Docker

Docker Network

When you install docker, it creates 3 networks automatically: bridge, none and host.

Bridge is the default network a container get attached to. If you want attach another network, you can specify the network info:

  • docker run ubuntu --network=none

  • docker run ubuntu --network=host

Bridge Network

Bridge network is private internal network created by docker on the host. Container attached to this network by default and they get internal IP address The container can access each other using this internal IP. To access any of these container externally, use port mapping.

Host Network

Another way to access the container externally is to associate the container to the hosts network. This takes out any network isolation between the docker host and docker container, meaning because the container is using the host network to be accessible externally and not requiring any port mapping. In this case, you will not be able to run multiple instance on the same host on the same port as the ports are now common to all containers in the host network.

None Network

With the none network, the container is not attached to any network and does not have any access to the external network or other container. They run in isolated network.

User-defined networks

How do you group different container on different internal IP? By default docker only create one internal bridge network. We can have user-defined network using the command:

docker network create  --driver bridge  --subnet 182.18.0.0/16 custom-isolated-network

docker network ls
// list all networks

The right way to connect between container (i.e web container connect to mysql container) is using the container name. Docker has embedded DNS that help resolve each other using the container name. The built-in DNS always run on 127.0.0.11

How does docker implement networking? Docker uses network namespaces that create a separate name space for each container. It then uses virtual Ethernet pairs to connect container together.

PreviousDocker StorageNextDocker Registry

Last updated 4 years ago

Was this helpful?