<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rahul Sil on Medium]]></title>
        <description><![CDATA[Stories by Rahul Sil on Medium]]></description>
        <link>https://medium.com/@rahul-official-150?source=rss-abdce474c6f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BgwSAARy-fQMUtGkU9TltA.jpeg</url>
            <title>Stories by Rahul Sil on Medium</title>
            <link>https://medium.com/@rahul-official-150?source=rss-abdce474c6f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:25:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rahul-official-150/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Configure an Identity Provider in OpenShift]]></title>
            <link>https://rahul-official-150.medium.com/configure-an-identity-provider-in-openshift-668ca1bd0bb?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/668ca1bd0bb</guid>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[red-hat-openshift]]></category>
            <category><![CDATA[openshift]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Sat, 19 Mar 2022 23:10:32 GMT</pubDate>
            <atom:updated>2022-03-20T12:27:38.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6UtU8ocPStN5abR9ZQRlSA.gif" /></figure><p><strong>Container orchestration</strong> is a fundamental enabler of digital transformation initiatives in today’s world. Most of the applications in today’s world are running in containers in the form of microservices.</p><p>However, as monolithic applications transition to containerized services, it can be tedious to manage these applications with legacy infrastructure. <strong>Red Hat OpenShift Container Platform ( RHOCP )</strong> helps developers and IT organizations to better manage application life cycles.</p><p><strong>Red Hat OpenShift</strong> is based on the <strong>Kubernetes</strong> open-source project and extends the platform with features that bring a robust, flexible, and scalable container platform to customer data centers, enabling developers to run workloads in a high availability environment.</p><p><strong>Red Hat OpenShift</strong> is a leading enterprise Kubernetes platform that enables a <strong>cloud-like experience</strong> everywhere it’s deployed. Whether it’s in the cloud, on-premise, or at the edge, Red Hat OpenShift gives you the ability to choose where you build, deploy, and run applications through a consistent experience. Red Hat OpenShift’s full-stack automated operations and self-service provisioning for developers let teams work together more efficiently to move ideas from development to production.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FxEofcsd6HGg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DxEofcsd6HGg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FxEofcsd6HGg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e8f305ebc10fe93e074d0a257318d68/href">https://medium.com/media/0e8f305ebc10fe93e074d0a257318d68/href</a></iframe><p>Red Hat OpenShift provides many services and features for the easy management of an application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1eMa3JLukQJBaXJL-_ub5Q.png" /><figcaption>OpenShift Services and Features.</figcaption></figure><p>Now let us come to the topic of the <strong>Authentication of users</strong> in OpenShift. 🧑‍💻</p><p>When we set up the cluster for the first time using the installer program then a <strong>Kubeadmin user</strong> is automatically created by OpenShift to administer the OpenShift cluster.</p><p>Now as a good practice we need to delete the Kubeadmin user and create our own user with the cluster-admin power to administer the OpenShift cluster. For this purpose, we use an<strong> Identity Provider</strong> to create users who can access the cluster resources.</p><p>To control access to an OpenShift Container Platform cluster, a <strong>cluster administrator</strong> can configure <strong>user authentication</strong> and ensure only approved users can access the cluster.</p><h4>Describing OpenShift Users and Groups 🧑‍💻</h4><p>🔹<strong>User — </strong>In the OpenShift Container Platform architecture, users are entities that interact with the API server.</p><p>🔹<strong>Identity</strong> — The identity resource keeps a record of successful authentication attempts from a specific user and identity provider. Any data concerning the source of the authentication is stored on the identity. Only a single user resource is associated with an identity resource.</p><p>🔹<strong>Group</strong> — Groups represent a specific set of users. Users are assigned to one or multiple groups. Groups are leveraged when implementing authorization policies to assign permissions to multiple users at the same time. For example, if you want to allow 10 users access to certain resources of a project, then it is advantageous to grant access to the group of 10 users rather than granting access individually.</p><p>OpenShift Container Platform also provides <strong>system groups</strong> or <strong>virtual groups</strong> that are provisioned automatically by the cluster.</p><p>Now let us get on with the task of Configuring the Identity Provider of OpenShift for user authentication. 🧑‍💻</p><h4>About identity providers in OpenShift Container Platform</h4><p>By default, only the <strong>kubeadmin</strong> virtual user exists in your cluster. To create other users and to specify an identity provider, we must create a <strong>Custom Resource ( CR )</strong> that describes that identity provider and add it to the cluster.</p><p>Let us first understand something about the identity provider configuration —</p><p>The OpenShift Container Platform master includes a built-in OAuth server. Developers and administrators of OpenShift obtain the <strong>OAuth access tokens</strong> to authenticate themselves to the API server.</p><p>As an administrator of the cluster, we can configure the OAuth to specify an identity Provider after we install the cluster. This is what we are trying to achieve here in this blog by creating the HTPasswd identity provider.</p><p><strong>Configuring the HTPasswd Identity Provider —</strong></p><p>The HTPasswd Identity Provider validates users against a secret that contains the credentials of the users. The credentials — username and password are generated with the <strong>htpasswd </strong>command from the <strong>Apache HTTP Server Project</strong>.</p><blockquote>📌 Only a <strong>cluster administrator</strong> can change the data inside the HTPasswd secret. Regular users cannot change their own password.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MBne6XmolONLipXE.png" /><figcaption>Source: Google images.</figcaption></figure><p>To define an HTPasswd Identity Provider you must perform the following steps —</p><ol><li>Create a file containing the credentials of the users using the <strong>htpasswd</strong> command.</li><li>Create a secret from the file created in the previous step.</li><li>Define the HTPasswd Identity Provider <strong>custom resource (CR)</strong>.</li><li>Apply the custom resource to the default OAuth configuration.</li></ol><h4><strong>Managing users with the HTPasswd Identity Provider —</strong></h4><p>Managing user credentials with the HTPasswd Identity Provider requires creating a temporary file, making changes to this file, and applying these changes to a secret.</p><p><strong>📌 Step 1 — Creating the file containing user credentials.</strong></p><p>To create the file using the <strong>htpasswd</strong> command we need to first install the package providing the command.</p><ul><li>On Red Hat Enterprise Linux, the <strong>htpasswd</strong> command comes from the <strong>httpd-tools</strong> package.</li></ul><pre><strong>sudo yum install httpd-tools -y</strong></pre><p>Now, let’s add some user credentials in a file using the <strong>htpasswd</strong> command.</p><pre><strong>htpasswd -cBb  /path/to/file  &lt;username&gt;   &lt;password&gt;</strong></pre><p>The options used in the above command —</p><ul><li><strong>&quot; -c &quot;</strong> — To create a new file for storing the user credentials. This option is used only when there is no pre-existing file for the user credentials.</li><li><strong>&quot; -b &quot; — </strong>To take the password for the user from the command line rather than prompting for it.</li><li><strong>&quot; -B &quot; — </strong>Force <strong>bcrypt encryption</strong> of the password. It’s very secure. Other types of encryption of the password are also available which can be used. By default <strong>MD5 encryption</strong> is used if no other options are mentioned.</li></ul><p>Example usage —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jIvj2cqHwhX86G23nTsQJw.png" /><figcaption>Creating the user credentials.</figcaption></figure><blockquote>❗For the remaining users also follow the same process, only removing <strong>&quot;-c&quot; </strong>option from next time as then it will overwrite the pre-existing file. ❗</blockquote><p>If you want to <strong>delete the credentials</strong> of a user then use —</p><pre><strong>htpasswd  -D  /path/to/file  &lt;username&gt;</strong> </pre><p>Now it’s time to log in to our <strong>Red Hat OpenShift Cluster</strong> and configure our identity provider by performing the remaining steps. 🧑‍💻</p><pre><strong>oc login -u kubeadmin -p ${KUBEADMIN_PASSWORD}  &lt;Cluster API URL&gt;</strong></pre><p>📌 <strong>Step 2 — Creating the HTPasswd Secret.</strong></p><p>To use the HTPasswd Identity Provider we have to create a secret that contains the user credentials from the flat file created in the previous step.</p><p>This is done so that OpenShift knows from where to validate the user credentials when one tries to authenticate themselves while logging into the OpenShift cluster.</p><ul><li>We need to create the secret in the <strong>openshift-config</strong> namespace as OpenShift reads all the internal configuration-related information from this namespace resources<strong>.</strong></li></ul><pre><strong>oc create secret generic  &lt;secret name&gt;  \<br>--from-file  htpasswd=/path/to/file  -n openshift-config</strong></pre><p>NOTE: The secret key containing the user&#39;s file for the <strong>&quot; --from-file &quot; </strong>option must be named <strong>htpasswd</strong> as shown in the above command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*En54OIEJ3d3fR8AF_Xq3OQ.png" /><figcaption>Secret created for storing user credentials.</figcaption></figure><p>📌 <strong>Step 3 — Configuring the OAuth Custom Resource.</strong></p><p>To use the HTPasswd Identity Provider, the OAuth custom resource must be edited and then replaced with the existing one.</p><p>Sample identity provider CR —</p><pre><strong>apiVersion: config.openshift.io/v1<br>kind: OAuth<br>metadata:<br>   name: cluster<br>spec:<br>   identityProviders:<br>   - name: </strong><em>&lt;identity name&gt;</em><strong><br>     mappingMethod: claim<br>     type: HTPasswd<br>     htpasswd:<br>        fileData:<br>           name: </strong><em>&lt;secret name&gt;</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*di0GXOqx-kqsL6cudUT4Tg.png" /><figcaption>OAuth Custom Resource.</figcaption></figure><p>1 — The provider name is prefixed to provider user names to form the identity name.</p><p>2 — An existing secret in the <strong>openshift-config</strong> namespace containing the file having the user credentials generated using <strong>htpasswd</strong>.</p><p>The <strong>mappingMethod</strong> defines how identities are mapped to users when they log in. There are many possible values for this parameter — <strong>claim</strong>, <strong>lookup</strong>, <strong>generate</strong>, <strong>add</strong>.</p><p>Now we have to apply the custom resource YAML file to bring the changes into effect.</p><pre><strong>oc apply -f oauth.yaml</strong></pre><p>When we apply the custom resource, it will trigger new pods in the <strong>openshift-authentication </strong>namespace. The pods in this namespace will redeploy themselves to bring the new changes into effect. After the new pods are running, then we can log in with the new user credentials that we have updated using htpasswd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hv9KMNbsR5BL6d0FvcvRvQ.png" /><figcaption>The initial state of pods in the <strong>openshift-authentication</strong> namespace.</figcaption></figure><p>Now we are going to apply our custom resource ( CR ) file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tbly886rlQvQJ6XpUPiv7g.png" /><figcaption>After applying the oauth.yaml file.</figcaption></figure><p>As we can see the pods in the <strong>openshift-authentication</strong> namespace that were present previously got terminated and new pods were deployed.</p><p>Now we can successfully log in with the new user in the OpenShift cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFlPB3wcgCL6Mb8yPpHPVg.png" /><figcaption>Successful login of the new user.</figcaption></figure><p>After you have logged in, OpenShift will create the identity entry which we can check using the following commands —</p><pre><strong>$ oc get users<br>$ oc get identity</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVoJz1Hzl_h614GsN8DitQ.png" /><figcaption>User and identity created after login.</figcaption></figure><blockquote>For checking this you need to switch to the kubeadmin user or any user with <strong>cluster-admin</strong> power.</blockquote><h4>Updating users for an HTPasswd Identity Provider —</h4><p>Now if you want to add or remove users from an existing HTPasswd Identity Provider, then you need to follow the following steps —</p><ol><li>Extract the existing secret that has the user credentials.</li><li>Update that file with the new user details or delete the user credential that you want to remove.</li></ol><p><strong>Extracting Secret Data —</strong></p><p>When adding or removing a user, the cluster administrator cannot assume the validity of a local htpasswd file. Moreover, the administrator may not be on a system that has the htpasswd file. So in the real-world scenario, the best practice is to extract the secret and update that.</p><pre><strong>oc extract secret/&lt;secret name&gt;  -n  openshift-config  \<br>  --to  /path/to/folder   --confirm</strong></pre><p>Here the <strong>--confirm </strong>option replaces the file in the location specified if it already exists there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7QTSHh0kq3rUlQ5R2Zvhtw.png" /><figcaption>Extracting the secret data.</figcaption></figure><p>As we can see in the above image, the secret containing the user credentials is extracted and a file with the key name “htpasswd” is created in the mentioned location.</p><p>Now let’s add another user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DwR1253bG_UlZ3WnuTE_Sg.png" /><figcaption>New user addition.</figcaption></figure><p>After the new user credentials have been generated, we need to update the secret.</p><p><strong>Updating HTPasswd Secret —</strong></p><pre><strong>oc set data secret/&lt;secret name&gt;  \<br> --from-file  /path/to/file   -n openshift-config</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NPMMR1vTMZvqCzVGRPApCw.png" /><figcaption>Updating the secret.</figcaption></figure><p>After updating the secret, the OAuth operator redeploys the pods in the <strong>openshift-authentication</strong> namespace. Monitor the redeployment of the pods using -</p><pre><strong>oc get pods -n openshift-authentication -w</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YpzWVV978dDVbwA-pdzGaQ.png" /><figcaption>New pods are being redeployed.</figcaption></figure><p>This way you can add multiple users.</p><h4>Deleting Users and Identities —</h4><p>When we need to delete a user, it is not sufficient to delete the user from the identity provider. The user and the identity resources must also be deleted otherwise it might lead to a conflict later on.</p><ul><li>We must remove the credentials from the htpasswd secret, remove it from the htpasswd file and then update the secret.</li></ul><p>Extracting the secret, deleting the user credentials from the file, and then updating the secret — all the required commands and procedure have been provided previously in the blog.</p><p>After this, we need to delete the <strong>user and the identity resource</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYWigyI7Q58qX4ehqLO30w.png" /><figcaption>Incorrect login attempt.</figcaption></figure><p>This type of error message you will get when you update the secret by removing the user credentials.</p><p>But the user and the identity resource of the user still exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wJ7drzViWF7Kc6yKmfWmMg.png" /><figcaption>User and identity of deleted user.</figcaption></figure><p>Remove the user and the identity with the following commands —</p><pre><strong>oc delete user  &lt;username&gt;<br>oc delete identity  &lt;identity name&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*36otSw5bVnAwHGNeR6bjPg.png" /><figcaption>Deleting the user and the identity resource.</figcaption></figure><p>As you can see the user and the identity resource of the user are also removed now.</p><p>Managing users using the HTPasswd identity provider might suffice for a proof-of-concept, environment with a small set of users. However, most production environments require a more powerful identity provider that integrates with the organization’s identity management system.</p><p>So, with that, we come to an end to this article. 💖</p><p>Hope you got a simple understanding of how to configure an identity provider in Red Hat OpenShift Container Platform.</p><p>I would definitely like to hear your reviews and feedback which will help me in improving my content in future technical blogs. 🗃️🙏</p><p>You can check my <strong>LinkedIn profile</strong> and connect with me and also follow me on <strong>medium</strong>.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=668ca1bd0bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker inside a Docker Container ]]></title>
            <link>https://rahul-official-150.medium.com/docker-inside-a-docker-container-e7ae144464f0?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7ae144464f0</guid>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[fedora]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[redhat-linux]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Tue, 30 Nov 2021 11:08:08 GMT</pubDate>
            <atom:updated>2021-11-30T11:08:08.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFbkOHAu4ADWlnI_YD5Mgg.gif" /></figure><p><strong>Containerization</strong> is the packaging together of software code with all the necessary libraries and other dependencies so that it can be isolated.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0rdaDpktu6o%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0rdaDpktu6o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0rdaDpktu6o%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3afb9f4a18b63b5923827928de60c083/href">https://medium.com/media/3afb9f4a18b63b5923827928de60c083/href</a></iframe><p>The softwares are isolated using containers so that it can be moved and executed consistently in any environment and on any infrastructure, independent of that environment or infrastructure’s operating system.</p><p>The container acts like a bubble or a computing environment surrounding the application and keeping it independent of its surroundings. <strong>It&#39;s basically a fully functional and portable computing environment.</strong></p><p>The idea of process isolation has been around for years, but when <strong>Docker</strong> introduced <strong>Docker Engine</strong> in 2013, it set a standard for container use with tools that were easy for developers to use, as well as a universal approach for packaging, which then accelerated the adoption of container technology.</p><p>Today developers can choose from a selection of containerization platforms and tools that support the <strong>Open Container Initiative (OCI) </strong>standards pioneered by Docker.</p><h4>Why Containerized Applications? 🤔</h4><p>Software applications typically depend on other libraries, configuration files, or services that are provided by the runtime environment. The traditional runtime environment for a software application is a physical host or a virtual machine, and application dependencies are installed as a part of the host.</p><p><strong>For example</strong>, consider a Python application that requires access to a common shared library that implements the TLS protocol. Traditionally, a system administrator installs the required package that provides the shared library before installing the Python application.</p><p>The major drawback to traditionally deployed software applications is that the application’s dependencies are entangled with the runtime environment. An application may break when any updates or patches are applied to the base operating system (OS).</p><p><strong>For example</strong>, an OS update to the TLS shared library removes TLS 1.0 as a supported protocol. This breaks the deployed Python application because it is written to use the TLS 1.0 protocol for network requests. This forces the system administrator to roll back the OS update to keep the application running, preventing other applications from using the benefits of the updated package.</p><p>Therefore, a company developing traditional software applications may require a full set of tests to guarantee that an OS update does not affect applications running on the host.</p><p>For overcoming these dependency issues and to make the software application portable we are isolating that inside a container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*qho0H_1p7aMtypTYMySegA.png" /><figcaption>Container versus Operating System differences.</figcaption></figure><h4>What is Docker?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*TaQJ8wLy48VUJVvRDWIPKg.gif" /><figcaption>Docker logo.</figcaption></figure><p>Docker is an open-source platform for building, deploying, and managing containerized applications.</p><p>The Docker technology uses the <strong>Linux Kernel</strong> and features of the kernel, like cgroups and namespaces, to segregate processes so that they run independently. This independence is the intention of containers - the ability to run multiple processes and apps separately from one another to make better use of your infrastructure while retaining the security you would have with separate systems.</p><p>Now as we have got to know so far that Docker is a containerization tool that helps to launch containers. So what’s the need to again launch the Docker Engine inside a docker container? 🤔</p><p>✏️ The use-cases where this comes in handy are —</p><p>🔹When we have launched a Jenkins server inside a container and for Jenkins to launch different nodes for running the CI/CD pipeline, there we will need the Jenkins from inside the container to launch other containers. Here, a Docker Engine inside a docker container comes in handy.</p><p>🔹For experimental purposes on your local development workstation.</p><p>🔹Sandboxed environments.</p><blockquote><strong>Before proceeding further, first, let’s get Docker installed in your system.</strong></blockquote><p><a href="https://docs.docker.com/engine/install/"></a></p><p>Go to the above link and install docker as per your Linux distribution.</p><p>For this article, I will be using <strong>Fedora 35</strong> 💻 as my base system for installing Docker Engine and going ahead with the rest of the practical.</p><p>📌 We will be using the <strong>Docker Community Edition</strong>.</p><p>✏️ For setting up Docker Engine in Fedora run the following commands -</p><pre><strong>$ sudo dnf -y install dnf-plugins-core<br><br>$ sudo dnf config-manager \<br>    --add-repo \<br>    </strong><a href="https://download.docker.com/linux/fedora/docker-ce.repo"><strong>https://download.docker.com/linux/fedora/docker-ce.repo</strong></a></pre><pre><strong>$ sudo dnf install docker-ce -y</strong></pre><p><strong>As now everything is set up, let’s dive deep into the main practical.</strong> 🚀</p><p>There are 3 methods of doing this. Let go through them one by one. 🧑‍💻</p><h4>1. Using the official docker:dind image from Dockerhub</h4><p>This container image has the docker binaries already installed in it. So we just directly use it and we will be having our docker engine running inside the docker container.</p><p>This method creates <strong>child containers</strong> inside a container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PaoGbAg2PcLcbkyInzZpVA.gif" /><figcaption>Child containers getting launched inside a container.</figcaption></figure><p>Steps to achieve this -</p><ul><li>Pull the <strong>docker:dind </strong>image from Docker Hub.</li></ul><pre><strong>$ sudo docker pull docker:dind</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BsGobLMtnDtnVDhp4cU03g.gif" /><figcaption>Pulling the docker:dind image from Docker hub.</figcaption></figure><p>Now let me show how this works by running a docker container and then running another container from that container, i.e, launching a child container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPQWqgJypyM9ivctvxegew.gif" /><figcaption>Docker inside Docker using docker:dind method.</figcaption></figure><p>Command that I have used to launch the docker container —</p><pre><strong>$ sudo docker run -d --privileged --name dockerindocker docker:dind</strong></pre><blockquote>📌<strong> Note: </strong>This requires your container to be run in <strong>privileged mode</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKo6JH1vrMt5nyBiHuLvxg.png" /><figcaption>Root docker container.</figcaption></figure><p>Here, by Root container, I mean the <strong>parent container</strong> from which the child containers will get launched.</p><p>ID of the parent container —<strong> 6fd2f677c02d</strong></p><p>From inside that container, we are pulling the centos image and then launching a container from inside it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KKUWDDTpXF9Mp5BSYKexlQ.png" /><figcaption>Child container.</figcaption></figure><p>The ID of the child container — <strong>dfb2cfc11494</strong></p><p>Now, if you return to your docker host system and run the “sudo docker ps” command, then you will see that only one container is running and that too is the parent container. The child container is running inside the parent container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g6fm_AtHwV6g8aTVBRQ8vA.png" /></figure><blockquote><strong>This proves that the inner container does not get launched as another container in the Docker host itself.</strong></blockquote><p>So, this was one of the ways of using Docker inside Docker.</p><h4>2. Using the /var/run/docker.sock file</h4><p>👉 What is /var/run/docker.sock ?</p><p>🔸/var/run/docker.sock is the default <strong>Unix socket</strong>.</p><p>🔸Sockets are meant for communication between processes on the same host. Docker daemon by default listens to docker.sock. If you are on the same host where the Docker daemon is running, you can use the /var/run/docker.sock to manage containers.</p><p>In this method, we will be using the <strong>docker:latest</strong> image to get the docker engine binaries in the image and mount the /var/run/docker.sock file of the docker host system with the /var/run/docker.sock file of the container.</p><pre><strong>$ sudo docker run -it \<br>       -v   /var/run/docker.sock:/var/run/docker.sock \<br>       docker:latest</strong></pre><blockquote>🚨 <strong>Note</strong>: If your container gets access to docker.sock, it means it has more privileges over your docker daemon. So when used in real projects, understand the security risks, and use it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*INOH9Y608i8oSGAlIbZpbQ.gif" /><figcaption>Docker in Docker using the docker.sock file.</figcaption></figure><p>As we can see by running the above command a container gets launched by the name of <strong>“practical_archimedes”. </strong>Now as we enter the container and run the <strong>“docker ps” </strong>command, we can see that it lists the same container.</p><p>It is because the docker command inside the container is contacting the <strong>same docker daemon in the docker host system</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0WHmT42RrsIk7ftlgjrpA.gif" /><figcaption>Sibling containers.</figcaption></figure><p>When we are launching a container from inside the container, then the new container that gets launched basically gets launched as a sibling of the previous container in the Docker host system.</p><p>This can be confirmed by the output of the <strong>“docker ps”</strong> command inside the container and outside the container in the docker host.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXG9Dd8ppvTlfthWtIhO_Q.png" /><figcaption>docker ps output from inside the container.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C9r050QgFOFDuz4CMH1f2w.png" /><figcaption>docker ps output from the docker host.</figcaption></figure><p>As we can see both are the same, so we can conclude that the two containers that we have launched are the <strong>sibling containers</strong>.</p><p>In this method, we are basically manipulating the docker daemon from inside a container because of the access to docker.sock file and not actually starting a nested container from inside the container.</p><h4>3. Using a base centos image</h4><p>This method is similar to the first method, just that here we are using a base centos image and setting the things by ourselves and seeing what troubles we may encounter and improve our troubleshooting skills.</p><p><strong>Step 1</strong>: Start a docker container from centos image.</p><pre><strong>$ sudo docker run -it --name dockerindocker centos:latest</strong></pre><p><strong>Step 2</strong>: After the container has been launched, set up the yum repository inside the container and then install docker-ce.</p><pre><strong># yum install -y yum-utils<br><br># yum-config-manager \<br>    --add-repo \<br>    </strong><a href="https://download.docker.com/linux/centos/docker-ce.repo"><strong>https://download.docker.com/linux/centos/docker-ce.repo</strong></a></pre><pre><strong># yum install docker-ce -y</strong></pre><p>It will take some time and the docker community edition software will get installed in the container.</p><p><strong>Step 3</strong>: Now to start the docker engine we use the following command -</p><pre><strong>dockerd &amp;</strong></pre><p>Now as we run this command a lot of logs will come and at the end, some error will come and the docker process start will fail.</p><p>The error will be something like — <strong>“….. Permission denied (you must be root)” </strong>at the end.</p><p>To overcome this error we have to use the <strong>“- -privileged”</strong> flag while running the container.</p><p>👉 As we have to again launch a container and then install docker again, to overcome this we can commit the container that we have just created and create an image from it.</p><pre><strong>$ sudo docker stop dockerindocker</strong></pre><pre><strong>$ sudo docker commit dockerindocker dockerindocker:v1</strong></pre><p><strong>Step 4</strong>: Now let’s start the container using the “privileged” tag.</p><pre><strong>$ sudo docker run -it --privileged dockerindocker:v1</strong></pre><p>After running the above command, a container gets launched in privileged mode. Now run the following command to test whether docker-engine starts or not.</p><pre><strong>dockerd &amp;</strong></pre><p>If at the end of this commands output you get something like — “<strong>API listen on /var/run/docker.sock</strong>”, then it means that docker services have started successfully.</p><p><strong>Note</strong>: Even after this you get an error which states something like “/var/lib/docker …..” then you have to use the following command -</p><pre><strong>$ sudo docker run -it --privileged \<br>       -v /var/lib/docker \<br>       dockerindocker:v1</strong></pre><p>This issue I did not face in Fedora 35 but faced in RHEL 8.4 system.</p><p>After this, things are the same as in Method 1. <strong>You can launch a container inside the container which will be the child container.</strong></p><p>So, with that, we come to an end to this article. 💖</p><p><strong>Researching on this topic has been an excellent learning journey.</strong> 💖💖</p><p>👉 If you want to know more about the good, bad and the ugly about docker in docker you can check out this below article. This helped me a lot to understand the things in a simple manner.</p><p><a href="https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/">Using Docker-in-Docker for your CI or testing environment? Think twice.</a></p><p>I hope you liked the article and got to know some interesting things that we can achieve using Docker.</p><p>I would definitely like to hear your reviews and feedbacks which will help me in improving my content in future technical blogs. 🗃️🙏</p><p><strong>Follow me on medium</strong> as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation, and their integration.</p><p>You can also check my <strong>LinkedIn profile</strong> and connect with me.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7ae144464f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating unique Dialog Boxes using Zenity ]]></title>
            <link>https://rahul-official-150.medium.com/creating-unique-dialog-boxes-using-zenity-8b1e53eea0a0?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b1e53eea0a0</guid>
            <category><![CDATA[zenity]]></category>
            <category><![CDATA[arthbylw]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[shellscripting]]></category>
            <category><![CDATA[gtk]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 17:09:56 GMT</pubDate>
            <atom:updated>2021-09-26T17:09:56.961Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cuz7IyYj_KlI6bXru5la8A.gif" /><figcaption>Made using Canva</figcaption></figure><p><strong>Zenity</strong> is an open-source and cross-platform application that displays <strong>GTK+ Dialog Boxes</strong> in command-line and using shell scripts. It allows to ask and present information to/from the shell in Graphical Boxes. The application lets you create Graphical dialog boxes in the command line and makes the interaction between user and shell very easy.</p><p>With zenity, we can create GUI dialog boxes with simplicity and not going into too many complex things. It has few features but is simpler than more complex GUI creation tools.</p><blockquote><strong>Other scripting languages such as Perl and Python can be used to construct full-scale GUI applications, but the zenity program enables a shell script to interact with a GUI user…. [The] user interface is not as refined as one that could be provided by a full-featured GUI application, but it is perfectly suitable for simple interactions.</strong></blockquote><blockquote><strong>— Chris Tyler</strong></blockquote><h3>Installation of Zenity 🚀</h3><p>Zenity is mostly comes installed in Linux-based operating systems. You can check that using the below command —</p><pre><strong>zenity --version</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*x45clfS6D9WZpm_s5d_usg.png" /></figure><p>It will tell the version of zenity that is installed on your system. As you can see I have the zenity version <strong>3.28.1</strong> installed on my system.</p><p>If in case it is not installed, then you can run the following command to install it -</p><pre><strong>sudo apt-get install zenity -y		[on Debian based systems]<br><br>yum install zenity -y		        [on RedHat based systems]</strong></pre><p>Moreover, you can also build it from the source files, download the latest <strong>Zenity</strong> source package (i.e. <strong>current version 3.8</strong>) using the following link.</p><p><a href="https://ftp.gnome.org/pub/gnome/sources/zenity/">http://ftp.gnome.org/pub/gnome/sources/zenity/</a></p><p>Now let’s create some dialog boxes using Zenity. 🙌🔥</p><p><strong>Note:</strong> I have created an alias to adjust the width and height of the dialog boxes. Also when we display something with zenity a warning message comes, in order to remove that redirected that to <strong>/dev/null.</strong></p><pre><strong>alias zenity=&#39;zenity --width=600 --height=600 2&gt; /dev/null&#39;</strong></pre><p>You can set this alias as per your needs by changing the width and the height of the dialog box.</p><ol><li>Let’s first display the calendar.🗓️📅</li></ol><pre><strong>zenity --calendar</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKgD0WEYiEamDejjoHFAAQ.png" /><figcaption>The output of the calendar option.</figcaption></figure><p>When we choose the date and click on “OK” then the chosen date is returned to the standard output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*wY98V1tUA7asmTEvJYUx9g.png" /><figcaption>Date output returned to the standard output- terminal.</figcaption></figure><p>We can change the default date format that is returned to the standard output.</p><pre><strong>zenity --calendar --date-format=%d/%m/%y</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*2BQjB9mBLD395b10hnSyzg.png" /><figcaption>Date format changed.</figcaption></figure><p>Now there are some extra options that can be used with the <strong>calendar option</strong> of zenity.</p><pre><strong>zenity --calendar --text=&quot;&lt;your message&gt;&quot; \<br>--day=15 --month=9 --year=2021 \<br>--title=&quot;&lt;your title&gt;&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_p_zPpRlyIzl0qZzkU8-aw.png" /></figure><p><strong>2.</strong> Next we have the <strong>entry option</strong> in zenity with which we can enter some data.</p><p>It also has some options using which we can create something.</p><pre><strong>zenity --entry --text=&quot;Enter your name&quot; --entry-text=&quot;&lt;your text&gt;&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Rvpa33Pdw0ychQTw69hjA.png" /></figure><p>We can also hide the text when we have to enter some sensitive data like a password.</p><pre><strong>zenity --entry --text=&quot;Enter the password&quot;  --hide-text</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJZafHVK2F41zGESd-Zmsw.png" /></figure><blockquote>Whatever we write in the input box is returned as an output to the standard terminal.</blockquote><p><strong>3.</strong> We can also use zenity to show some error pop-ups. ❌</p><pre><strong>zenity --error --text=&quot;Not Authorized&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ojn5dqo8-hZfm0rsAP_Tng.png" /></figure><p><strong>4.</strong> We select files also using the zenity command. 🗃️</p><pre><strong>zenity --file-selection</strong></pre><p>It opens the file explorer from where we can select a file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CE9VyAMWf1FMfwQhf4_0CA.png" /></figure><p>For selecting multiple files we use the following command -</p><pre><strong>zenity --file-selection --multiple</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XW0tyP-pXRTNedzE0NPgTw.png" /></figure><p>Now if you are using zenity in a shell script and want to overwrite a file, but before that ask yes/no if the file exists, then we use the following command —</p><pre><strong>zenity --file-selection --confirm-overwrite --save</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dg9y-CwzCLVheTSVt56tPw.png" /></figure><p>If we do not use the “- -<strong>confirm-overwrite</strong>”<strong> </strong>then without asking the file will be overwritten.</p><p>Then we have an option for selecting directory only.</p><pre><strong>zenity --file-selection --directory</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cP8XTLOCOVwCVpCh1mgYg.png" /></figure><p>These were some of the combinations of file selection of zenity. Other options you can definitely explore from the man page of the command.</p><pre><strong>man zenity</strong></pre><p><strong>5.</strong> With the help of zenity we can also display an information pop-up window.</p><pre><strong>zenity --info --title=&quot;Information Box&quot; --text=&quot;&lt;your message&gt;&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hj1u2jQo4KDGDv23paU7iw.png" /></figure><p><strong>6.</strong> We can also create a checklist with the zenity dialog box.</p><pre><strong>zenity --list --title=&quot;&lt;your title&gt;&quot; --checklist --editable \<br>--column=&quot;&lt;column 1 name&gt;&quot; --column=&quot;&lt;column 2 name&gt;&quot; \<br>--text= &quot;&lt;column 1 data&gt;&quot; &quot;&lt;column 2 data&gt;&quot; &quot;&lt;column 1 data&gt;&quot;       &quot;&lt;column 2 data&gt;&quot; </strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dXRgkxxuo2cSpNfVRJouWQ.png" /></figure><p>There are other options also which can be used and can be used as per the use case.</p><p><strong>7.</strong> For notification 🔔purposes also we can use the zenity command.</p><pre><strong>zenity --notification --window-icon=&lt;path to picture&gt;               --text=&quot;&lt;text in the notification bar&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1JjzbWpRdPp7BIEs-gjRSA.png" /></figure><blockquote><strong>Note:</strong> This “- -window-icon” option, for now, works only with the notification option of zenity.</blockquote><p><strong>8.</strong> We can display a <strong>progress bar</strong> with zenity when we are downloading any software.</p><pre><strong>zenity --progress --text=&quot;&lt;your text&gt;&quot; --percentage=&lt;INT&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JuKnTsFuL1m6sDDOFtLA_w.png" /></figure><p>We can have a pulsating progress bar also.</p><pre><strong>zenity --progress --text=&quot;&lt;your text&gt;&quot; --percentage=&lt;INT&gt; --pulsate</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPt2gtGGKv465rRaWDHf-w.png" /></figure><p><strong>9.</strong> We can have question dialogs as well 🙋‍♂️</p><pre><strong>zenity --question --text=&quot;&lt;your question&gt;&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wp4UcaiT28jvYwpIH--grQ.png" /></figure><p><strong>10.</strong> We can read the data of the file 📁 using the zenity dialog boxes.</p><pre><strong>zenity --text-info --filename=&lt;filename&gt;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lPS7T34g7rEjQhF0PkEAWw.png" /></figure><p>The file can also be edited.</p><pre><strong>zenity --text-info --filename=&lt;filename&gt; --editable</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vaAt3HOOarxsUvjjjmFA2A.png" /></figure><p>When we use this option the contents of the file are sent to the standard output.</p><p><strong>11.</strong> Warning ⚠️ dialog box using zenity</p><pre><strong>zenity --warning</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJHEROEKShz-gUQmccAaKw.png" /></figure><p><strong>12.</strong> We have a scale dialog box in zenity using which we can select a value from a range of values.</p><pre><strong>zenity --scale</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHJpQk9u5-U0XamJHmA2UA.png" /></figure><p>When we normally use the command like this then we have the range from 0 to 100. We have options to change the minimum value, maximum value and also set an initial value.</p><pre><strong>zenity --scale --value=25</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*NGBFFXDQn62H1cRlrcX9_w.png" /><figcaption>An initial value set in zenity scale.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*6cG4BsM1X-D-2yn6a6mWmg.png" /><figcaption>Minimum and maximum values.</figcaption></figure><p>We have an option “<strong>- -print-partial</strong> ” using which we can print the values which we choose on the slider on the standard output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*SXw_sTofBLEOjCf_s0lZHQ.png" /><figcaption>The values are printed on the standard output.</figcaption></figure><p><strong>13.</strong> When we have used paint 🎨 in our childhood we have used the color palette to choose the color that we want to fill in our drawing. Using zenity also we can create such a dialog box.</p><pre><strong>zenity --color-selection</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xUgvyYl3bEDqE85oouysig.png" /></figure><p>As we can see the hex code of the color is shown in the dialog box. When we select the color then the RGB value is returned to the standard output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*MceOnt0WKoKXrCp5faDpkg.png" /><figcaption>RGB value returned to the terminal.</figcaption></figure><p>We can also have a color palette of specific solid colors.</p><pre><strong>zenity --color-selection --show-palette</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*QNYHqY3CvD2y0wtT9X5xDA.png" /><figcaption>Color palette.</figcaption></figure><p>Also if we know the hex code of color and want to look at what shade of color that is we can do that also.</p><pre><strong>zenity --color-selection --color=#490707</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FBgAszXiEJG6OG3yUCbwjg.png" /><figcaption>Color palette with the specific color hex code.</figcaption></figure><p><strong>14.</strong> We can create a user sign-in dialog box.</p><pre><strong>zenity --password --username</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o3ZqoeYQXgJ0446lNCVBVA.png" /><figcaption>Sign-in dialog box.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*c5uZxXebcDU2c-wP4p0L6A.gif" /></figure><blockquote><strong>Caution:</strong> When you click “OK” the username and password are displayed as plain text on the standard output.</blockquote><p><strong>15.</strong> We can create a Google form kind of thing using zenity as well.</p><pre><strong>zenity --forms --text=&quot;Registration Form&quot; --title=&quot;ARTH&quot; \<br>--add-entry=&quot;Name&quot; --add-entry=&quot;Email ID&quot; \<br>--add-entry=&quot;WhatsApp Number&quot;</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DtFGWGCz1rk4A7Gqtuvk2w.png" /><figcaption>Form created using zenity.</figcaption></figure><p>Here also, after we have entered the data, they are returned and printed on the standard output.</p><p>So these were some of the options that can be used with the zenity command and can help us a lot to make our shell scripting code a bit more user-friendly.🙌</p><p>I hope you liked this article. ️💖</p><p>I would definitely like to hear your reviews and feedbacks which will help me in improving my content in future technical blogs. 🗃️🙏</p><p>Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation, and their integration.</p><p>You can also check my <strong>LinkedIn profile</strong> and connect with me.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b1e53eea0a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fun Image Processing using Python ]]></title>
            <link>https://rahul-official-150.medium.com/fun-image-processing-using-python-e6c17f381655?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6c17f381655</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Wed, 09 Jun 2021 18:18:22 GMT</pubDate>
            <atom:updated>2021-06-09T18:18:22.068Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0QQM3DX5ZfS1MWkIqcBaA.png" /><figcaption>Source: Google</figcaption></figure><p>Most of us are familiar with image processing, not in formal terms of image processing but we all edit our pictures and post them on social media. 💖</p><p>Here I am going to show some interesting ways of doing image processing that we normally do every day using OpenCV and python.</p><h4>What I am going to demonstrate specifically?</h4><ol><li>Creating a custom image using OpenCV 😍✨</li><li>Cropping pictures and pasting them ( We do that every day, don’t we while making memes 😂😂 )</li><li>Making a collage of 2 pictures</li></ol><p>So let&#39;s get going ✌💥</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8a1bc4c4f9c3bde595b855a3485e233/href">https://medium.com/media/e8a1bc4c4f9c3bde595b855a3485e233/href</a></iframe><p>Using the above code we can create a smiley face 😊</p><p>I have basically used the drawing functions that are available from the OpenCV library in the cv2 module and created the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UNiBbbgDvjPHYQNjdXPfhg.png" /><figcaption>Image Output</figcaption></figure><p>Keep smiling 😊 in your tough times and things will definitely come back to normal and you will achieve all the success in the world 😊✌🙏</p><p>🚩 You can get creative and create your own custom image like this. 😉😉</p><p>Now I will show you how to crop a face from an image and paste it somewhere ( the thing we mostly do while meme-making 😂😂 )</p><p>The Original Image I am going to use is -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*T4BDdDL9Xb_s8yBOZmwwRw.jpeg" /><figcaption>Source: Google</figcaption></figure><p>Our very favorite Tom and Jerry.😍</p><p><strong>Who all got reminded of their childhood memories? 💖🤩</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d50c82ca32115659eb697a434b428ebd/href">https://medium.com/media/d50c82ca32115659eb697a434b428ebd/href</a></iframe><p>Now using the above code we can crop Tom and Jerry’s faces and swap them also.</p><p>Results -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*gTMju65fyI6cebuD8Yzz8w.png" /><figcaption>Tom’s cropped image</figcaption></figure><p>Here the face of Tom is cropped and swapped with Jerry’s face.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*S-LTfi7cNizJu8E-ENtX0A.png" /><figcaption>Jerry’s cropped image</figcaption></figure><p>Here the face of Jerry is cropped and swapped with Tom’s face.</p><p><strong>❗ In the above code, only one face swap code will work at a time, that is if you run the code for pasting Tom’s face on top of Jerry’s face then the other won’t work, and vice-versa. You need to then run the codes separately. I have given the codes together here. ❗</strong></p><p>Now I will be creating a collage of Tom and Jerry ( after all they were the best of buddies 💖 )</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4125ffbaedfd21a0f00ece5e72536a9c/href">https://medium.com/media/4125ffbaedfd21a0f00ece5e72536a9c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZAlG5ByJXcImBs6Fsv98sA.png" /><figcaption>Collage made using OpenCV</figcaption></figure><p>This way I have performed few fun experiments with OpenCV and NumPy. 💖</p><p>You can find all the codes and images that I used here from the below <strong>GitHub link </strong>—</p><p><a href="https://github.com/iamrahulsil/opencv-numpy-image.git">iamrahulsil/opencv-numpy-image</a></p><p>A lot more things can be done using OpenCV and NumPy but for now this much.✌</p><p>I hope you liked this article.💖</p><p>Would definitely like to hear your views on this and feedbacks so that I can improve on those points in future articles. 🙌 Comment your views below.</p><p><strong>You can also check my LinkedIn profile and connect with me.</strong></p><p>Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation, and their integration.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6c17f381655" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning in Cyber Security ]]></title>
            <link>https://rahul-official-150.medium.com/machine-learning-in-cyber-security-871b26ec6cb7?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/871b26ec6cb7</guid>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Sun, 06 Jun 2021 18:00:48 GMT</pubDate>
            <atom:updated>2021-06-06T18:00:48.708Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1TtCEwtfcqpDUNA7apBbQ.jpeg" /><figcaption>Source: Google</figcaption></figure><p><strong>Machine learning</strong> has become a vital technology for cybersecurity. Machine learning preemptively stamps out cyber threats and bolsters security infrastructure through pattern detection, real-time cybercrime mapping, and thorough penetration testing.</p><p>Emerging technologies put cybersecurity at risk. Even the new advancements in defensive strategies of security professionals fail at some point. Besides, as offensive-defensive strategies and innovations are running in a never-ending cycle, the complexity and volume of cyberattacks have increased. Combining the strength of artificial intelligence (AI) with cybersecurity, security professionals have additional resources to defend vulnerable networks and data from cyber attackers. After applying this technology, it brought instant insights, resulting in reduced response times. Capgemini recently released a report based on AI in cybersecurity, which mentions that 42% of the companies studied had seen a rise in security incidents through time-sensitive applications. It also revealed that <a href="https://www.capgemini.com/wp-content/uploads/2019/07/AI-in-Cybersecurity_Report_20190711_V06.pdf">two out of three organizations are planning to adopt AI solutions by 2020</a>.</p><h3>Challenges and Promises of Artificial Intelligence in Cybersecurity</h3><p>While cybersecurity experts have accepted AI as the future of the industry, finding solutions to its problems is still not adequately addressed. Apart from being a solution, it is a considerable threat to businesses.</p><p>AI can efficiently analyze user behaviors, deduce a pattern, and identify all sorts of abnormalities or irregularities in the network. With such data, it’s much easier to identify cyber vulnerabilities quickly. In spite of being a security risk to businesses, AI will continue to minimize routine security responsibilities with high-quality results. AI automation will be able to identify recurring incidents and even remediate them. It will also be able to manage insider threats and device management.</p><h3>AI Adopters Inspiring to Make a Shift</h3><p>AI has already been adopted to strengthen the security infrastructure of organizations. There are numerous real-life examples where AI-powered solutions are significantly improving cybersecurity.</p><ul><li><a href="https://www.theverge.com/2019/2/6/18213453/gmail-tensorflow-machine-learning-spam-100-million">Gmail uses machine learning to block 100 million spams in a day</a>. It has developed a system to filter out emails and offer a spam-free environment efficiently.</li><li>IBM’s Watson cognitive training uses machine learning to detect cyber threats and other cybersecurity solutions.</li><li><a href="https://www.forbes.com/sites/bernardmarr/2017/08/08/the-amazing-ways-how-google-uses-deep-learning-ai/#77c6ea9b3204">Google is using Deep Learning AI on its Cloud Video Intelligence platform</a>. On this platform, the videos stored on the server are analyzed based on their content and context. The AI algorithms send security alerts whenever something suspicious is found.</li><li>Balbix platform uses AI-powered risk predictions to protect the IT infrastructure against data and security breaches.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wCdvqvEwTnxu_F1F.jpeg" /></figure><h3>Understanding Confusion Matrix</h3><p>When we get the data, after data cleaning, pre-processing and wrangling, the first step we do is to feed it to an outstanding model and of course, get output in probabilities. But how can we measure the effectiveness of our model? Better the effectiveness, better the performance and that’s what we want. And it is where the Confusion matrix comes into the limelight. Confusion Matrix is a performance measurement for machine learning classification.</p><p>There are multiple ways of finding errors in the machine learning model. The Mean Absolute Error (Error/cost) function helps the model to be trained in the correct direction by trying to make the distance between the Actual and predicted value to be 0. We find the error in machine learning model prediction by “y — y^”.</p><p><strong>Mean Square Error (MSE):</strong> Points from the data set are taken and they are squared first and then the mean is taken to overcome the error.</p><p>In Binary Classification models, the error is detected with the help of a confusion matrix.</p><p>Confusion Matrix is a performance measurement for machine learning classification problems where output can be two or more classes. It is a table with 4 different combinations of predicted and actual values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/0*fzy5GKzHscdizNXD.png" /></figure><p>It is extremely useful for measuring Recall, Precision, Specificity, Accuracy, and most importantly AUC-ROC curves.</p><p><strong>Understanding Confusion Matrix in a simpler manner:</strong></p><p>Let’s start with an <strong>example confusion matrix for a binary classifier</strong> (though it can easily be extended to the case of more than two classes):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/0*XN_4-l4v1zdJqxfe.png" /></figure><p><strong>What can we learn from this matrix?</strong></p><p>● There are two possible predicted classes: “yes” and “no”. If we were predicting the presence of a disease, for example, “yes” would mean they have the disease, and “no” would mean they don’t have the disease.</p><p>● The classifier made a total of 165 predictions (e.g., 165 patients were being tested for the presence of that disease).</p><p>● Out of those 165 cases, the classifier predicted “yes” 110 times, and “no” 55 times.</p><p>● In reality, 105 patients in the sample have the disease, and 60 patients do not.</p><p><strong>Let’s now define the most basic terms, which are whole numbers (not rates):</strong></p><p>● <strong>true positives (TP):</strong> These are cases in which we predicted yes (they have the disease), and they do have the disease.</p><p>● <strong>true negatives (TN):</strong> We predicted no, and they don’t have the disease.</p><p>● <strong>false positives (FP):</strong> We predicted yes, but they don’t have the disease. (Also known as a “Type I error.”)</p><p>● <strong>false negatives (FN):</strong> We predicted no, but they do have the disease. (Also known as a “Type II error.”)</p><p>I’ve added these terms to the confusion matrix, and also added the row and column totals:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/0*AE002eL9JvKzwrgJ.png" /></figure><p>This is a list of rates that are often computed from a confusion matrix for a binary classifier:</p><p><strong>Accuracy:</strong> Overall, how often is the classifier correct?</p><p>o (TP+TN)/total = (100+50)/165 = 0.91</p><p><strong>Misclassification Rate:</strong> Overall, how often is it wrong?</p><p>o (FP+FN)/total = (10+5)/165 = 0.09</p><p>o equivalent to 1 minus Accuracy</p><p>o also known as “Error Rate”</p><p><strong>True Positive Rate:</strong> When it’s actually yes, how often does it predict yes?</p><p>o TP/actual yes = 100/105 = 0.95</p><p>o also known as “Sensitivity” or “Recall”</p><p><strong>False Positive Rate:</strong> When it’s actually no, how often does it predict yes?</p><p>o FP/actual no = 10/60 = 0.17</p><p><strong>True Negative Rate:</strong> When it’s actually no, how often does it predict no?</p><p>o TN/actual no = 50/60 = 0.83</p><p>o equivalent to 1 minus False Positive Rate</p><p>o also known as “Specificity”</p><p><strong>Precision:</strong> When it predicts yes, how often is it correct?</p><p>o TP/predicted yes = 100/110 = 0.91</p><p><strong>Prevalence:</strong> How often does the yes condition occur in our sample?</p><p>o actual yes/total = 105/165 = 0.64</p><p><strong>A couple of other terms are also worth mentioning:</strong></p><p><strong>Null Error Rate:</strong> This is how often you would be wrong if you always predicted the majority class. (In our example, the null error rate would be 60/165=0.36 because if you always predicted yes, you would only be wrong for the 60 “no” cases.) This can be a useful baseline metric to compare your classifier against. However, the best classifier for a particular application will sometimes have a higher error rate than the null error rate, as demonstrated by the Accuracy Paradox.</p><p><strong>Cohen’s Kappa:</strong> This is essentially a measure of how well the classifier performed as compared to how well it would have performed simply by chance. In other words, a model will have a high Kappa score if there is a big difference between the accuracy and the null error rate. (<a href="http://en.wikipedia.org/wiki/Cohen&#39;s_kappa">More details about Cohen’s Kappa.</a>)</p><p><strong>F Score:</strong> This is a weighted average of the true positive rate (recall) and precision. (<a href="http://en.wikipedia.org/wiki/F1_score">More details about the F Score.</a>)</p><p><strong>ROC Curve:</strong> This is a commonly used graph that summarizes the performance of a classifier over all possible thresholds. It is generated by plotting the True Positive Rate (y-axis) against the False Positive Rate (x-axis) as you vary the threshold for assigning observations to a given class. (<a href="https://www.dataschool.io/roc-curves-and-auc-explained/">More details about ROC Curves.</a>)</p><p><strong>Precision:</strong> The precision metric shows the accuracy of the positive class. It measures how likely the prediction of the positive class is correct.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/0*8N_eOVmS1hfCRaqH.png" /></figure><p>The maximum score is 1 when the classifier perfectly classifies all the positive values. Precision alone is not very helpful because it ignores the negative class. The metric is usually paired with the Recall metric. The recall is also called sensitivity or true positive rate.</p><p>● <strong>Sensitivity</strong>: Sensitivity computes the ratio of positive classes correctly detected. This metric gives how good the model is to recognize a positive class.</p><p><strong>Is it necessary to check for recall (or) precision if you already have a high accuracy?</strong></p><p>We can not rely on a single value of accuracy in classification when the classes are imbalanced. For example, we have a dataset of 100 patients in which 5 have diabetes and 95 are healthy. However, if our model only predicts the majority class i.e. all 100 people are healthy even though we have a classification accuracy of 95%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/178/0*PzpePjxfwPsLvwjC.png" /></figure><p><strong>When to use Accuracy / Precision / Recall / F1-Score?</strong></p><p>● Accuracy is used when the True Positives and True Negatives are more important. Accuracy is a better metric for Balanced Data.</p><p>● Whenever a False Positive is much more important use Precision.</p><p>● Whenever a False Negative is much more important use Recall.</p><p>● F1-Score is used when the False Negatives and False Positives are important. F1-Score is a better metric for Imbalanced Data.</p><p><strong>Why do we need a Confusion matrix?</strong></p><p>Here are the pros/benefits of using a confusion matrix.</p><p>● It shows how any classification model is confused when it makes predictions.</p><p>● The confusion matrix not only gives you insight into the errors being made by your classifier but also the types of errors that are being made.</p><p>● This breakdown helps you to overcome the limitation of using classification accuracy alone.</p><p>● Every column of the confusion matrix represents the instances of that predicted class.</p><p>● Each row of the confusion matrix represents the instances of the actual class.</p><p>● It provides insight not only into the errors which are made by a classifier but also errors that are being made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xdcLouqWXH7yXxMf.png" /></figure><p>Cyberattack detection is a classification problem, in which we classify the normal pattern from the abnormal pattern (attack) of the system.</p><p><strong>Cyber Attack Detection and Classification Using Parallel Support Vector Machine</strong></p><p>Cyber-attack is becoming a critical issue of organizational information systems. Several cyber-attack detection and classification methods have been introduced with different levels of success that are used as a countermeasure to preserve data integrity and system availability from attacks. The classification of attacks against computer networks is becoming a harder problem to solve in the field of network security.</p><p>Soon, AI-powered systems will be an integral part of cybersecurity solutions. It will also be used by cybercriminals to harm organizations. This will leave AI using automated programs susceptible to advanced threats. Like any other cybersecurity solution, AI is not 100% foolproof. It is a double-edged sword with the ability to limit cyber-attacks and automate mundane routine tasks, and yet, it’s a blessing. The automation wave will take over everyday tasks while the same technology will increase the chances of <a href="https://blog.eccouncil.org/the-role-of-human-error-in-cybersecurity/">fewer human errors</a> and <a href="https://blog.eccouncil.org/negligence-the-number-one-cause-leading-to-cyberattacks/">negligence</a>.</p><p>I hope you liked this article.💖</p><p>Would definitely like to hear your views on this and feedbacks so that I can improve on those points in future articles. 🙌 Comment your views below.</p><p>You can also check my LinkedIn profile and connect with me.</p><p>Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation, and their integration.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=871b26ec6cb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GUI Applications in Docker ]]></title>
            <link>https://rahul-official-150.medium.com/gui-applications-in-docker-def05dab4e0c?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/def05dab4e0c</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[gui]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Tue, 01 Jun 2021 12:25:46 GMT</pubDate>
            <atom:updated>2021-06-01T12:25:46.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VJXbh96F8QOHvMQEehwkJw.gif" /><figcaption>Made using Canva</figcaption></figure><p>Most of us know that <strong>Docker is a containerization tool</strong> that helps us in provisioning an OS within seconds.</p><blockquote><strong>Well if you did not know about that, you know it now !! 😉</strong></blockquote><p>It basically creates a process in the base system which is treated as a new operating system.</p><p>In most of the use cases in the industry utilizing the container technology we use the CLI only and Docker gives us the CLI of a container only and not the GUI.</p><p>But it might be sometimes needed that we want to launch a graphical application inside a docker container and that is by default not possible. We need to pass certain variables during the runtime of the container so that the container can launch certain GUI applications.</p><p>🚩 In this blog, I am going to show you how you can enable and launch a GUI application inside a docker container. ✨🤩</p><p>I will be using 𝗥𝗲𝗱𝗛𝗮𝘁 𝗘𝗻𝘁𝗲𝗿𝗽𝗿𝗶𝘀𝗲 𝗟𝗶𝗻𝘂𝘅 ( 𝗥𝗛𝗘𝗟 ) 𝟴 operating system as the Docker host that is the base system.</p><p>📍 You need to have docker configured in the system. You can refer to the below-mentioned blog where I have explained how to configure docker.</p><p><a href="https://rahul-official-150.medium.com/-1e603e594710">⚜ 𝗠𝗮𝗰𝗵𝗶𝗻𝗲 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝘂𝘀𝗶𝗻𝗴 𝗖𝗼𝗻𝘁𝗮𝗶𝗻𝗲𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻…</a></p><p>After you have configured docker in your system, proceed with the following steps. ✌</p><p>I have created a basic Dockerfile that will have the GUI applications software already installed.</p><p><strong>You can find the Dockerfile in the following Github repo.</strong></p><p><a href="https://github.com/iamrahulsil/docker_gui.git">iamrahulsil/docker_gui</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LqAgmgvmL6ZWrqiyuxRlg.png" /><figcaption>Dockerfile</figcaption></figure><p>Create a directory and save this Dockerfile there.</p><pre><strong>mkdir docker_gui/<br>cd docker_gui/</strong></pre><blockquote><strong>❗ The name of the file should be “Dockerfile” only.</strong> ❗</blockquote><p>After you have created the Dockerfile using your favourite text editor, now it&#39;s time to create the docker image.</p><pre><strong>docker build -t docker_gui:v1.0 .</strong></pre><blockquote>Make sure to run this command in the location where the Dockerfile is present.</blockquote><p>I have already created the image and uploaded it to Docker Hub. You can pull that image also.</p><p>Docker Hub Link — <a href="https://hub.docker.com/r/rahulsil/docker_gui">https://hub.docker.com/r/rahulsil/docker_gui</a></p><p>After we have all the above things set up, let us move onto the main part of launching a GUI application inside a Docker container.✨</p><pre><strong>docker run -it --name guios--net=host --env=&quot;DISPLAY&quot; --volume=&quot;$HOME/.Xauthority:/root/.Xauthority:rw&quot; rahulsil/docker_gui:v1.0</strong></pre><p>Run the above command to launch a new container.</p><p>Now the command is quite messy, right? Let us understand it properly:</p><ul><li><strong>run</strong>:- is used to start our container</li><li><strong>-it</strong>:- this keyword provides us with an interactive terminal</li><li><strong>- -name</strong>:- used to set the name of the container</li><li><strong>guios</strong>:- it is the name of the container, anything could be given.</li><li><strong>- -net=host</strong>:- use to launch the container with the host network.</li><li><strong>- -env=”Display”</strong>:- This is used to share the display of the host to the container</li><li><strong>- -volume=”$HOME/.Xauthority:/root/.Xauthority:rw”</strong>:- This is used to share the host X server with the container by creating volume.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KiIToHBUTMRTqjfMNfPSMA.png" /></figure><p>As you can see as we launched the container and executed the firefox command the firefox browser opened and shows the centos home page as the container is created from Centos image.</p><p>This way we have successfully completed the task of launching a GUI application inside a docker container. 😍✨</p><blockquote><strong>I will soon come up with a blog where I will be explaining the basics of docker and the commnds of docker, dockerfile that I have used here. Stay tuned for that !!</strong></blockquote><p>I hope you liked this article.💖</p><p>Would definitely like to hear your views on this and feedbacks so that I can improve on those points in future articles. 🙌 Comment your views below.</p><p>You can also check my LinkedIn profile and connect with me.</p><p>Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation, and their integration.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def05dab4e0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚜    …]]></title>
            <link>https://rahul-official-150.medium.com/-1e603e594710?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e603e594710</guid>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Sun, 30 May 2021 15:20:23 GMT</pubDate>
            <atom:updated>2021-06-16T05:11:49.153Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NUMXsinA40_dU0kFR6oMAQ.gif" /><figcaption>Made using Canva</figcaption></figure><h3>⚜ 𝗠𝗮𝗰𝗵𝗶𝗻𝗲 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝘂𝘀𝗶𝗻𝗴 𝗖𝗼𝗻𝘁𝗮𝗶𝗻𝗲𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝗰𝗵𝗻𝗼𝗹𝗼𝗴𝘆💻 ⚜</h3><p><strong>Technology was not what it was many years ago. It has changed and is evolving continuously. 💻</strong></p><p>In today’s world, we can say that <strong>Machine Learning</strong> is the most trending technology. Almost all the big companies are trying to automate things using <strong>Artificial Intelligence</strong>.</p><p>But the challenge faced by them is that the ML model that is created is somehow not getting deployed to the production world.</p><p><strong>The percentage of AI models created but never put into production in large enterprises has been estimated to be as much as 90% or more</strong>.</p><p>With massive investments in data science teams, platforms, and infrastructure, the number of AI projects is dramatically increasing — along with the number of missed opportunities. Unfortunately, most projects are not showing the value that business leaders expect and are introducing new risks that need to be managed.</p><p><strong>✨ The solution to the above problem statement is MLOps. ✨</strong></p><h4>🔰 But, what exactly is MLOps? 🤔 💻</h4><p>Simply put, MLOps is when DevOps is applied to machine learning. MLOps can be looked upon as the communication between data scientists and the production or operations team of an organization or business. Collaborative in nature, MLOps is designated for eliminating unnecessary functions or waste and automate processes as much as possible that helps in producing consistent and richer business or organizational insights using machine learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Inntmbhi2UbiofL8FDjrA.gif" /><figcaption>Source: Google</figcaption></figure><p>📍 The first thing we need for MLOps is — 𝗖𝗼𝗻𝘁𝗮𝗶𝗻𝗲𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻 𝘁𝗲𝗰𝗵𝗻𝗼𝗹𝗼𝗴𝘆.</p><p><strong>Containerization</strong> is defined as a form of operating system virtualization, through which applications are run in isolated user spaces called containers, all using the same shared operating system (OS).</p><p>For using containerization technology we have many tools like <strong>Docker, Podman</strong>, etc.</p><p>Now let’s get into some hands-on practical implementing the topic. 😍</p><p>Before that certain pre-requisites need to be taken care of. I will be using 𝗥𝗲𝗱𝗛𝗮𝘁 𝗘𝗻𝘁𝗲𝗿𝗽𝗿𝗶𝘀𝗲 𝗟𝗶𝗻𝘂𝘅 ( 𝗥𝗛𝗘𝗟 ) 𝟴 for doing this practical.</p><p>❗ Your yum should be configured in the system. ❗</p><p>Now for installing the Docker community edition into the system create a repo file in the location <strong>/etc/yum.repos.d/ </strong>with the name docker-ce.repo</p><pre><strong>touch /etc/yum.repos.d/docker-ce.repo</strong></pre><blockquote><strong>📍 Note: The name of the repo file can be anything of your choice but the extension should be “.repo” only.</strong></blockquote><p>Now open the repo file with any of your favorite editors and copy the below lines to configure docker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kNLOA-uulaKR0a5Tr6v04A.png" /><figcaption>docker-ce.repo file</figcaption></figure><p>Now your Docker should be configured in your system. ✨</p><p>Run the following command to install docker.</p><pre><strong>yum install docker-ce --nobest -y</strong></pre><p>It will install the docker community edition software along with all the dependencies that it might require.</p><p>Here I will be using a <strong>Dockerfile</strong> to create the container image.The container image will have the machine learning code and the dataset.</p><p>The goal is when we run a container from this image then the ML code will create the model and then start the app for prediction.</p><p>❗ This point will be more clear when we go onto the practicals.</p><p>First create a directory containing all the required files.</p><p>My directory structure looks something as follows -</p><pre><strong>[root@localhost ML]# tree<br>.<br>├── Dockerfile<br>├── Salary_Data.csv<br>├── salaryLR.py<br>└── salary_predictor.py</strong></pre><pre><strong>0 directories, 4 files</strong></pre><ul><li><strong><em>“Salary_Data.csv”</em></strong> is the dataset file.</li><li><strong><em>“salaryLR.py”</em></strong> is the file that contains the Linear Regression code.</li><li><strong><em>“salary_predictor.py”</em></strong> is the app that will be used by the user for predicting the salary.</li></ul><p>You can get the salary dataset from the following link.</p><p><a href="https://www.kaggle.com/rohankayan/years-of-experience-and-salary-dataset">Years of experience and Salary dataset</a></p><p>Now let’s come onto the Dockerfile.</p><pre><strong>FROM centos:latest</strong></pre><pre><strong>MAINTAINER RAHUL SIL &lt;</strong><a href="/service/mailto:rahul.official.150@gmail.com"><strong>rahul.official.150@gmail.com</strong></a><strong>&gt;</strong></pre><pre><strong>RUN dnf install python3 ncurses net-tools -y &amp;&amp; \<br>    pip3 install numpy pandas joblib scikit-learn</strong></pre><pre><strong>WORKDIR /root/ML</strong></pre><pre><strong>COPY * /root/ML/</strong></pre><pre><strong>RUN python3 salaryLR.py<br> <br>CMD [&quot;python3&quot;, &quot;salary_predictor.py&quot; ]</strong></pre><p>Lets build the dockerfile.</p><pre><strong>docker build -t linear_regression:v1.0  .</strong></pre><p>After the dockerfile gets executed you can confirm that a new linear_regression:v1.0 image has been created and stored in the local repository using the following command.</p><pre><strong>docker images</strong></pre><p>Now lets use the image to run and use the ML model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kaej9vV5ko0otqfIiOboCg.png" /><figcaption>docker container output</figcaption></figure><p>This way we have sucessfully implemented the task of running a Machine Learning model inside a docker container. ✨😍</p><blockquote>I will soon come up with a blog where I will be explaining the basics of docker and the commnds of docker, dockerfile that I have used here. Stay tuned for that !!</blockquote><p>You can get all the code for this task from the below link.</p><p><a href="https://github.com/iamrahulsil/ML_in_container.git">iamrahulsil/ML_in_container</a></p><p>I hope you liked this article.💖</p><p>Would definitely like to hear your views on this and feedbacks so that I can improve on those points in future articles. 🙌 Comment your views below.</p><p>You can also check my LinkedIn profile and connect with me.</p><p>Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation and their integration.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e603e594710" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running Python Code in a Docker Container ]]></title>
            <link>https://rahul-official-150.medium.com/running-python-code-in-a-docker-container-f28fe2b45604?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f28fe2b45604</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Mon, 15 Mar 2021 12:21:47 GMT</pubDate>
            <atom:updated>2021-03-15T12:21:47.573Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LE2UPiFApm1Y8D9JOhD1DQ.png" /><figcaption>Designed by Rahul Sil.</figcaption></figure><p>The main purpose of a Operating System is to run a program. Therefore, in order to run a program we need to boot up a system which takes a lot of time.</p><p>In today’s dynamic and fast world we cannot use the older approach of provisioning an OS which takes a long time. Now is the time of Containerization where the OS is provisioned within seconds.</p><p><strong>Docker</strong> is one such containerization technology which helps us in using containers. Other containerization technology includes Podman, CRIO.</p><p>📌 In this blog I am going to show how we can setup a Python interpreter 🐍inside a Docker container 🚢 and run a python code.🤩</p><p>Before starting with it, first we need Docker installed in our system.</p><p>📍 Refer to my below article where I can explained how to install Docker in a RHEL 8 system and run a container.</p><p><a href="https://rahul-official-150.medium.com/configuring-webserver-in-a-docker-container-435e7da6b01a">Configuring Webserver in a Docker Container 🚢</a></p><p>Now I believe you have Docker installed in your system. So lets proceed ahead.</p><p>Run the below command to start a container -</p><pre><strong>docker run -it --rm --name pythonos centos:latest</strong> </pre><p>When you run this command in your host system, a new container provisions and you are landed in that containers terminal.</p><p>Now you are at the containers terminal. Run the following command to install python3 in the container.</p><pre><strong>yum install python3 -y</strong></pre><p>This will successfully install python version 3 in the container. You can confirm that by running the python REPL.</p><p>Now let’s create a simple python program which will print the IP address of the container and run that program in the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1XBfhDheMqxCFwoAid32OA.png" /><figcaption>container screenshot.</figcaption></figure><p><strong>This way we successfully installed the Python 🐍 interpreter and executed a python code 📝 inside the docker container. 🚢</strong></p><p>I hope you liked this article.💖</p><p>Would definitely like to hear your views on this and feedbacks so that I can improve on those points in future articles. 🙌 Comment your views below.</p><p>You can also check my LinkedIn profile and connect with me.</p><p>Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation and their integration.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f28fe2b45604" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Webserver in a Docker Container ]]></title>
            <link>https://rahul-official-150.medium.com/configuring-webserver-in-a-docker-container-435e7da6b01a?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/435e7da6b01a</guid>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[web-server]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Mon, 15 Mar 2021 11:43:58 GMT</pubDate>
            <atom:updated>2021-03-15T11:43:58.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yqrqGusAi6fGnJ6tW1QTyw.png" /><figcaption>Designed By Rahul Sil.</figcaption></figure><p>Today is the world of <strong>containerization</strong> where all the applications are being deployed in containers.</p><p>Containers help us in the microservices world were every part of an application is deployed inside containers. <strong>Docker</strong> is one such containerization technology which helps us with containers. The best part of using containerization technologies like Docker, Podman, CRIO is that the containers/OS are launched and provisioned is a few seconds.</p><p>This speed in provisioning of OS helps us in the field where the servers are terminated often frequently and needs to be provisioned fast enough so that the users do not face any delay in the services.</p><p>📌 In this blog I am going to discuss about a setup where a <strong>webserver is running inside a docker container</strong>. 🤩</p><p>I am going to use <strong>RedHat Enterprise Linux 8</strong> for doing this practical.</p><p><strong>First lets install docker in our system</strong>. For that we need to configure our yum repository so that yum command can install the docker software.</p><p>Go to the location <strong>/etc/yum.repos.d/</strong> and create a file with the name <strong>docker.repo</strong></p><blockquote>You can give any name to the file but the extension of the file should be <strong>.repo</strong></blockquote><p>Now in the docker.repo file copy the below statements.</p><pre><strong>[docker-ce]<br>name=DOCKER REPO<br>baseurl=</strong><a href="https://download.docker.com/linux/centos/7/x86_64/stable/"><strong>https://download.docker.com/linux/centos/7/x86_64/stable/</strong></a><strong><br>gpgcheck=0</strong></pre><p>The baseurl given above contains the docker software and all other dependent softwares that docker requires. yum will go to this url and download all the required packages.</p><p><strong>gpgcheck=0</strong> so that no signature check is done.</p><p>Normally in RedHat Enterprise Linux we need to install the <strong>Docker Enterprise Edition</strong>, but using this method we can install <strong>Docker Community Edition </strong>which is free.</p><p>After you have created the repo file, then run the below command to install docker.</p><pre><strong>yum install docker-ce --nobest</strong></pre><p>The option “<strong>- -nobest</strong>” is used so that no broken packages are installed and all the dependent packages are in working state.</p><p>After the installation is done then start the docker services in your system.</p><pre><strong>systemctl enable docker --now</strong></pre><p>This command will start the docker services and also make it permanent so that after restart of the system the docker services are still running and we do not have to manually start the docker services every time.</p><h4>Docker 🚢 is now successfully installed and permanently started.</h4><p>After this, if you run the command “<strong>docker images</strong>” you will see no container images is present. We will install images now but this tells us that docker is running successfully.</p><p>I am going to use <strong>centos:latest </strong>image for this practical. You can use any other image as well. You can check all the available container images in docker hub.</p><p><a href="https://hub.docker.com/">Docker Hub Container Image Library | App Containerization</a></p><p>To pull the centos image run the following command -</p><pre><strong>docker pull centos:latest</strong></pre><blockquote>🎯 You can use any other version of centos as well.</blockquote><p>After the image download is done you can confirm the same using the following command -</p><pre><strong>docker images</strong></pre><p>Now let’s start a container …..</p><pre><strong>docker run -dit --rm --privileged=true --name webserver centos:latest &quot;/usr/sbin/init&quot;</strong></pre><p><strong>docker run</strong> command is basically used to run a container.</p><p>“<strong>-dit</strong>” — To run the container in detached(d) mode and have an interactive(i) terminal(t).</p><p>“<strong>- -rm</strong>” — To remove the container as soon as it is stopped.</p><p>“<strong>- -name</strong>” — To give a name of your choice to the container.</p><p>Now inside the docker containers “<strong>systemctl</strong>” commands does not work as it is not booted up using systemD. So in order to make the systemctl command available inside the container we use the “<strong>- -priviledged=true</strong>” option and pass the “<strong>/usr/sbin/init</strong>” path also.</p><p>After running the above command you will see that a container ID is displayed as the output. This also means that the container is launched and provisioned within a second.</p><pre><strong>docker ps</strong></pre><p>Using the above command you can see that the container is in the running state.</p><pre><strong>docker exec -it webserver bash</strong></pre><p>After you have run the above command you will land up in the containers terminal.</p><p>Now you can start configuring the HTTPD webserver inside the container.</p><p>From now run the commands in the container terminal.</p><pre><strong>yum install net-tools ncurses httpd php -y</strong></pre><p>This will install the httpd software, php software. net-tools and ncurses packages for getting the ifconfig and clear commands inside the container, normally they are not there as container images are created having minimum commands available.</p><pre><strong>systemctl enable httpd --now</strong></pre><p>This will start and enable the httpd webserver which can be confirmed using the netstat command.</p><pre><strong>[root@ec49910bd2ac /]# systemctl enable httpd --now</strong></pre><pre><strong>Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.</strong></pre><pre><strong>[root@ec49910bd2ac /]# netstat -tnlp</strong></pre><pre><strong>Active Internet connections (only servers)<br>Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    <br>tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      258/httpd           </strong></pre><p>As we can see that the webserver is running inside the container at port 80.</p><p>Let’s write a PHP page which prints the IP address of the server where it is running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*ZZTUd8_fgjBWtoAoB5FUkg.png" /><figcaption>PHP Code.</figcaption></figure><p>Create a <strong>index.php</strong> page in the <strong>/var/www/html/</strong> location.</p><p>After this get the IP address of the container using ifconfig.</p><p>In my case the container IP = <strong>172.17.0.2</strong></p><p>Now go to the docker host system and open the browser. Write the container IP in the URL box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQgQFW36iu4oma4orfVziw.png" /></figure><p>As you can see that the webpage displays the container IP, <strong>this confirms that our webserver was successfully configured inside a Docker container</strong>.🤩</p><p>I hope you liked this article.💖</p><p>Would definitely like to hear your views on this and feedbacks so that I can improve on those points in future articles. 🙌 Comment your views below.</p><p>You can also check my LinkedIn profile and connect with me.</p><p>Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation and their integration.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><p><strong>That’s all for now. Thank You !!</strong> 😊✌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=435e7da6b01a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[⚜ Network Setup of blocking one site from the Routing Table ⚜]]></title>
            <link>https://rahul-official-150.medium.com/network-setup-of-blocking-one-site-from-the-routing-table-40a963e84b6d?source=rss-abdce474c6f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/40a963e84b6d</guid>
            <category><![CDATA[route]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Rahul Sil]]></dc:creator>
            <pubDate>Mon, 15 Mar 2021 10:01:18 GMT</pubDate>
            <atom:updated>2021-03-15T10:01:18.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1NRfsGSeCKC9KY69QCJ_vA.png" /><figcaption>Designed by Rahul Sil.</figcaption></figure><p>Nowadays, people are very much involved in the social medias like Facebook, Twitter, Instagram, etc. Sometimes in order to restrict usage to social medias for certain time they block those sites using some certain site blocking software.</p><p>📌 Similar setup of blocking certain websites can be achieved in a more core technical form using the<strong> Routing Table </strong>and its modifications.</p><p>👉 In this blog I am going to discuss how you can modify the routing table so that you can connect to one website like Google but not Facebook. I am going to show <strong>two methods</strong> of making changes to the routing table.</p><p>Before going into the practical setup, let us understand few things about <strong>Networking</strong>.</p><p>Networking is a way of exchanging data between multiple nodes over a shared medium like a LAN network or a WAN network ( Internet ). <strong>Our system can generate network packets for those set of IP address that is present in our routing table.</strong></p><p>For connecting to the Internet we require a <strong>Gateway </strong>which takes our network packets to the destination IP address.</p><blockquote><strong>I am going to use RedHat Enterprise Linux 8 system.</strong></blockquote><p>We can check the routing table of our system using the following command -</p><pre><strong>route -n</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GLATsK0WJ7hSQiyp4KCCCg.png" /><figcaption>Routing Table</figcaption></figure><p>Here in the routing table we can see that there is an entry where it says Destination = 0.0.0.0 and gateway is 192.168.0.1</p><p>Basically this 192.168.0.1 is the Gateway IP of my system which allows network packets transfer between my system and the Internet. We can check what is the gateway IP of the system by reading the file <strong>/etc/resolv.conf</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*VvQAFhbzOhL0DOADcKO8Gw.png" /><figcaption>Gateway IP of the system</figcaption></figure><p>The Destination IP = 0.0.0.0 means that my system can connect to any IP in the world.</p><p>🔰 Now lets get on with the practical demo.</p><h4>Method 1 -</h4><p>First lets look at what Google and Facebook server our system is connected to.</p><pre><strong>nslookup &lt;domain name&gt;</strong></pre><p>📍If in your RHEL system <strong>nslookup</strong> command does not work, then you need to install a package for that.</p><pre><strong>yum install bind-utils -y</strong></pre><p>Now lets see what is the google server IP and Facebook server IP that my system is connected to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*RDOPwDU4r1jIle1gs0QNHA.png" /><figcaption>Google IP.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*IMxiJ1JYwEBXr10Q5RMtzw.png" /><figcaption>Facebook IP.</figcaption></figure><p>Now when we have made no alterations to the routing table we can ping both Google and Facebook and also any other domain.</p><pre><strong>[root@localhost ~]# ping google.com -c 3</strong></pre><pre><strong>PING google.com (172.217.167.46) 56(84) bytes of data.<br>64 bytes from del03s16-in-f14.1e100.net (172.217.167.46): icmp_seq=1 ttl=119 time=46.8 ms<br>64 bytes from del03s16-in-f14.1e100.net (172.217.167.46): icmp_seq=2 ttl=119 time=48.8 ms<br>64 bytes from del03s16-in-f14.1e100.net (172.217.167.46): icmp_seq=3 ttl=119 time=46.6 ms</strong></pre><pre><strong>--- google.com ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, time 6ms<br>rtt min/avg/max/mdev = 46.626/47.411/48.774/0.967 ms</strong></pre><pre><strong>[root@localhost ~]# </strong></pre><pre><strong>[root@localhost ~]# ping facebook.com -c 3</strong></pre><pre><strong>PING facebook.com (157.240.16.35) 56(84) bytes of data.<br>64 bytes from edge-star-mini-shv-01-bom1.facebook.com (157.240.16.35): icmp_seq=1 ttl=55 time=39.1 ms<br>64 bytes from edge-star-mini-shv-01-bom1.facebook.com (157.240.16.35): icmp_seq=2 ttl=55 time=37.2 ms<br>64 bytes from edge-star-mini-shv-01-bom1.facebook.com (157.240.16.35): icmp_seq=3 ttl=55 time=34.9 ms</strong></pre><pre><strong>--- facebook.com ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, time 6ms<br>rtt min/avg/max/mdev = 34.884/37.065/39.104/1.732 ms</strong></pre><pre><strong>[root@localhost ~]# </strong></pre><pre><strong>[root@localhost ~]# ping twitter.com -c 3<br>PING twitter.com (104.244.42.65) 56(84) bytes of data.<br>64 bytes from 104.244.42.65 (104.244.42.65): icmp_seq=1 ttl=56 time=74.5 ms<br>64 bytes from 104.244.42.65 (104.244.42.65): icmp_seq=2 ttl=56 time=73.7 ms<br>64 bytes from 104.244.42.65 (104.244.42.65): icmp_seq=3 ttl=56 time=79.9 ms</strong></pre><pre><strong>--- twitter.com ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, time 4ms<br>rtt min/avg/max/mdev = 73.731/76.035/79.903/2.751 ms</strong></pre><pre><strong>[root@localhost ~]#</strong></pre><p>This is possible because we have an entry in the routing table where <strong>Destination network = 0.0.0.0/0</strong> and <strong>Gateway = 192.168.0.1</strong></p><p>Now, let’s delete this route and see what happens…</p><pre><strong>route del -net 0.0.0.0</strong></pre><p>After we run the above command in the terminal our routing table will look like this -</p><pre><strong>[root@localhost ~]# route -n</strong></pre><pre><strong>Kernel IP routing table</strong></pre><pre><strong>Destination     Gateway         Genmask         Flags Metric Ref    Use Iface</strong></pre><pre><strong>172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0</strong></pre><pre><strong>192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 ens160</strong></pre><pre><strong>192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0</strong></pre><pre><strong>[root@localhost ~]#</strong></pre><p>The 0.0.0.0 route gets deleted and due to this we now cannot ping to any website on the internet.</p><pre><strong>[root@localhost ~]# ping google.com -c 3<br>connect: Network is unreachable<br>[root@localhost ~]# <br>[root@localhost ~]# ping facebook.com -c 3<br>connect: Network is unreachable<br>[root@localhost ~]# <br>[root@localhost ~]# ping twitter.com -c 3<br>connect: Network is unreachable<br>[root@localhost ~]#</strong></pre><p>Now in order to make connectivity to only google, we will add the google server IP that we have found out previously using the nslookup command in the routing table and also add the gateway IP in this route.</p><pre><strong>route add -net 172.217.0.0/16 gw 192.168.0.1 dev ens160</strong></pre><p>After we have made the above entry to the routing table, our routing table looks like this -</p><pre><strong>[root@localhost ~]# route -n</strong></pre><pre><strong>Kernel IP routing table</strong></pre><pre><strong>Destination     Gateway         Genmask         Flags Metric Ref    Use Iface</strong></pre><pre><strong>172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0</strong></pre><pre><strong>172.217.0.0     192.168.0.1     255.255.0.0     UG    0      0        0 ens160</strong></pre><pre><strong>192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 ens160</strong></pre><pre><strong>192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0</strong></pre><pre><strong>[root@localhost ~]#</strong></pre><p>And as per this we can now only ping google server and no other server in the world.</p><pre><strong>[root@localhost ~]# ping google.com -c 3</strong></pre><pre><strong>PING google.com (172.217.166.206) 56(84) bytes of data.<br>64 bytes from del03s13-in-f14.1e100.net (172.217.166.206): icmp_seq=1 ttl=119 time=33.4 ms<br>64 bytes from del03s13-in-f14.1e100.net (172.217.166.206): icmp_seq=2 ttl=119 time=35.3 ms<br>64 bytes from del03s13-in-f14.1e100.net (172.217.166.206): icmp_seq=3 ttl=119 time=32.5 ms</strong></pre><pre><strong>--- google.com ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, time 7ms<br>rtt min/avg/max/mdev = 32.519/33.728/35.260/1.151 ms</strong></pre><pre><strong>[root@localhost ~]# </strong></pre><pre><strong>[root@localhost ~]# ping facebook.com<br>connect: Network is unreachable</strong></pre><pre><strong>[root@localhost ~]# </strong></pre><pre><strong>[root@localhost ~]# ping twitter.com<br>connect: Network is unreachable</strong></pre><p>From the browser also we can check that these websites cannot be connected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-qG6_WqYGMbHrGcQsTLhTw.png" /><figcaption>Google is accessible.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-YeAmiM8KMjEvgrFX31Qzg.png" /><figcaption>Facebook is not accessible.</figcaption></figure><p>This way we successfully created the setup where we can ping to Google but not Facebook !! 🙌</p><p>But there is a <strong>drawback</strong> using the above method.</p><p>🎯 <strong>Using the above method, it blocks all other websites except the specific one that is added in the routing table. If the use case is that or to allow only 2–3 websites access then we can go ahead with this.</strong></p><p>But if the use case is to block only one site and allow the rest then we need a different approach. From this use case idea we come to our Method 2.</p><h4>Method 2 —</h4><p>To reverse all the changes made previously and to get a fresh routing table we need to restart our network connection. We can do so from the cli using the below commands -</p><pre><strong>nmcli conn down ens160<br>nmcli conn up ens160</strong></pre><blockquote><strong>🎯 “ens160” is my network card name. Your case it might be different. Check that using the “ifconfig” command.</strong></blockquote><p>Now to only block Facebook we run the following command -</p><pre><strong>route add -net 157.240.0.0/16 reject dev ens160</strong></pre><p>Using the <strong>“reject”</strong> option we can just block the network traffic to the that domain.</p><p><strong>📌 So now we can ping to other domains except Facebook.</strong></p><pre><strong>[root@localhost ~]# ping facebook.com<br>connect: Network is unreachable</strong></pre><pre><strong>[root@localhost ~]# </strong></pre><pre><strong>[root@localhost ~]# ping google.com -c 3<br>PING google.com (172.217.167.46) 56(84) bytes of data.<br>64 bytes from del03s16-in-f14.1e100.net (172.217.167.46): icmp_seq=1 ttl=119 time=47.3 ms<br>64 bytes from del03s16-in-f14.1e100.net (172.217.167.46): icmp_seq=2 ttl=119 time=53.3 ms<br>64 bytes from del03s16-in-f14.1e100.net (172.217.167.46): icmp_seq=3 ttl=119 time=51.2 ms</strong></pre><pre><strong>--- google.com ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, time 6ms<br>rtt min/avg/max/mdev = 47.270/50.589/53.334/2.508 ms</strong></pre><pre><strong>[root@localhost ~]# </strong></pre><pre><strong>[root@localhost ~]# ping twitter.com -c 3<br>PING twitter.com (104.244.42.193) 56(84) bytes of data.<br>64 bytes from 104.244.42.193 (104.244.42.193): icmp_seq=1 ttl=56 time=75.3 ms<br>64 bytes from 104.244.42.193 (104.244.42.193): icmp_seq=2 ttl=56 time=75.3 ms<br>64 bytes from 104.244.42.193 (104.244.42.193): icmp_seq=3 ttl=56 time=77.10 ms</strong></pre><pre><strong>--- twitter.com ping statistics ---<br>3 packets transmitted, 3 received, 0% packet loss, time 123ms<br>rtt min/avg/max/mdev = 75.288/76.194/77.984/1.304 ms</strong></pre><p>This way we successfully managed to create the setup for the other use-case as well where we needed to block only a specific site. 🙌</p><p>📍 If you want to remove the route that you have added using the “reject” option then use the below mentioned command -</p><pre><strong>ip route del unreachable 157.240.0.0/16</strong></pre><blockquote>In a summary -</blockquote><blockquote>✨ Method 1 — Use case when we want to allow traffic only to specific sites and block all other sites. ✨</blockquote><blockquote>✨ Method 2 — Use case when we want to block traffic only to specific sites and allow all other sites. ✨</blockquote><p>Hope you liked this blog. 💖</p><p>I tried to explain it in very simple terms. If any doubt you can contact me over LinkedIn.</p><p><a href="https://www.linkedin.com/in/rahul-sil/">Rahul Sil - ARTH Learner - ARTH - The School of Technologies | LinkedIn</a></p><h4><strong>Thank you for reading the article !!</strong> 💖</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40a963e84b6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>