What is an Image

What is an Image:

App binaries and dependencies.


Metadata about the image data and how to run the image.


Official Definition: "An Image is an ordered collection of root filesystem changes and the corresponding execution parameters for use within a container runtime."


Not a complete OS. there's not actually a complete OS. There's no kernel. There's no kernel modules.


It's really just the binaries that your application needs because the host provides the kernel.
That's one of the distinct characteristics around containers that makes it different from a virtual.
It's not booting up a full operating system.

It's really just starting an application, and that image can be really small.

Small as one file.

Even you make it as Big as a CentOS, Ubuntu distro with apt, and apache, PHP, and more installed.


The Mighty Hub using DOCKER Hub Registry Images:

Basics of Docker Hub (hub.docker.com)
Find official and other good public images
Download images and basics of image tags

Register and login to hub.docker.com and search for the images (Eg: nginx) 
There you can see the,

Supported tags and respective Dockerfile links

Note: // All these tags in the same line are targeting same image.
Eg:


You can pull the image by using the tags.

Eg: docker pull nginx, docker pull nginx:1.17.5.


"Explorer" tab shows you the official images,

Images and the Layers:

Image layers
Union file system
history and inspect commands
copy on write


Image layers, this is a fundamental concept of how Docker works. It uses something called the union file system to present a series of file system changes as an actual file system.

The history and inspect commands and see how we can use them to understand

PS C:\Users\MOHI> docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              775349758637        10 days ago         64.2MB
httpd               latest              d3017f59d5e2        11 days ago         165MB
nginx               alpine              b6753551581f        2 weeks ago         21.4MB
nginx               latest              540a289bab6c        2 weeks ago         126MB
alpine              latest              965ea09ff2eb        2 weeks ago         5.55MB
mysql               latest              c8ee894bd2bd        3 weeks ago         456MB
centos              latest              0f3e07c0138f        5 weeks ago         220MB
centos              7                   67fa590cfc1c        2 months ago        202MB
ubuntu              14.04               2c5e00d77a67        5 months ago        188MB
hello-world         latest              fce289e99eb9        10 months ago       1.84kB
elasticsearch       2                   5e9d896dc62c        14 months ago       479MB


PS C:\Users\MOHI> docker history nginx:latest
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
540a289bab6c        2 weeks ago         /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B
<missing>           2 weeks ago         /bin/sh -c #(nop)  STOPSIGNAL SIGTERM           0B
<missing>           2 weeks ago         /bin/sh -c #(nop)  EXPOSE 80                    0B
<missing>           2 weeks ago         /bin/sh -c ln -sf /dev/stdout /var/log/nginx…   22B
<missing>           2 weeks ago         /bin/sh -c set -x     && addgroup --system -…   57MB    // Some data changes so size differs
<missing>           2 weeks ago         /bin/sh -c #(nop)  ENV PKG_RELEASE=1~buster     0B
<missing>           2 weeks ago         /bin/sh -c #(nop)  ENV NJS_VERSION=0.3.6        0B
<missing>           2 weeks ago         /bin/sh -c #(nop)  ENV NGINX_VERSION=1.17.5     0B
<missing>           3 weeks ago         /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B      //Only Meta data changes since 0KB
<missing>           3 weeks ago         /bin/sh -c #(nop)  CMD ["bash"]                 0B
<missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:74b2987cacab5a6b0…   69.2MB



What do I mean by image layers?
It's actually transparent completely to you when you're using Docker, but when you start digging into certain commands, like the history command, the inspect and commit, you start to get a sense that an image. 

Every image starts from the very beginning with a blank layer known as scratch.

Then every set of changes that happens after that on the file system, in the image, is another layer.

You might have one layer, you might have dozens of layers and some layers maybe no change in terms of the file size.

You'll notice on here that we actually have a change here that was simply a metadata change about.

we're starting with one layer. Every layer gets its own unique SHA that helps the system identify.

What happens if I have another image that's also using the same version of nginx?
Well, that image can have its own changes, on top of the same layer that I have in my cache. This is where the fundamental concept of the cache of image layers saves us a whole bunch of time and space. Because we don't need to download layers we already have, and remember it uses a unique SHA for each layer so it's guaranteed to be the exact layer it needs. It knows how to match them between Docker Hub and our local cache. As we make changes to our images, they create more layers.

If we decide that we want to have the same image be the base image for more layers, then it's only ever storing one copy of each layer.

In this system, really, one of the biggest benefits is that we're never storing the same image data more than once on our file system.

It also means that when we're uploading and downloading we don't need to upload and download the same layers that we already have on the other side.


DNS round robin test (Load balancing):

DNS round robin test:

Ever since Docker engine 1.11, we can have multiple containers on a created network respond to the same DNS address (Load balancing).

Using image: elasticsearch:2
Option: --net-alias search
For example, start two elasticsearch containers with "–net-alias search" and from within the network, using the ‘search’ as the DNS name for connecting, you’d get 1 of the 2 servers at random.
Run alpine nslookup search with --net to see the two containers list for the same DNS name.
Run centos curl -s search:9200 with --net multiple times until you see both "name" fileds show

// Creating a network "mohi_nw":
PS C:\Users\MOHI> docker network create mohi_nw
bdc0a10f5d4acdc26b70953ab8233c5fe858b4cc265453f278bbc670f4f52b6d

// Creating two containers of "elasticsearch":
PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias search elasticsearch:2
Unable to find image 'elasticsearch:2' locally
2: Pulling from library/elasticsearch
05d1a5232b46: Pull complete
5cee356eda6b: Pull complete
89d3385f0fd3: Pull complete
65dd87f6620b: Pull complete
78a183a01190: Pull complete
1a4499c85f97: Pull complete
2c9d39b4bfc1: Pull complete
1b1cec2222c9: Pull complete
59ff4ce9df68: Pull complete
1976bc3ee432: Pull complete
a27899b7a5b5: Pull complete
b0fc7d2c927a: Pull complete
6d94b96bbcd0: Pull complete
6f5bf40725fd: Pull complete
2bf2a528ae9a: Pull complete
Digest: sha256:41ed3a1a16b63de740767944d5405843db00e55058626c22838f23b413aa4a39
Status: Downloaded newer image for elasticsearch:2
4fd6c4c81d858e61414d7c66af81d9ba29443d41ed62ab18586ec9cf9ca8c093

PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias search elasticsearch:2
9d19a976898957aa57d0abcdfcee982782bd762e4cc8c6ae4d0a31fea6f71dcc

PS C:\Users\MOHI> docker container ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
9d19a9768989        elasticsearch:2     "/docker-entrypoint.…"   3 minutes ago       Up 3 minutes        9200/tcp, 9300/tcp   nostalgic_visvesvaraya
4fd6c4c81d85        elasticsearch:2     "/docker-entrypoint.…"   6 minutes ago       Up 5 minutes        9200/tcp, 9300/tcp   fervent_antonelli

Now we need to run a test to make sure we can get to both of these with the same DNS names. so creating few dockers to test DNS (nslookup and curl)

PS C:\Users\MOHI> docker container run --rm --net mohi_nw alpine nslookup search
nslookup: can't resolve '(null)': Name does not resolve

Name:      search
Address 1: 172.19.0.2 search.mohi_nw
Address 2: 172.19.0.3 search.mohi_nw

// Checking the load balancing by using centos container with the curl:

PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
729ec3a6ada3: Pull complete
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Downloaded newer image for centos:latest
{
  "name" : "Arena",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "4SKj4oiTQhK4nJXPZWhPHg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
{
  "name" : "Polaris",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "iLhlDVkJQP6ZuhBjdVyHAg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}

PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
{
  "name" : "Polaris",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "iLhlDVkJQP6ZuhBjdVyHAg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s search:9200
{
  "name" : "Arena",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "4SKj4oiTQhK4nJXPZWhPHg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}



///  Same DNS round robin testing with the different alias value as "test":

PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias test elasticsearch:2
852b8032318f224f060a4faf3d8f3272040bc14a5582c3a0d7f0a0ad37347ec7
PS C:\Users\MOHI> docker container run -d --net mohi_nw --net-alias test elasticsearch:2
9417e1493b28999385a072db6f65e46e83fcf1253ed221ec5fb61eb0aa0438cb
PS C:\Users\MOHI> docker container run --rm --net mohi_nw alpine nslookup search
nslookup: can't resolve '(null)': Name does not resolve

Name:      search
Address 1: 172.19.0.2 search.mohi_nw
Address 2: 172.19.0.3 search.mohi_nw
PS C:\Users\MOHI> docker container run --rm --net mohi_nw alpine nslookup test
nslookup: can't resolve '(null)': Name does not resolve

Name:      test
Address 1: 172.19.0.5 test.mohi_nw
Address 2: 172.19.0.4 test.mohi_nw
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s test:9200
{
  "name" : "Nikki",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "tkoLDOgKQHO7qyCguKTA9g",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}
PS C:\Users\MOHI> docker container run --rm --net mohi_nw centos curl -s test:9200
{
  "name" : "Brothers Grimm",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "qg_eVQhISLC7UxyKTicXIQ",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace8240fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}

Creating various distros of Linux, installing "Curl" and check it's version:

Creating various distros of Linux, installing "Curl" and check it's version:

Installing Linux container:
Using --rm : Automatically remove the container when it exits.

PS C:\Users\MOHI> docker container run --rm -it centos:7 bash
Unable to find image 'centos:7' locally
7: Pulling from library/centos
d8d02d457314: Pull complete
Digest: sha256:307835c385f656ec2e2fec602cf093224173c51119bbebd602c53c3653a3d6eb
Status: Downloaded newer image for centos:7

[root@344b7c870c4a /]# yum update curl
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: centos.mirrors.estointernet.in
 * extras: centos.mirrors.estointernet.in
 * updates: centos.mirrors.estointernet.in
base                                                                                                                                                                                                       | 3.6 kB  00:00:00
extras                                                                                                                                                                                                     | 2.9 kB  00:00:00
updates                                                                                                                                                                                                    | 2.9 kB  00:00:00
(1/4): base/7/x86_64/group_gz                                                                                                                                                                              | 165 kB  00:00:00
(2/4): extras/7/x86_64/primary_db                                                                                                                                                                          | 153 kB  00:00:00
(3/4): updates/7/x86_64/primary_db                                                                                                                                                                         | 2.8 MB  00:00:00
(4/4): base/7/x86_64/primary_db                                                                                                                                                                            | 6.0 MB  00:00:02
Resolving Dependencies
--> Running transaction check
---> Package curl.x86_64 0:7.29.0-51.el7_6.3 will be updated
---> Package curl.x86_64 0:7.29.0-54.el7 will be an update
--> Processing Dependency: libcurl = 7.29.0-54.el7 for package: curl-7.29.0-54.el7.x86_64
--> Running transaction check
---> Package libcurl.x86_64 0:7.29.0-51.el7_6.3 will be updated
---> Package libcurl.x86_64 0:7.29.0-54.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================================
 Package                                               Arch                                                 Version                                                      Repository                                          Size
==================================================================================================================================================================================================================================
Updating:
 curl                                                  x86_64                                               7.29.0-54.el7                                                base                                               270 k
Updating for dependencies:
 libcurl                                               x86_64                                               7.29.0-54.el7                                                base                                               222 k

Transaction Summary
==================================================================================================================================================================================================================================
Upgrade  1 Package (+1 Dependent package)

Total download size: 493 k
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/base/packages/libcurl-7.29.0-54.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for libcurl-7.29.0-54.el7.x86_64.rpm is not installed
(1/2): libcurl-7.29.0-54.el7.x86_64.rpm                                                                                                                                                                    | 222 kB  00:00:00
(2/2): curl-7.29.0-54.el7.x86_64.rpm                                                                                                                                                                       | 270 kB  00:00:00
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                             1.2 MB/s | 493 kB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-6.1810.2.el7.centos.x86_64 (@CentOS)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libcurl-7.29.0-54.el7.x86_64                                                                                                                                                                                   1/4
  Updating   : curl-7.29.0-54.el7.x86_64                                                                                                                                                                                      2/4
  Cleanup    : curl-7.29.0-51.el7_6.3.x86_64                                                                                                                                                                                  3/4
  Cleanup    : libcurl-7.29.0-51.el7_6.3.x86_64                                                                                                                                                                               4/4
  Verifying  : libcurl-7.29.0-54.el7.x86_64                                                                                                                                                                                   1/4
  Verifying  : curl-7.29.0-54.el7.x86_64                                                                                                                                                                                      2/4
  Verifying  : curl-7.29.0-51.el7_6.3.x86_64                                                                                                                                                                                  3/4
  Verifying  : libcurl-7.29.0-51.el7_6.3.x86_64                                                                                                                                                                               4/4

Updated:
  curl.x86_64 0:7.29.0-54.el7

Dependency Updated:
  libcurl.x86_64 0:7.29.0-54.el7

Complete!
[root@344b7c870c4a /]# curl --version
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.36 zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets
[root@344b7c870c4a /]#


PS C:\Users\MOHI> docker container ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
344b7c870c4a        centos:7            "bash"              5 seconds ago       Up 2 seconds                            sleepy_banzai


Installing Ubuntu container:

PS C:\Users\MOHI> docker container run --rm -it ubuntu:14.04 bash
Unable to find image 'ubuntu:14.04' locally
14.04: Pulling from library/ubuntu
a7344f52cb74: Pull complete
515c9bb51536: Pull complete
e1eabe0537eb: Pull complete
4701f1215c13: Pull complete
Digest: sha256:2f7c79927b346e436cc14c92bd4e5bd778c3bd7037f35bc639ac1589a7acfa90
Status: Downloaded newer image for ubuntu:14.04
root@edc7c3a45581:/# apt-get update && apt-get install curl   (can also give apt-get update && apt-get install -y curl)

root@edc7c3a45581:/# apt-get update && apt-get install curl
Get:1 http://security.ubuntu.com trusty-security InRelease [65.9 kB]
Ign http://archive.ubuntu.com trusty InRelease
Get:2 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:3 http://security.ubuntu.com trusty-security/main amd64 Packages [1032 kB]
Get:4 http://archive.ubuntu.com trusty-backports InRelease [65.9 kB]
Get:5 http://archive.ubuntu.com trusty Release.gpg [933 B]
Get:6 http://archive.ubuntu.com trusty-updates/main amd64 Packages [1460 kB]
Get:7 http://security.ubuntu.com trusty-security/restricted amd64 Packages [18.1 kB]
Get:8 http://security.ubuntu.com trusty-security/universe amd64 Packages [377 kB]
Get:9 http://security.ubuntu.com trusty-security/multiverse amd64 Packages [4730 B]
Get:10 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [21.4 kB]
Get:11 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [671 kB]
Get:12 http://archive.ubuntu.com trusty-updates/multiverse amd64 Packages [16.1 kB]
Get:13 http://archive.ubuntu.com trusty-backports/main amd64 Packages [14.7 kB]
Get:14 http://archive.ubuntu.com trusty-backports/restricted amd64 Packages [40 B]
Get:15 http://archive.ubuntu.com trusty-backports/universe amd64 Packages [52.5 kB]
Get:16 http://archive.ubuntu.com trusty-backports/multiverse amd64 Packages [1392 B]
Get:17 http://archive.ubuntu.com trusty Release [58.5 kB]
Get:18 http://archive.ubuntu.com trusty/main amd64 Packages [1743 kB]
Get:19 http://archive.ubuntu.com trusty/restricted amd64 Packages [16.0 kB]
Get:20 http://archive.ubuntu.com trusty/universe amd64 Packages [7589 kB]
Get:21 http://archive.ubuntu.com trusty/multiverse amd64 Packages [169 kB]
Fetched 13.4 MB in 38s (348 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  ca-certificates krb5-locales libasn1-8-heimdal libcurl3 libgssapi-krb5-2
  libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal
  libheimntlm0-heimdal libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1
  libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2
  libroken18-heimdal librtmp0 libsasl2-2 libsasl2-modules libsasl2-modules-db
  libwind0-heimdal openssl
Suggested packages:
  krb5-doc krb5-user libsasl2-modules-otp libsasl2-modules-ldap
  libsasl2-modules-sql libsasl2-modules-gssapi-mit
  libsasl2-modules-gssapi-heimdal
The following NEW packages will be installed:
  ca-certificates curl krb5-locales libasn1-8-heimdal libcurl3
  libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal
  libheimntlm0-heimdal libhx509-5-heimdal libidn11 libk5crypto3 libkeyutils1
  libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2
  libroken18-heimdal librtmp0 libsasl2-2 libsasl2-modules libsasl2-modules-db
  libwind0-heimdal openssl
0 upgraded, 25 newly installed, 0 to remove and 5 not upgraded.
Need to get 2660 kB of archives.
After this operation, 11.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libroken18-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [39.9 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libasn1-8-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [160 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libkrb5support0 amd64 1.12+dfsg-2ubuntu5.4 [31.1 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libk5crypto3 amd64 1.12+dfsg-2ubuntu5.4 [79.4 kB]
Get:5 http://archive.ubuntu.com/ubuntu/ trusty/main libkeyutils1 amd64 1.5.6-1 [7318 B]
Get:6 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libkrb5-3 amd64 1.12+dfsg-2ubuntu5.4 [262 kB]
Get:7 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libgssapi-krb5-2 amd64 1.12+dfsg-2ubuntu5.4 [114 kB]
Get:8 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libhcrypto4-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [84.1 kB]
Get:9 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libheimbase1-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [29.0 kB]
Get:10 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libwind0-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [47.9 kB]
Get:11 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libhx509-5-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [104 kB]
Get:12 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libkrb5-26-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [196 kB]
Get:13 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libheimntlm0-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [15.2 kB]
Get:14 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libgssapi3-heimdal amd64 1.6~git20131207+dfsg-1ubuntu1.2 [89.7 kB]
Get:15 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libidn11 amd64 1.28-1ubuntu2.2 [94.6 kB]
Get:16 http://archive.ubuntu.com/ubuntu/ trusty/main libsasl2-modules-db amd64 2.1.25.dfsg1-17build1 [14.9 kB]
Get:17 http://archive.ubuntu.com/ubuntu/ trusty/main libsasl2-2 amd64 2.1.25.dfsg1-17build1 [56.5 kB]
Get:18 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libldap-2.4-2 amd64 2.4.31-1+nmu2ubuntu8.5 [153 kB]
Get:19 http://archive.ubuntu.com/ubuntu/ trusty-updates/main librtmp0 amd64 2.4+20121230.gitdf6c518-1ubuntu0.1 [50.4 kB]
Get:20 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libcurl3 amd64 7.35.0-1ubuntu2.20 [173 kB]
Get:21 http://archive.ubuntu.com/ubuntu/ trusty-updates/main openssl amd64 1.0.1f-1ubuntu2.27 [489 kB]
Get:22 http://archive.ubuntu.com/ubuntu/ trusty-updates/main ca-certificates all 20170717~14.04.2 [166 kB]
Get:23 http://archive.ubuntu.com/ubuntu/ trusty-updates/main krb5-locales all 1.12+dfsg-2ubuntu5.4 [14.0 kB]
Get:24 http://archive.ubuntu.com/ubuntu/ trusty/main libsasl2-modules amd64 2.1.25.dfsg1-17build1 [64.3 kB]
Get:25 http://archive.ubuntu.com/ubuntu/ trusty-updates/main curl amd64 7.35.0-1ubuntu2.20 [123 kB]
Fetched 2660 kB in 20s (132 kB/s)
Preconfiguring packages ...
Selecting previously unselected package libroken18-heimdal:amd64.
(Reading database ... 11585 files and directories currently installed.)
Preparing to unpack .../libroken18-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libroken18-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libasn1-8-heimdal:amd64.
Preparing to unpack .../libasn1-8-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libasn1-8-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libkrb5support0:amd64.
Preparing to unpack .../libkrb5support0_1.12+dfsg-2ubuntu5.4_amd64.deb ...
Unpacking libkrb5support0:amd64 (1.12+dfsg-2ubuntu5.4) ...
Selecting previously unselected package libk5crypto3:amd64.
Preparing to unpack .../libk5crypto3_1.12+dfsg-2ubuntu5.4_amd64.deb ...
Unpacking libk5crypto3:amd64 (1.12+dfsg-2ubuntu5.4) ...
Selecting previously unselected package libkeyutils1:amd64.
Preparing to unpack .../libkeyutils1_1.5.6-1_amd64.deb ...
Unpacking libkeyutils1:amd64 (1.5.6-1) ...
Selecting previously unselected package libkrb5-3:amd64.
Preparing to unpack .../libkrb5-3_1.12+dfsg-2ubuntu5.4_amd64.deb ...
Unpacking libkrb5-3:amd64 (1.12+dfsg-2ubuntu5.4) ...
Selecting previously unselected package libgssapi-krb5-2:amd64.
Preparing to unpack .../libgssapi-krb5-2_1.12+dfsg-2ubuntu5.4_amd64.deb ...
Unpacking libgssapi-krb5-2:amd64 (1.12+dfsg-2ubuntu5.4) ...
Selecting previously unselected package libhcrypto4-heimdal:amd64.
Preparing to unpack .../libhcrypto4-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libhcrypto4-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libheimbase1-heimdal:amd64.
Preparing to unpack .../libheimbase1-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libheimbase1-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libwind0-heimdal:amd64.
Preparing to unpack .../libwind0-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libwind0-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libhx509-5-heimdal:amd64.
Preparing to unpack .../libhx509-5-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libhx509-5-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libkrb5-26-heimdal:amd64.
Preparing to unpack .../libkrb5-26-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libkrb5-26-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libheimntlm0-heimdal:amd64.
Preparing to unpack .../libheimntlm0-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libheimntlm0-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libgssapi3-heimdal:amd64.
Preparing to unpack .../libgssapi3-heimdal_1.6~git20131207+dfsg-1ubuntu1.2_amd64.deb ...
Unpacking libgssapi3-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Selecting previously unselected package libidn11:amd64.
Preparing to unpack .../libidn11_1.28-1ubuntu2.2_amd64.deb ...
Unpacking libidn11:amd64 (1.28-1ubuntu2.2) ...
Selecting previously unselected package libsasl2-modules-db:amd64.
Preparing to unpack .../libsasl2-modules-db_2.1.25.dfsg1-17build1_amd64.deb ...
Unpacking libsasl2-modules-db:amd64 (2.1.25.dfsg1-17build1) ...
Selecting previously unselected package libsasl2-2:amd64.
Preparing to unpack .../libsasl2-2_2.1.25.dfsg1-17build1_amd64.deb ...
Unpacking libsasl2-2:amd64 (2.1.25.dfsg1-17build1) ...
Selecting previously unselected package libldap-2.4-2:amd64.
Preparing to unpack .../libldap-2.4-2_2.4.31-1+nmu2ubuntu8.5_amd64.deb ...
Unpacking libldap-2.4-2:amd64 (2.4.31-1+nmu2ubuntu8.5) ...
Selecting previously unselected package librtmp0:amd64.
Preparing to unpack .../librtmp0_2.4+20121230.gitdf6c518-1ubuntu0.1_amd64.deb ...
Unpacking librtmp0:amd64 (2.4+20121230.gitdf6c518-1ubuntu0.1) ...
Selecting previously unselected package libcurl3:amd64.
Preparing to unpack .../libcurl3_7.35.0-1ubuntu2.20_amd64.deb ...
Unpacking libcurl3:amd64 (7.35.0-1ubuntu2.20) ...
Selecting previously unselected package openssl.
Preparing to unpack .../openssl_1.0.1f-1ubuntu2.27_amd64.deb ...
Unpacking openssl (1.0.1f-1ubuntu2.27) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../ca-certificates_20170717~14.04.2_all.deb ...
Unpacking ca-certificates (20170717~14.04.2) ...
Selecting previously unselected package krb5-locales.
Preparing to unpack .../krb5-locales_1.12+dfsg-2ubuntu5.4_all.deb ...
Unpacking krb5-locales (1.12+dfsg-2ubuntu5.4) ...
Selecting previously unselected package libsasl2-modules:amd64.
Preparing to unpack .../libsasl2-modules_2.1.25.dfsg1-17build1_amd64.deb ...
Unpacking libsasl2-modules:amd64 (2.1.25.dfsg1-17build1) ...
Selecting previously unselected package curl.
Preparing to unpack .../curl_7.35.0-1ubuntu2.20_amd64.deb ...
Unpacking curl (7.35.0-1ubuntu2.20) ...
Setting up libroken18-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libasn1-8-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libkrb5support0:amd64 (1.12+dfsg-2ubuntu5.4) ...
Setting up libk5crypto3:amd64 (1.12+dfsg-2ubuntu5.4) ...
Setting up libkeyutils1:amd64 (1.5.6-1) ...
Setting up libkrb5-3:amd64 (1.12+dfsg-2ubuntu5.4) ...
Setting up libgssapi-krb5-2:amd64 (1.12+dfsg-2ubuntu5.4) ...
Setting up libhcrypto4-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libheimbase1-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libwind0-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libhx509-5-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libkrb5-26-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libheimntlm0-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libgssapi3-heimdal:amd64 (1.6~git20131207+dfsg-1ubuntu1.2) ...
Setting up libidn11:amd64 (1.28-1ubuntu2.2) ...
Setting up libsasl2-modules-db:amd64 (2.1.25.dfsg1-17build1) ...
Setting up libsasl2-2:amd64 (2.1.25.dfsg1-17build1) ...
Setting up libldap-2.4-2:amd64 (2.4.31-1+nmu2ubuntu8.5) ...
Setting up librtmp0:amd64 (2.4+20121230.gitdf6c518-1ubuntu0.1) ...
Setting up libcurl3:amd64 (7.35.0-1ubuntu2.20) ...
Setting up openssl (1.0.1f-1ubuntu2.27) ...
Setting up ca-certificates (20170717~14.04.2) ...
Setting up krb5-locales (1.12+dfsg-2ubuntu5.4) ...
Setting up libsasl2-modules:amd64 (2.1.25.dfsg1-17build1) ...
Setting up curl (7.35.0-1ubuntu2.20) ...
Processing triggers for libc-bin (2.19-0ubuntu6.15) ...
Processing triggers for ca-certificates (20170717~14.04.2) ...
Updating certificates in /etc/ssl/certs... 148 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
root@edc7c3a45581:/# curl --version
curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP
root@edc7c3a45581:/#

Docker Networks

Docker Networks:
docker network ls
docker network inspect
docker network create --driver
docker network connect
docker network disconnect

Note: 
(bridge) Defalt Docker virtual network is NATed with Host IP. 
(host) It gains performance by skipping virtual networks and directly connectes the container to the Host interface, but sacrifies security of container model.
(none) Kind of equivalent of having an interface on your computer that's not attached to anything, but we can create our own.

PS C:\Users\MOHI\code> docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
2a59253871ff        nginx               "nginx -g 'daemon of…"   2 hours ago         Up 2 hours          0.0.0.0:80->80/tcp                  nginx_web
8c8313534019        mysql               "docker-entrypoint.s…"   2 hours ago         Up 2 hours          0.0.0.0:3306->3306/tcp, 33060/tcp   mysql_db

// Checking the configured port for the container
PS C:\Users\MOHI\code> docker container port nginx_web
80/tcp -> 0.0.0.0:80

// Checking the IP address of the container:
PS C:\Users\MOHI\code> docker container inspect --format '{{ .NetworkSettings.IPAddress }}' nginx_web
172.17.0.3

PS C:\Users\MOHI\code> docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
981b5c0569a0        bridge              bridge              local
a77057e70878        host                host                local
cdcd8436ab53        none                null                local

PS C:\Users\MOHI> docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "981b5c0569a0035a7c05d3e7094060c9f631a195389fd8eee81e8bb3da4898a1",
        "Created": "2019-11-03T17:53:31.7228006Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466": {
                "Name": "nginx_web",
                "EndpointID": "21663238eb94c4af42e1bea175eed205b433ffab39b6067be6861a433fc629b1",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            },
            "8c83135340196a58031c7cca0012c83938b72d31851a10d920863e82e588caf2": {
                "Name": "mysql_db",
                "EndpointID": "e4fd935517985d081fe9c5bd7af39bfeb5ed712009286e8d8b5e8d1967f8f2a8",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]


// Creating a new Docker network:
PS C:\Users\MOHI> docker network create my_app_net
60095a7d865da0b55404ed123c8b0ed44cc99fb1c9af6b91ce40bf82d393f418

PS C:\Users\MOHI> docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
981b5c0569a0        bridge              bridge              local
a77057e70878        host                host                local
60095a7d865d        my_app_net          bridge              local
cdcd8436ab53        none                null                local

Note: The new Docker network (my_app_net) is using the "bridge" driver

PS C:\Users\MOHI> docker network create --help

Usage:  docker network create [OPTIONS] NETWORK

Create a network

Options:
      --attachable           Enable manual container attachment
      --aux-address map      Auxiliary IPv4 or IPv6 addresses used by
                             Network driver (default map[])
      --config-from string   The network from which copying the configuration
      --config-only          Create a configuration only network
  -d, --driver string        Driver to manage the Network (default "bridge")
      --gateway strings      IPv4 or IPv6 Gateway for the master subnet
      --ingress              Create swarm routing-mesh network
      --internal             Restrict external access to the network
      --ip-range strings     Allocate container ip from a sub-range
      --ipam-driver string   IP Address Management Driver (default "default")
      --ipam-opt map         Set IPAM driver specific options (default map[])
      --ipv6                 Enable IPv6 networking
      --label list           Set metadata on a network
  -o, --opt map              Set driver specific options (default map[])
      --scope string         Control the network's scope
      --subnet strings       Subnet in CIDR format that represents a
                             network segment

PS C:\Users\MOHI> docker network inspect my_app_net
[
    {
        "Name": "my_app_net",
        "Id": "60095a7d865da0b55404ed123c8b0ed44cc99fb1c9af6b91ce40bf82d393f418",
        "Created": "2019-11-07T15:38:45.9824155Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]


// Creating a new container with virtual network option:
PS C:\Users\MOHI> docker container run -d --name new_nginx --network my_app_net nginx
872f240ce4928764c69bee37a69677c4e06fc12e0110f0c68c1d7cda705b6b11

PS C:\Users\MOHI> docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
872f240ce492        nginx               "nginx -g 'daemon of…"   40 seconds ago      Up 37 seconds       80/tcp                              new_nginx
2a59253871ff        nginx               "nginx -g 'daemon of…"   4 hours ago         Up 4 hours          0.0.0.0:80->80/tcp                  nginx_web
8c8313534019        mysql               "docker-entrypoint.s…"   4 hours ago         Up 4 hours          0.0.0.0:3306->3306/tcp, 33060/tcp   mysql_db

PS C:\Users\MOHI> docker network inspect my_app_net
[
    {
        "Name": "my_app_net",
        "Id": "60095a7d865da0b55404ed123c8b0ed44cc99fb1c9af6b91ce40bf82d393f418",
        "Created": "2019-11-07T15:38:45.9824155Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "872f240ce4928764c69bee37a69677c4e06fc12e0110f0c68c1d7cda705b6b11": {
                "Name": "new_nginx",
                "EndpointID": "8b78c2ff891147b1772e5d3b6d2e2de4cb14b831a75c32a018d9bb6d123a21b5",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]


PS C:\Users\MOHI> docker network --help

Usage:  docker network COMMAND

Manage networks

Commands:
  connect     Connect a container to a network
  create      Create a network
  disconnect  Disconnect a container from a network
  inspect     Display detailed information on one or more networks
  ls          List networks
  prune       Remove all unused networks
  rm          Remove one or more networks

Run 'docker network COMMAND --help' for more information on a command.

//Docker network connect:
Note: Dynamically creates a NIC in the container on an existing virtual network.

PS C:\Users\MOHI> docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
981b5c0569a0        bridge              bridge              local
a77057e70878        host                host                local
60095a7d865d        my_app_net          bridge              local
cdcd8436ab53        none                null                local

docker network connect {newly created nw id} {container id)
docker network connect 60095a7d865d 2a59253871ff

PS C:\Users\MOHI> docker container inspect nginx_web
[
    {
        "Id": "2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466",
        "Created": "2019-11-07T12:11:17.0763598Z",
        "Path": "nginx",
        "Args": [
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 4415,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2019-11-07T12:11:21.8310527Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:540a289bab6cb1bf880086a9b803cf0c4cefe38cbb5cdefa199b69614525199f",
        "ResolvConfPath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/hostname",
        "HostsPath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/hosts",
        "LogPath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466-json.log",
        "Name": "/nginx_web",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                50,
                120
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c-init/diff:/var/lib/docker/overlay2/08b90638737e516cb36bc344eed1af3b3031e37b47364996b51d8c3014380d9a/diff:/var/lib/docker/overlay2/64cfd2d2aebaa6155623792ba07ab098a755c9be60783bc93acd429352a01991/diff:/var/lib/docker/overlay2/6d7637e12181a5a3d9dd5250a2d6e04dec26d0e361bf118d6d494557d22095d3/diff",
                "MergedDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c/merged",
                "UpperDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c/diff",
                "WorkDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "2a59253871ff",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.17.5",
                "NJS_VERSION=0.3.6",
                "PKG_RELEASE=1~buster"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "nginx",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGTERM"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "7ec0248663c9475baca243426089563c22a0b1039e778e69df0d667c38cdfc66",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/7ec0248663c9",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "21663238eb94c4af42e1bea175eed205b433ffab39b6067be6861a433fc629b1",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "981b5c0569a0035a7c05d3e7094060c9f631a195389fd8eee81e8bb3da4898a1",
                    "EndpointID": "21663238eb94c4af42e1bea175eed205b433ffab39b6067be6861a433fc629b1",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                },
                "my_app_net": {
                    "IPAMConfig": {},
                    "Links": null,
                    "Aliases": [
                        "2a59253871ff"
                    ],
                    "NetworkID": "60095a7d865da0b55404ed123c8b0ed44cc99fb1c9af6b91ce40bf82d393f418",
                    "EndpointID": "8ee15c7ef28cb4fb0265bcf8d844290bca04ec414008d2999b08a3ec2ef9eb10",
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:03",
                    "DriverOpts": {}
                }
            }
        }
    }
]

Note: Now we can see that this nginx_web container has two different networks (bridge and my_app_net) and different IPs (172.17.0.3 and 172.18.0.3).


Docker network disconnect:
Dynamically remove a NIC from a container on a specific virtual network:

PS C:\Users\MOHI> docker network disconnect 60095a7d865d 2a59253871ff
PS C:\Users\MOHI> docker container inspect nginx_web
[
    {
        "Id": "2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466",
        "Created": "2019-11-07T12:11:17.0763598Z",
        "Path": "nginx",
        "Args": [
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 4415,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2019-11-07T12:11:21.8310527Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:540a289bab6cb1bf880086a9b803cf0c4cefe38cbb5cdefa199b69614525199f",
        "ResolvConfPath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/hostname",
        "HostsPath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/hosts",
        "LogPath": "/var/lib/docker/containers/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466/2a59253871ffed45115fc5d6778c7d5d24971dc3020c9f0a8bee551200b93466-json.log",
        "Name": "/nginx_web",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                50,
                120
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c-init/diff:/var/lib/docker/overlay2/08b90638737e516cb36bc344eed1af3b3031e37b47364996b51d8c3014380d9a/diff:/var/lib/docker/overlay2/64cfd2d2aebaa6155623792ba07ab098a755c9be60783bc93acd429352a01991/diff:/var/lib/docker/overlay2/6d7637e12181a5a3d9dd5250a2d6e04dec26d0e361bf118d6d494557d22095d3/diff",
                "MergedDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c/merged",
                "UpperDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c/diff",
                "WorkDir": "/var/lib/docker/overlay2/21a32567dcfff9817453d9efdb9dd3b7fc8c0eba1cd62560ef975e08a85e3a9c/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "2a59253871ff",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.17.5",
                "NJS_VERSION=0.3.6",
                "PKG_RELEASE=1~buster"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "nginx",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGTERM"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "7ec0248663c9475baca243426089563c22a0b1039e778e69df0d667c38cdfc66",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/7ec0248663c9",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "21663238eb94c4af42e1bea175eed205b433ffab39b6067be6861a433fc629b1",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "981b5c0569a0035a7c05d3e7094060c9f631a195389fd8eee81e8bb3da4898a1",
                    "EndpointID": "21663238eb94c4af42e1bea175eed205b433ffab39b6067be6861a433fc629b1",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]

Note: Now we can see that 172.18.0.3 (my_app_net) has been removed for nginx_web

Docker networks DNS:
Note: 
Docker daemon has a built-in DNS server that containers use by default.
Containers shouldn't rely on IP's for inter-communication.

PS C:\Users\MOHI> docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
872f240ce492        nginx               "nginx -g 'daemon of…"   36 minutes ago      Up 36 minutes       80/tcp                              new_nginx
2a59253871ff        nginx               "nginx -g 'daemon of…"   4 hours ago         Up 4 hours          0.0.0.0:80->80/tcp                  nginx_web
8c8313534019        mysql               "docker-entrypoint.s…"   4 hours ago         Up 4 hours          0.0.0.0:3306->3306/tcp, 33060/tcp   mysql_db

PS C:\Users\MOHI> docker network inspect my_app_net
[
    {
        "Name": "my_app_net",
        "Id": "60095a7d865da0b55404ed123c8b0ed44cc99fb1c9af6b91ce40bf82d393f418",
        "Created": "2019-11-07T15:38:45.9824155Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "872f240ce4928764c69bee37a69677c4e06fc12e0110f0c68c1d7cda705b6b11": {
                "Name": "new_nginx",
                "EndpointID": "8b78c2ff891147b1772e5d3b6d2e2de4cb14b831a75c32a018d9bb6d123a21b5",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

Note: DNS default names, Docker defaults the hostname to the container's name, but you can also set aliases 

// Creating new container "my_nginx_new" (We are using alpine linux based nginx here since we need a "ping" command to work:

PS C:\Users\MOHI> docker container run -d --name my_nginx_alpine --network my_app_net nginx:alpine
Unable to find image 'nginx:alpine' locally
alpine: Pulling from library/nginx
89d9c30c1d48: Already exists
110ad692b782: Pull complete
Digest: sha256:085e84650dbe56f27ca3ed00063a12d5b486e40c3d16d83c4e6c2aad1e4045ab
Status: Downloaded newer image for nginx:alpine
64f0dba4ea987ae614310cef046f2d1032ef86d089a4f9d66a777b77b09cd00b

PS C:\Users\MOHI> docker network inspect my_app_net
[
    {
        "Name": "my_app_net",
        "Id": "60095a7d865da0b55404ed123c8b0ed44cc99fb1c9af6b91ce40bf82d393f418",
        "Created": "2019-11-07T15:38:45.9824155Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "3cac4f533443bea5f1919acf3b0297e00b947d679bc2429f5ef596be61725245": {
                "Name": "my_nginx",
                "EndpointID": "eb8b0dacc10542cf1bc305df8cfb1eddf7964ce48f5f4f3a23db01e3d247b26b",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            },
            "64f0dba4ea987ae614310cef046f2d1032ef86d089a4f9d66a777b77b09cd00b": {
                "Name": "my_nginx_alpine",
                "EndpointID": "302b5679b9431bb4ed0faed713c1cc766be4e446b0520d552bf4e9e08f8c9747",
                "MacAddress": "02:42:ac:12:00:04",
                "IPv4Address": "172.18.0.4/16",
                "IPv6Address": ""
            },
            "872f240ce4928764c69bee37a69677c4e06fc12e0110f0c68c1d7cda705b6b11": {
                "Name": "new_nginx",
                "EndpointID": "8b78c2ff891147b1772e5d3b6d2e2de4cb14b831a75c32a018d9bb6d123a21b5",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]


Note: Now we can see new container (my_nginx_alpine). We can ping a same networks container by using it name.

PS C:\Users\MOHI> docker container exec -it my_nginx_alpine ping new_nginx
PING new_nginx (172.18.0.2): 56 data bytes
64 bytes from 172.18.0.2: seq=0 ttl=64 time=0.103 ms
64 bytes from 172.18.0.2: seq=1 ttl=64 time=0.188 ms
64 bytes from 172.18.0.2: seq=2 ttl=64 time=0.192 ms
64 bytes from 172.18.0.2: seq=3 ttl=64 time=0.196 ms
64 bytes from 172.18.0.2: seq=4 ttl=64 time=0.190 ms
64 bytes from 172.18.0.2: seq=5 ttl=64 time=0.187 ms
^C
--- new_nginx ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 0.103/0.176/0.196 ms

Now we can see that DNS resolution is works fine.