Shakiba Moshiri
  • Shakiba Moshiri (شکیبا مشیری)
  • opt
    • high traffic site optimization
      • infrastructure check
      • infrastructure test
  • tools
    • Cryptsetup
      • Container encryption using cryptsetup
    • curly
      • ftp
      • ssl
      • http
      • dns
      • ip
      • email
    • SSH
      • ssh password-less login
        • Untitled
    • volumes and FS
      • installing Gluster fs on Ubuntu 18.04 server
      • Accessing Gluster FS from the client machine
  • CDN
    • How does a CDN work
  • Server Panel
  • DirectAdmin
    • DirectAdmin through a reverse proxy
  • Web Server
    • Nginx
      • Live Steaming with Nginx and FFMPEG
  • Security
  • Container
    • Docker Networking 101
      • why docker networking is important?
      • type of networking in docker
    • Docker
      • How to run gitlab-runner with docker
      • using vim inside any container without installing it
      • Cannot connect to the Docker daemon at unix:///var/run/docker.sock
      • moving docker images around using ssh and pipe
      • How can I make docker-compose pull images using a socks5 proxy?
  • Stack Overflow
  • Github
  • vmware
    • tools
      • how to install vmware CLI govc on Linux
  • Windows
    • How to Erase a Recovery Partition in Windows
Powered by GitBook
On this page

Was this helpful?

  1. Container
  2. Docker Networking 101

why docker networking is important?

PreviousDocker Networking 101Nexttype of networking in docker

Last updated 3 years ago

Was this helpful?

One thing about Docker is, it makes it very easy to deal with containers and managing them. Simple by an one-liner we can run any container like so:

docker container run -dp 80:80 nginx:alpine

Want to have ten Nginx running simultaneously? No problem

for N in {1..10}; do
    docker container run --rm -dp 8${N}:80 --name nginx_${N} nginx:alpine
done

And here is a shot of it:

Or the output:

docker container ls
CONTAINER ID   IMAGE                 COMMAND                  CREATED              STATUS              PORTS                                 NAMES
25bec68cb5f0   nginx:stable-alpine   "/docker-entrypoint.…"   29 seconds ago       Up 23 seconds       0.0.0.0:810->80/tcp, :::810->80/tcp   nginx_10
42817975af5c   nginx:stable-alpine   "/docker-entrypoint.…"   33 seconds ago       Up 28 seconds       0.0.0.0:89->80/tcp, :::89->80/tcp     nginx_9
fc0bb78c7652   nginx:stable-alpine   "/docker-entrypoint.…"   37 seconds ago       Up 33 seconds       0.0.0.0:88->80/tcp, :::88->80/tcp     nginx_8
d40c639f35e7   nginx:stable-alpine   "/docker-entrypoint.…"   42 seconds ago       Up 37 seconds       0.0.0.0:87->80/tcp, :::87->80/tcp     nginx_7
78312e3e8a4d   nginx:stable-alpine   "/docker-entrypoint.…"   48 seconds ago       Up 42 seconds       0.0.0.0:86->80/tcp, :::86->80/tcp     nginx_6
bec616fe6e3c   nginx:stable-alpine   "/docker-entrypoint.…"   53 seconds ago       Up 48 seconds       0.0.0.0:85->80/tcp, :::85->80/tcp     nginx_5
f8ea11810a30   nginx:stable-alpine   "/docker-entrypoint.…"   58 seconds ago       Up 53 seconds       0.0.0.0:84->80/tcp, :::84->80/tcp     nginx_4
5300c419a04e   nginx:stable-alpine   "/docker-entrypoint.…"   About a minute ago   Up 58 seconds       0.0.0.0:83->80/tcp, :::83->80/tcp     nginx_3
7c8a6fa2ede7   nginx:stable-alpine   "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:82->80/tcp, :::82->80/tcp     nginx_2
941453ac23a9   nginx:stable-alpine   "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:81->80/tcp, :::81->80/tcp     nginx_1

So not just 10 containers we can run as many as we want but what do they do for us? If you have 10 or 1000 Nginx containers? And from now networking comes to the play because if we want to join to different containers to communicate with each other we have to connect them to each other and this connection is possible through networking.

The bigger or the more complex our containers' communication is, the more depth understanding is needed about networking. Thus lets go to next part.