AMP AMP

How To Create a Local Docker Network on Rocky Linux 8.6

To create a local Docker Network on Rocky Linux 8.6

Introduction:

Docker is an open-source platform for creating, deploying, and managing virtualized application containers. A Docker network connects multiple Docker containers together and permits swarm services to communicate with each other.

Installation Procedure:

Step 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release 
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"

Step 2: Create the Nginx image from the Docker Hub by using the below command

[root@linuxhelp ~]# docker create nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
461246efe0a7: Pull complete 
060bfa6be22e: Pull complete 
b34d5ba6fa9e: Pull complete 
8128ac56c745: Pull complete 
44d36245a8c9: Pull complete 
ebcc2cc821e6: Pull complete 
Digest: sha256:1761fb5661e4d77e107427d8012ad3a5955007d997e0f4a3d41acc9ff20467c7
Status: Downloaded newer image for nginx:latest
64f6ffb2e9ac505796a4a6c884deee8533e6396574b0a1e3296331d693a70143

Step 3: Create a Docker Network named by “local” by using the below command

[root@linuxhelp ~]# docker network create --subnet=10.0.1.1/24 local
200503bcefb4950a9e665f4cdc63cadbeb9f7a77656dd520ac79f22d81ea7c4b

Step 4: Run a container from Nginx image with IP address by using the below command

[root@linuxhelp ~]# docker run --net local --ip 10.0.1.10 -it nginx bash

Step 5: Check the status of the Nginx service by using the below command

root@247b2d4f6c02:/# service nginx status
nginx is not running ... failed!

Step 6: Start the Nginx service by using the below command

root@247b2d4f6c02:/# service nginx start
2022/07/22 10:51:47 [notice] 45#45: using the "epoll" event method
2022/07/22 10:51:47 [notice] 45#45: nginx/1.23.1
2022/07/22 10:51:47 [notice] 45#45: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2022/07/22 10:51:47 [notice] 45#45: OS: Linux 4.18.0-372.9.1.el8.x86_64
2022/07/22 10:51:47 [notice] 45#45: getrlimit(RLIMIT_NOFILE): 1048576:1048576
root@247b2d4f6c02:/# 2022/07/22 10:51:47 [notice] 46#46: start worker processes
2022/07/22 10:51:47 [notice] 46#46: start worker process 47

Step 7: Now update the package by using the below command

root@247b2d4f6c02:/# apt update
Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 Packages [8182 kB]
Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [166 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2592 B]
Fetched 8555 kB in 2s (4242 kB/s)               
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

Step 8: Now install the open-vm-tool by using the below command

root@247b2d4f6c02:/# apt install open-vm-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  distro-info-data ethtool fuse iproute2 libatm1 libbpf0 libcap2 libcap2-bin libdrm-common libdrm2 libelf1
  libfuse2 libglib2.0-0 libglib2.0-data libgpm2 libkmod2 libmnl0 libmpdec3 libmspack0 libncursesw6 libpam-cap
  libpci3 libpython3-stdlib libpython3.9-minimal libpython3.9-stdlib libsqlite3-0 libxmlsec1
  libxmlsec1-openssl libxtables12 lsb-release media-types net-tools pci.ids pciutils python3 python3-minimal
  python3.9 python3.9-minimal shared-mime-info xdg-user-dirs zerofree
Suggested packages:
  iproute2-doc gpm open-vm-tools-desktop cloud-init bzip2 python3-doc python3-tk python3-venv python3.9-venv
  python3.9-doc binutils binfmt-support

Step 9: Now check the ip address of the nginx container by using the below command

root@247b2d4f6c02:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:0a:00:01:0a brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.0.1.10/24 brd 10.0.1.255 scope global eth0
       valid_lft forever preferred_lft forever

Step 10: Ping the IP address in the browser as shown in the below image

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to create local Docker Network on Rocky Linux 8.6 . Your feedback is much welcome.

FAQ
Q
Does Docker have its own network?
A
Yes, Docker automatically creates a subnet and gateway for the bridge network and adds all containers to it automatically.
Q
How to create the Nginx container's latest version?
A
To Create the Nginx container's latest version by "docker create nginx:latest" or "docker create nginx"
Q
How to run a container with an IP address defined?
A
To run a container with an IP address defined by "docker run --net --ip 192.168.6.120 -it nginx bash"
Q
How to create a Docker Network?
A
To Create a Docker Network use the following command "docker network create --subnet=192.168.6.0/23 "
Q
What is Docker Network?
A
Docker networks connect multiple Docker containers together and enable swarm services to communicate with each other