<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Deepak Porwal</title>
    <description>The latest articles on DEV Community by Deepak Porwal (@dporwal).</description>
    <link>https://dev.to/dporwal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F545023%2Ff054915f-6fdb-49ff-b14c-85b695c262b8.jpg</url>
      <title>DEV Community: Deepak Porwal</title>
      <link>https://dev.to/dporwal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dporwal"/>
    <language>en</language>
    <item>
      <title>Bridging vs Bonding in Linux Networking – Explained with Real-Life Analogies</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Mon, 02 Feb 2026 07:16:24 +0000</pubDate>
      <link>https://dev.to/dporwal/bridging-vs-bonding-in-linux-networking-explained-with-real-life-analogies-51ek</link>
      <guid>https://dev.to/dporwal/bridging-vs-bonding-in-linux-networking-explained-with-real-life-analogies-51ek</guid>
      <description>&lt;p&gt;Hey folks! So I've been studying for my LFCS exam lately, and I hit this networking section about bridges and bonds. At first, I was confused - aren't they basically the same thing? Nope. Turns out they're completely different, and once I understood it, it clicked.&lt;/p&gt;

&lt;p&gt;Let me share what helped me finally get it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "Aha!" Moment
&lt;/h2&gt;

&lt;p&gt;You know how sometimes you need a simple analogy to make tech concepts stick? Here's what worked for me:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bridging&lt;/strong&gt; is like connecting two different neighborhoods with a flyover. People from both sides can now meet each other easily.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonding&lt;/strong&gt; is like widening a single road by adding more lanes. Same road, just more capacity.&lt;/p&gt;

&lt;p&gt;See the difference? One connects separate places, the other makes one place handle more traffic.&lt;/p&gt;




&lt;h2&gt;
  
  
  When I Actually Use Bridges
&lt;/h2&gt;

&lt;p&gt;Last month, I was setting up my homelab (yeah, I know, typical DevOps thing). I had this Ubuntu server with one NIC, and I wanted my VMs to be on the same network as my laptop.&lt;/p&gt;

&lt;p&gt;What did I do? Created a bridge.&lt;/p&gt;

&lt;p&gt;Basically, a bridge in Linux is like a virtual switch living inside your server. You plug in your physical NICs and maybe some virtual interfaces (like for VMs), and boom - everything talks to each other like they're all connected to the same switch.&lt;/p&gt;

&lt;p&gt;Here's the deal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each NIC you add to a bridge becomes a "port"&lt;/li&gt;
&lt;li&gt;Devices on different segments suddenly act like they're on the same LAN&lt;/li&gt;
&lt;li&gt;No routing needed, it's all Layer 2 magic&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real scenario from my homelab
&lt;/h3&gt;

&lt;p&gt;I had:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My server's &lt;code&gt;enp0s3&lt;/code&gt; connected to my home router&lt;/li&gt;
&lt;li&gt;A couple of VMs that needed IPs from the same DHCP pool&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Solution? Bridge &lt;code&gt;enp0s3&lt;/code&gt; with the VM tap interfaces. Now my router sees the VMs as if they're physical machines on my network. Pretty neat.&lt;/p&gt;

&lt;p&gt;This is super common in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;KVM/libvirt setups&lt;/li&gt;
&lt;li&gt;Docker networking (container bridges)&lt;/li&gt;
&lt;li&gt;Transparent firewall configurations&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Now Let's Talk Bonding
&lt;/h2&gt;

&lt;p&gt;Bonding is a different beast. You're not connecting networks here - you're combining multiple NICs to act as ONE.&lt;/p&gt;

&lt;p&gt;Think about it like this: you have two 1Gbps cables going to the same switch. Instead of using them separately, you bond them into &lt;code&gt;bond0&lt;/code&gt;, and from your server's perspective, there's just one fat pipe.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why would you do this?
&lt;/h3&gt;

&lt;p&gt;Three solid reasons:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. High Availability&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
If one cable gets unplugged (trust me, it happens), traffic automatically fails over to the other NIC. Your app keeps running. No downtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. More Bandwidth&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Depending on the bonding mode, you can actually push traffic through multiple NICs simultaneously. More lanes = more cars.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Peace of Mind&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
One flaky link? No problem, the bond shifts traffic to the healthier ones.&lt;/p&gt;

&lt;p&gt;I've seen this save production systems multiple times. One time at work, someone accidentally knocked a cable loose in the datacenter. We didn't even notice until the monitoring alert came in - the bond had already failed over.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bonding Modes - This Confused Me At First
&lt;/h2&gt;

&lt;p&gt;Okay, so Linux supports 7 bonding modes (0 through 6), and honestly, you don't need to memorize all of them. But here are the ones I actually use:&lt;/p&gt;

&lt;h3&gt;
  
  
  Mode 1: Active-Backup (My Go-To)
&lt;/h3&gt;

&lt;p&gt;This is the simplest and most common one I've used. One NIC is active, the others are just chilling on standby. If the active one dies, a standby instantly takes over.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When I use it:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Production servers where uptime matters&lt;/li&gt;
&lt;li&gt;When I can't touch the switch config (which is... often)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The catch:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
You're not getting any extra throughput. Only one link is active at a time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mode 4: LACP (The "Proper" Way)
&lt;/h3&gt;

&lt;p&gt;This is 802.3ad - the official standard for link aggregation. Both your server and the switch negotiate and form a team.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When I use it:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When I have access to managed switches (datacenter setups)&lt;/li&gt;
&lt;li&gt;Need both redundancy AND more bandwidth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The catch:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Your switch needs to support LACP, and you need to configure it on both ends.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mode 0: Round Robin (Lab Only)
&lt;/h3&gt;

&lt;p&gt;Sends packets round-robin across all NICs. Great for testing, but can cause packet reordering issues in production.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Others
&lt;/h3&gt;

&lt;p&gt;There's Mode 2 (XOR), Mode 3 (Broadcast - rarely used), Mode 5 (Transmit Load Balancing), and Mode 6 (Adaptive Load Balancing). Honestly, I've barely touched these in real work. Mode 1 and Mode 4 handle 90% of my use cases.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Decision Tree (This Helped Me)
&lt;/h2&gt;

&lt;p&gt;Whenever I'm confused about which to use, I ask myself:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 1:&lt;/strong&gt; Do I have multiple NETWORKS that need to talk?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yes&lt;/strong&gt; → Use a &lt;strong&gt;bridge&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No&lt;/strong&gt; → Keep reading&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Question 2:&lt;/strong&gt; Do I have multiple cables to the SAME network?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yes&lt;/strong&gt; → Use &lt;strong&gt;bonding&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No&lt;/strong&gt; → You probably don't need either&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Question 3 (if bonding):&lt;/strong&gt; Can I configure the switch?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Yes&lt;/strong&gt; → Use &lt;strong&gt;Mode 4 (LACP)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No&lt;/strong&gt; → Use &lt;strong&gt;Mode 1 (Active-Backup)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Seriously, this little mental checklist has saved me so much time.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Quick Comparison Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Thing&lt;/th&gt;
&lt;th&gt;Bridging&lt;/th&gt;
&lt;th&gt;Bonding&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;What it does&lt;/td&gt;
&lt;td&gt;Connects different networks&lt;/td&gt;
&lt;td&gt;Combines NICs on same network&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best analogy&lt;/td&gt;
&lt;td&gt;Flyover connecting neighborhoods&lt;/td&gt;
&lt;td&gt;Adding lanes to a highway&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What apps see&lt;/td&gt;
&lt;td&gt;Multiple networks reachable&lt;/td&gt;
&lt;td&gt;One interface (bond0)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Common use&lt;/td&gt;
&lt;td&gt;VMs, containers&lt;/td&gt;
&lt;td&gt;Production servers, storage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;My usage&lt;/td&gt;
&lt;td&gt;Homelab, dev environments&lt;/td&gt;
&lt;td&gt;Work servers, HA setups&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Real-World Examples From My Experience
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1: My Homelab VMs
&lt;/h3&gt;

&lt;p&gt;I create a bridge &lt;code&gt;br0&lt;/code&gt;, plug in my physical NIC and VM interfaces. My VMs get IPs from my home router's DHCP. Easy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 2: Production App Server
&lt;/h3&gt;

&lt;p&gt;Two NICs, same VLAN, can't modify the switch. I create &lt;code&gt;bond0&lt;/code&gt; in Mode 1. One cable goes bad? Server keeps running. Simple as that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 3: Database Server With Storage
&lt;/h3&gt;

&lt;p&gt;Two 10GbE NICs, heavy storage traffic, and I control the switch. Mode 4 (LACP) all the way. I get aggregated bandwidth and failover.&lt;/p&gt;




&lt;h2&gt;
  
  
  For LFCS Exam Folks
&lt;/h2&gt;

&lt;p&gt;If you're studying for the LFCS like me, remember these key points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Bridge&lt;/strong&gt; = virtual switch connecting interfaces; makes separate networks behave as one&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bond&lt;/strong&gt; = multiple NICs presented as one logical interface&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mode 1&lt;/strong&gt; = Active-backup, simple HA, no switch config needed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mode 4&lt;/strong&gt; = LACP, needs switch support, gives you both HA and bandwidth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the exam, they'll probably ask you to configure one or the other using &lt;code&gt;nmcli&lt;/code&gt; or &lt;code&gt;ip&lt;/code&gt; commands. Just remember the concept - the syntax you can look up.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Honestly, once the bridge vs bond concept clicked for me, a lot of other networking stuff started making sense too.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bridge = connect networks&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Bond = combine NICs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's it. That's the tweet.&lt;/p&gt;

&lt;p&gt;If you're setting up a homelab, start with a simple bridge for your VMs. If you're managing production servers, look into bonding for HA. And if you're studying for LFCS, just understand the concepts - the commands are easy once you know what you're trying to achieve.&lt;/p&gt;

&lt;p&gt;Hope this helps someone out there who was as confused as I was!&lt;/p&gt;

&lt;p&gt;Feel free to drop any questions below - I'm still learning too, so we can figure it out together.&lt;/p&gt;

&lt;p&gt;Cheers! ✨&lt;/p&gt;

</description>
      <category>linux</category>
      <category>networking</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>AWS CDK Python</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Wed, 04 May 2022 05:21:14 +0000</pubDate>
      <link>https://dev.to/dporwal/aws-cdk-python-2ado</link>
      <guid>https://dev.to/dporwal/aws-cdk-python-2ado</guid>
      <description>&lt;h2&gt;
  
  
  Basics:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---3onRk-W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hiazt3dc26at7vugjx7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---3onRk-W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1hiazt3dc26at7vugjx7.png" alt="cdk" width="880" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Resources and Identifiers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Any piece of Infrastructure that is created via CDK is a &lt;strong&gt;Resource&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Every Resource has an &lt;strong&gt;identifier&lt;/strong&gt; which will help you to refrence it later.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Resource&lt;/strong&gt; in the CDK maps to a Resource in CloudFormation&lt;/li&gt;
&lt;li&gt;The Resource Identifierwill also be the Identifierwith CloudFormation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Constructs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A Construct is a logical grouping of one or more Resources.&lt;/li&gt;
&lt;li&gt;Constructs are the building blocks with the CDK.&lt;/li&gt;
&lt;li&gt;Constructs can be programmatically customized.&lt;/li&gt;
&lt;li&gt;Constructs enable customizable reuse within an Organization.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can also create another resource out of the construct.&lt;br&gt;
Eg. we need to have a &lt;em&gt;Resource&lt;/em&gt; (security group) and an &lt;em&gt;Identifier&lt;/em&gt; with (WebSG)&lt;/p&gt;

&lt;p&gt;To deploy all of the above resources, called &lt;strong&gt;&lt;em&gt;Stack&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Stack
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A stack is the unit of deployment within CDK.&lt;/li&gt;
&lt;li&gt;A stack in the CDK corresponds to a stack in Cloudformation.&lt;/li&gt;
&lt;li&gt;Stacks share cloudformation Stack limitations.&lt;/li&gt;
&lt;li&gt;Every stack has an Environment that specifies account and region.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environments&lt;/strong&gt; can be either explicity or implicitly define.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  App
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A CDK App is the root of the context tree for a CDK Project.&lt;/li&gt;
&lt;li&gt;An App can contain one or more stack.&lt;/li&gt;
&lt;li&gt;Each stack within an App can contain its own environment.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  CDK Workflow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Init&lt;/strong&gt; --&amp;gt; Project is created using the command line tool&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bootstrap&lt;/strong&gt; --&amp;gt; Create needed AWS Resources for CDK Enviroment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Synth&lt;/strong&gt; --&amp;gt; Generate Cloudformation template from Code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy&lt;/strong&gt; --&amp;gt; Template are launched by Cloudformation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update&lt;/strong&gt; --&amp;gt; CDK Project is updated with new Infrastructure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diff&lt;/strong&gt; --&amp;gt; Update Against deployed stack are Identified&lt;/li&gt;
&lt;li&gt;Again &lt;strong&gt;Deploy&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Why use the AWS CDK
&lt;/h3&gt;

&lt;p&gt;Let's look at the power of the AWS CDK. Here is some code in an AWS CDK&lt;br&gt;
project to create an Amazon ECS service with AWS Fargate launch type (this is&lt;br&gt;
the code we use in the Creating an AWS Fargate service using the AWS CDK).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyEcsConstructStack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;core&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Stack&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;core&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Construct&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nb"&gt;super&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;vpc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ec2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Vpc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"MyVpc"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_azs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# default is all AZs in region
&lt;/span&gt;        &lt;span class="n"&gt;cluster&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ecs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Cluster&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"MyCluster"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vpc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;vpc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;ecs_patterns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ApplicationLoadBalancedFargateService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"MyFargateService"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;cluster&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;cluster&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Required
&lt;/span&gt;            &lt;span class="n"&gt;cpu&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Default is 256
&lt;/span&gt;            &lt;span class="n"&gt;desired_count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Default is 1
&lt;/span&gt;                                &lt;span class="n"&gt;task_image_options&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ecs_patterns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ApplicationLoadBalancedTaskImageOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ecs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ContainerImage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;from_registry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"amazon/amazon-ecssample"&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
            &lt;span class="n"&gt;memory_limit_mib&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Default is 512
&lt;/span&gt;            &lt;span class="n"&gt;public_load_balancer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Default is False
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class produces an AWS CloudFormation template of more than 500&lt;br&gt;
lines.&lt;/p&gt;
&lt;h2&gt;
  
  
  Other advantages of the AWS CDK include:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use logic (if statements, for-loops, etc) when defining your infrastructure&lt;/li&gt;
&lt;li&gt;Use object-oriented techniques to create a model of your system&lt;/li&gt;
&lt;li&gt;Define high level abstractions, share them, and publish them to your team, company, or community&lt;/li&gt;
&lt;li&gt;Organize your project into logical modules&lt;/li&gt;
&lt;li&gt;Share and reuse your infrastructure as a library&lt;/li&gt;
&lt;li&gt;Testing your infrastructure code using industry-standard protocols&lt;/li&gt;
&lt;li&gt;Use your existing code review workflow&lt;/li&gt;
&lt;li&gt;Code completion within your IDE&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Developing with the AWS CDK
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;AWS CDK Toolkit&lt;/strong&gt; is a command line tool for interacting with CDK apps. It enables developers to synthesize artifacts such as AWS CloudFormation templates, deploy stacks to development AWS accounts, and diff against a deployed stack to understand the impact of a code change.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;AWS Construct Library&lt;/strong&gt; includes a module for each AWS service with constructs that offer rich APIs that encapsulate the details of how to create resources for an Amazon or AWS service. The aim of the AWS Construct Library is to reduce the complexity and glue logic required when integrating various AWS services to achieve your goals on AWS.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;:&lt;br&gt;
There is no charge for using the AWS CDK, but you might incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage. Use the &lt;strong&gt;AWS Pricing Calculator&lt;/strong&gt; to estimate charges for the use of various AWS resources.&lt;/p&gt;


&lt;h2&gt;
  
  
  Getting Started:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Create the App:
&lt;/h3&gt;

&lt;p&gt;Each AWS CDK app should be in its own directory, with its own local module dependencies. Create a new directory for your app. Starting in your home directory, or another directory if you prefer, issue the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;hello-cdk
&lt;span class="nb"&gt;cd &lt;/span&gt;hello-cdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Important&lt;/em&gt;&lt;br&gt;
Be sure to use the name &lt;em&gt;hello-cdk&lt;/em&gt; for your project directory, exactly as shown here. The AWS CDK project template uses the directory name to name things in the generated code, so if you use a different name, some of the code in this tutorial won't work.&lt;/p&gt;

&lt;p&gt;Now initialize the app using the cdk init command, specifying the desired template ("app") and programming language.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk init TEMPLATE &lt;span class="nt"&gt;--language&lt;/span&gt; LANGUAGE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;i.e&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk init app &lt;span class="nt"&gt;--language&lt;/span&gt; python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;![[Pasted image 20220405151619.png]]&lt;/p&gt;

&lt;p&gt;After the app has been created, also enter the following two commands to activate the app's Python virtual environment and install its dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; .venv/Scripts/activate
python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Tip&lt;/em&gt;&lt;/strong&gt; --&amp;gt; &lt;br&gt;
If you don't specify a template, the default is "&lt;strong&gt;app&lt;/strong&gt;," which is the one we wanted anyway, so technically you can leave it out and save four keystrokes. If you have Git installed, each project you create using &lt;strong&gt;cdk init&lt;/strong&gt; is also initialized as a Git repository. We'll ignore that for now, but it's there when you need it.&lt;/p&gt;

&lt;p&gt;Here in Python Building is not required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List the stacks in the app&lt;/strong&gt;&lt;br&gt;
Just to verify everything is working correctly, list the stacks in your app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't see &lt;em&gt;HelloCdkStack&lt;/em&gt;, make sure you named your app's directory &lt;em&gt;hello-cdk&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="" class="article-body-image-wrapper"&gt;&lt;img alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Add an Amazon S3 bucket
&lt;/h4&gt;

&lt;p&gt;At this point, your app doesn't do anything useful because the stack doesn't define any resources. Let's define an Amazon S3 bucket. Install the Amazon S3 package from the AWS Construct Library.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;aws-cdk.aws-s3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the first import statement in &lt;em&gt;hello_cdk_stack.py&lt;/em&gt; in the &lt;em&gt;hello_cdk&lt;/em&gt; directory with the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;aws_cdk&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aws_s3&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;core&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#Replace the comment with the following code.
&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Bucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"MyFirstBucket"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;versioned&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bucket is the first construct we've seen, so let's take a closer look. Like all constructs, the Bucket class takes three parameters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;scope:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
Tells the bucket that the stack is its parent: it is defined within the scope of the stack. You can define constructs inside of constructs, creating a hierarchy (tree).&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Id:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
The logical ID of the Bucket within your AWS CDK app. This (plus a hash based on the bucket's location within the stack) uniquely identifies the bucket across deployments so the AWS CDK can update it if you change how it's defined in your app. Buckets can also have a name, which is separate from this ID (it's the bucketName property).&lt;br&gt;
&lt;strong&gt;&lt;em&gt;props:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
A bundle of values that define properties of the bucket. Here we've defined only one roperty: versioned, which enables versioning for the files in the bucket.&lt;br&gt;
All constructs take these same three arguments, so it's easy to stay oriented as you learn about new ones. And as you might expect, you can subclass any construct to extend it to suit your needs, or just to change its defaults.&lt;/p&gt;

&lt;p&gt;Tip --&amp;gt;&lt;br&gt;
If all a construct's props are optional, you can omit the third parameter entirely.&lt;/p&gt;
&lt;h4&gt;
  
  
  Synthesize an AWS CloudFormation template
&lt;/h4&gt;

&lt;p&gt;Synthesize an AWS CloudFormation template for the app, as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk synth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your app contained more than one stack, you'd need to specify which stack(s) to synthesize. But since it only contains one, the Toolkit knows you must mean that one.&lt;/p&gt;

&lt;p&gt;Tip --&amp;gt;&lt;br&gt;
If you received an error like "--app" is required..., it's probably because you are running the command from a subdirectory. Navigate to the main app directory and try again.&lt;/p&gt;

&lt;p&gt;The cdk synth command executes your app, which causes the resources defined in it to be translated to an AWS CloudFormation template. The output of cdk synth is a YAML-format AWS CloudFormation template, which looks something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;MyFirstBucketB8884501&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::S3::Bucket&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;VersioningConfiguration&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;Status&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Enabled&lt;/span&gt;
    &lt;span class="na"&gt;UpdateReplacePolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Retain&lt;/span&gt;
    &lt;span class="na"&gt;DeletionPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Retain&lt;/span&gt;
    &lt;span class="na"&gt;Metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="s"&gt;aws:cdk:path: HelloCdkStack/MyFirstBucket/Resource&lt;/span&gt;
  &lt;span class="na"&gt;CDKMetadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::CDK::Metadata&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;Analytics&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v2:deflate64:H4sIAAAAAAAA/yXIQQ5AMBBA0bPYt0NZ2XIB4QBSVTHKNNFpRMTdEav/8nNQJWSJPoI0o5MrDnB1rI0T7+pDAVcVjbMs6ol+3R9bG3zcjf1cexqR0dMtmpNnT2kBJSiVLAFR7pEYNwvt3wd3SI6vcAAAAA==&lt;/span&gt;
    &lt;span class="na"&gt;Metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="s"&gt;aws:cdk:path: HelloCdkStack/CDKMetadata/Default&lt;/span&gt;
    &lt;span class="na"&gt;Condition&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CDKMetadataAvailable&lt;/span&gt;
&lt;span class="na"&gt;Conditions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;CDKMetadataAvailable&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even if you aren't very familiar with AWS CloudFormation, you should be able to find the definition for an &lt;strong&gt;AWS::S3::Bucket&lt;/strong&gt; and see how the versioning configuration was translated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Every generated template contains a &lt;strong&gt;AWS::CDK::Metadata&lt;/strong&gt; resource by default. The AWS CDK team uses this metadata to gain insight into how the AWS CDK is used, so we can continue to improve it. For details, including how to opt out of version reporting, see Version reporting. The cdk synth generates a perfectly valid AWS CloudFormation template. You could take it and deploy it using the AWS CloudFormation console. But the AWS CDK Toolkit also has that feature built-in.&lt;/p&gt;
&lt;h3&gt;
  
  
  Deploying the stack
&lt;/h3&gt;

&lt;p&gt;To deploy the stack using AWS CloudFormation, issue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As with cdk synth, you don't need to specify the name of the stack since there's only one in the app. It is optional (though good practice) to synthesize before deploying. The AWS&lt;br&gt;
CDK synthesizes your stack before each deployment. If your code changes have security implications, you'll see a summary of these, and be asked to confirm them before deployment proceeds. cdk deploy displays progress information as your stack is deployed. When it's done, the command prompt reappears. You can go to the AWS CloudFormation console and see that it now lists &lt;em&gt;HelloCdkStack&lt;/em&gt;. You'll also find&lt;br&gt;
MyFirstBucket in the Amazon S3 console.&lt;br&gt;
You've deployed your first stack using the AWS CDK—congratulations! But&lt;br&gt;
that's not all there is to the AWS CDK.&lt;/p&gt;
&lt;h3&gt;
  
  
  Modifying the app
&lt;/h3&gt;

&lt;p&gt;The AWS CDK can update your deployed resources after you modify your app. Let's make a little change to our bucket. We want to be able to &lt;em&gt;delete the bucket automatically when we delete the stack, so we'll change the RemovalPolicy.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# hello_cdk/hello_cdk_stack.py
&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Bucket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"MyFirstBucket"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;versioned&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;removal_policy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;core&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RemovalPolicy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DESTROY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we'll use the &lt;em&gt;cdk diff&lt;/em&gt; command to see the differences between what's already been deployed, and the code we just changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk diff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The AWS CDK Toolkit queries your AWS account for the current AWS CloudFormation template for the hello-cdk stack, and compares it with the template it synthesized from your app. The Resources section of the output should look like the following.&lt;/p&gt;

&lt;p&gt;[~] AWS::S3::Bucket MyFirstBucket MyFirstBucketB8884501&lt;br&gt;
├─ [~] DeletionPolicy&lt;br&gt;
│ ├─ [-] Retain&lt;br&gt;
│ └─ [+] Delete&lt;br&gt;
└─ [~] UpdateReplacePolicy&lt;br&gt;
├─ [-] Retain&lt;br&gt;
└─ [+] Delete&lt;/p&gt;

&lt;p&gt;As you can see, the diff indicates that the DeletionPolicy property of the bucket is now set to Delete, enabling the bucket to be deleted when its stack is deleted. The UpdateReplacePolicy is also changed.&lt;br&gt;
Don't be confused by the difference in name. The AWS CDK calls it RemovalPolicy because its meaning is slightly different from AWS CloudFormation's DeletionPolicy: the AWS CDK default is to retain the bucket when the stack is deleted, while AWS CloudFormation's default is to delete it. See Removal policies for further details.&lt;br&gt;
You can also see that the bucket isn't going to be replaced, but will be updated instead.&lt;br&gt;
Now let's deploy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter y to approve the changes and deploy the updated stack. The Toolkit updates the bucket configuration as you requested.&lt;/p&gt;

&lt;h3&gt;
  
  
  Destroying the app's resources
&lt;/h3&gt;

&lt;p&gt;Now that you're done with the quick tour, destroy your app's resources to avoid incurring any costs from the bucket you created, as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cdk destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enter y to approve the changes and delete any stack resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
This wouldn't have worked if we hadn't changed the bucket's &lt;strong&gt;&lt;em&gt;RemovalPolicy&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
just a minute ago!&lt;br&gt;
If &lt;em&gt;cdk destroy&lt;/em&gt; fails, it probably means you put something in your Amazon S3 bucket. AWS CloudFormation won't delete buckets with files in them. Delete the files and try again.&lt;/p&gt;
&lt;h3&gt;
  
  
  Working with the AWS CDK in Python
&lt;/h3&gt;

&lt;p&gt;Python is a fully-supported client language for the AWS CDK and is considered stable. Working with the AWS CDK in Python uses familiar tools, including the standard Python implementation (CPython), virtual environments with virtualenv, and the Python package installer pip. The modules comprising the AWS Construct Library are distributed via pypi.org. The Python version of the AWS CDK even uses Python-style identifiers (for example, snake_case method names).&lt;br&gt;
You can use any editor or IDE; many AWS CDK developers use Visual Studio Code (or its open-source equivalent VSCodium), which has good support for Python via an official extension. The IDLE editor included with Python will suffice to get started. The Python modules for the AWS CDK do have type hints, which are useful for a linting tool or an IDE that supports type validation.&lt;/p&gt;
&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;To work with the AWS CDK, you must have an AWS account and credentials and have installed Node.js and the AWS CDK Toolkit. See AWS CDK Prerequisites.&lt;br&gt;
Python AWS CDK applications require Python 3.6 or later. If you don't already have it installed, download a compatible version for your platform at &lt;em&gt;python.org&lt;/em&gt;. If you run Linux, your system may have come with a compatible version, or you may install it using your distro's package manager (yum, apt, etc.).&lt;br&gt;
Mac users may be interested in Homebrew, a Linux-style package manager for Mac OS X.&lt;br&gt;
The Python package installer, pip, and virtual environment manager, virtualenv, are also required. Windows installations of compatible Python versions include these tools. On Linux, pip and virtualenv may be provided as separate packages in your package manager. Alternatively, you may install them with the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; ensurepip &lt;span class="nt"&gt;--upgrade&lt;/span&gt;
python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; pip
python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you encounter a permission error, run the above commands with the --user flag so that the modules are installed in your user directory, or use sudo to obtain the permissions to install the modules system-wide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
It is common for Linux distros to use the executable name python3 for Python 3.x, and have python refer to a Python 2.x installation. You can adjust the command used to run your application by editing cdk.json in the project's main directory.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating a project
&lt;/h4&gt;

&lt;p&gt;You create a new AWS CDK project by invoking cdk init in an empty directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;my-project
&lt;span class="nb"&gt;cd &lt;/span&gt;my-project
cdk init app &lt;span class="nt"&gt;--language&lt;/span&gt; python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;cdk init uses the name of the project folder to name various elements of the project, including classes, subfolders, and files. After initializing the project, activate the project's virtual environment. This allows the project's dependencies to be installed locally in the project folder, instead of globally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; .env/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
You may recognize this as the Mac/Linux command to activate a virtual environment. The Python templates include a batch file, source.bat, that allows the same command to be used on Windows. The traditional Windows command, &lt;em&gt;.env\Scripts\activate.bat&lt;/em&gt;, works, too. Then install the app's standard dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important&lt;/strong&gt;&lt;br&gt;
Activate the project's virtual environment whenever you start working on it. Otherwise, you won't have access to the modules installed there, and modules you install will go in the Python global module directory (or will result in a permission error).&lt;/p&gt;
&lt;h4&gt;
  
  
  Managing AWS construct library modules
&lt;/h4&gt;

&lt;p&gt;Use the Python package installer, &lt;em&gt;pip&lt;/em&gt;, to install and update AWS Construct Library modules for use by your apps, as well as other packages you need. pip also installs the dependencies for those modules automatically. To run &lt;em&gt;pip&lt;/em&gt; without needing it installed in a special directory, invoke it as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; pip PIP-COMMAND
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AWS Construct Library modules are named like &lt;strong&gt;&lt;em&gt;aws-cdk.SERVICE-NAME&lt;/em&gt;&lt;/strong&gt;. For&lt;br&gt;
example, the command below installs the modules for Amazon S3 and AWS Lambda.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; pip &lt;span class="nb"&gt;install &lt;/span&gt;aws-cdk.aws-s3 aws-cdk.aws-lambda
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similar names are used for importing AWS Construct Library modules into your Python code (just replace the hyphens with underscores).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;aws_cdk.aws_s3&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;s3&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;aws_cdk.aws_lambda&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;lam&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing a module, update your project's &lt;em&gt;requirements.txt&lt;/em&gt; file, which lists your project's dependencies. It is best to do this manually rather than using pip freeze. pip freeze captures the current versions of all modules installed in your Python virtual environment, which can be useful when bundling up a project to be run elsewhere.&lt;br&gt;
Usually, though, your requirements.txt should list only top-level dependencies (modules that your app depends on directly) and not the dependencies of those modules. This strategy makes updating your dependencies simpler. Here is what your &lt;em&gt;requirements.txt&lt;/em&gt; file might look like if you have installed the Amazon S3 and AWS Lambda modules as shown earlier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws-cdk.aws-s3==X.YY.ZZ
aws-cdk.aws-lambda==X.YY.ZZ
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can edit &lt;em&gt;requirements.txt&lt;/em&gt; to allow upgrades; simply replace the == preceding a version number with ~= to allow upgrades to a higher compatible version, or remove the version requirement entirely to specify the latest available version of the module.&lt;br&gt;
With requirements.txt edited appropriately to allow upgrades, issue this command to upgrade your project's installed modules at any time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--upgrade&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
All AWS Construct Library modules used in your project must be the same version.&lt;/p&gt;
&lt;h4&gt;
  
  
  AWS CDK idioms in Python
&lt;/h4&gt;
&lt;h5&gt;
  
  
  &lt;strong&gt;Props&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;All AWS Construct Library classes are instantiated using three arguments: the &lt;strong&gt;&lt;em&gt;scope&lt;/em&gt;&lt;/strong&gt; in which the construct is being defined (its parent in the construct tree), a &lt;strong&gt;&lt;em&gt;name&lt;/em&gt;&lt;/strong&gt;, and &lt;strong&gt;&lt;em&gt;props&lt;/em&gt;&lt;/strong&gt;, a bundle of key/value pairs that the construct uses to configure the resources it creates. Other classes and methods also use the "bundle of attributes" pattern for arguments.&lt;/p&gt;

&lt;p&gt;In Python, &lt;em&gt;props&lt;/em&gt; are expressed as keyword arguments. If an argument contains nested data structures, these are expressed using a class which takes its own keyword arguments at instantiation. The same pattern is applied to other method calls that take a single structured argument.&lt;/p&gt;

&lt;p&gt;For example, in a Amazon S3 bucket's add_lifecycle_rule method, the transitions property is a list of Transition instances.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_lifecycle_rule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;transitions&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="n"&gt;Transition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;storage_class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;StorageClass&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GLACIER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;transition_after&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Duration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;days&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When extending a class or overriding a method, you may want to accept additional arguments for your own purposes that are not understood by the parent class. In this case you should accept the arguments you don't care about using the &lt;strong&gt;&lt;em&gt;kwargs&lt;/em&gt;&lt;/strong&gt; idiom, and use keyword-only arguments to accept the arguments you're interested in. When calling the parent's constructor or the overridden method, pass only the arguments it is expecting (often just &lt;strong&gt;&lt;em&gt;kwargs&lt;/em&gt;&lt;/strong&gt;). Passing arguments that the parent class or method doesn't expect results in an error.&lt;br&gt;
Future releases of the AWS CDK may coincidentally add a new property with a name you used for your own property. This won't cause any technical issues for users of your construct or method (since your property isn't passed "up the chain," the parent class or overridden method will simply use a default value) but it may cause confusion. You can avoid this potential problem by naming your properties so they clearly belong to your construct. If there are many new properties, bundle them into an appropriately-named class and pass it as a single keyword argument.***&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AWS: Launch an EC2 Instance from the Web Console</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Fri, 18 Feb 2022 07:52:41 +0000</pubDate>
      <link>https://dev.to/dporwal/aws-launch-an-ec2-instance-from-the-web-console-3124</link>
      <guid>https://dev.to/dporwal/aws-launch-an-ec2-instance-from-the-web-console-3124</guid>
      <description>&lt;p&gt;You are a Systems Adminstrator at Globomantics corporation. You have been asked to investigate the IaaS (Infrastructure as a Service) offerings in Amazon Web Services. To do this, you've been asked to launch an EC2 instance so that you and your team can test out the Virtual Machine capabilities on AWS.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;strong&gt;Open AWS console&lt;/strong&gt; to access the lab environment, then use the provided credentials to log in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Ensure you are in the &lt;strong&gt;US West (Oregon)&lt;/strong&gt; region in the top-right corner of your screen.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the search bar at the top to navigate to the &lt;strong&gt;EC2&lt;/strong&gt; service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the &lt;strong&gt;Launch instance&lt;/strong&gt; button and then click &lt;strong&gt;Launch instance&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;At the top of the list of AMIs on the &lt;strong&gt;Choose an Amazon Machine Image&lt;/strong&gt; start page, click the &lt;strong&gt;Select&lt;/strong&gt; button for the option labeled &lt;strong&gt;Amazon Linux 2 AMI (HVM), SSD Volume Type&lt;/strong&gt;. Keep the radio button for &lt;strong&gt;64-bit (x86)&lt;/strong&gt; selected.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h3&gt;✅ Note&lt;/h3&gt;
&lt;p&gt;This Quick Start page allows you to choose from a variety of different Amazon approved Quick Start images. Options include: Amazon Linux, Red Hat, Suse, Ubuntu, and Windows. Amazon curates this selection of Quick Start options and vendors must agree to continually update the images that appear here, to ensure they are kept up-to-date with security patches.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;blockquote&gt;
&lt;h3&gt;✅ Note&lt;/h3&gt;
&lt;p&gt;If you wanted to launch an EC2 option from an AMI (Amazon Machine Image) that does not appear in the limited Quick Start list, you could select from the other tabs on the left hand side. These options include &lt;b&gt;My AMI's&lt;/b&gt; (for images your organization has built themselves), &lt;b&gt;AWS Marketplace&lt;/b&gt; (which includes AMI's from many different vendors, often using a pay per minute model), and &lt;b&gt;Community AMI's&lt;/b&gt;, where you can find images for additional operating systems, such as CentOS and Debian.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;ol&gt;
&lt;li&gt; On the &lt;strong&gt;Choose an Instance Type&lt;/strong&gt; page, keep the &lt;strong&gt;t2.micro&lt;/strong&gt; instance type selected, then click the &lt;strong&gt;Next: Configure Instance Details&lt;/strong&gt; button at the bottom right. This instance type creates a virtual machine with 1 vCPU (virtual CPU) and 1 GiB of memory.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h3&gt;✅ Note&lt;/h3&gt;
&lt;p&gt;Notice that the t2.micro instance type has a green label for "&lt;em&gt;Free tier eligible.&lt;/em&gt;" AWS offers a free tier that allows you to launch and run a t2.micro instance for 1 year without incurring any charges. Be aware that, if this were your own AWS account, other AWS services may cause your account to incur charges – but it is possible to run some things in AWS for a year without paying anything, thanks to the generous Free tier.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;On the &lt;strong&gt;Configure Instance Details&lt;/strong&gt; page, review the available options, but keep the defaults selected. Scroll down to the &lt;strong&gt;Advanced Details&lt;/strong&gt; section and expand it if it is collapsed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;User data&lt;/strong&gt; section, keep &lt;strong&gt;As text&lt;/strong&gt; selected, and then paste the following lines into the text box:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash -xe&lt;/span&gt;
yum &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; ruby
&lt;span class="nb"&gt;cd&lt;/span&gt; /opt
curl &lt;span class="nt"&gt;-O&lt;/span&gt; https://aws-codedeploy-us-west-2.s3.amazonaws.com/latest/install
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x ./install
./install auto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then click the &lt;strong&gt;Next: Add Storage&lt;/strong&gt; button at the bottom right.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;✅ Note&lt;/h3&gt;
&lt;p&gt;The above script will download and install the AWS CodeDeploy agent immediately after the EC2 instance is launched. The usage of EC2 User data scripts is the most common way to initialize or bootstrap EC2 virtual machines.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;On the &lt;strong&gt;Add Storage&lt;/strong&gt; page, review the EBS (Elastic Block Store) Volume attributes, keep the default 8 GiB size, and then click the &lt;strong&gt;Next: Add Tags&lt;/strong&gt; button at the bottom right.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the &lt;strong&gt;Add Tags&lt;/strong&gt; page, click the &lt;strong&gt;Add Tag&lt;/strong&gt; button, enter a Key of &lt;code&gt;env&lt;/code&gt; and set its Value to &lt;code&gt;test&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add another tag with the Key &lt;code&gt;Name&lt;/code&gt; and the Value &lt;code&gt;webserver1&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h4&gt;✅ Note&lt;/h4&gt;
&lt;p&gt;The &lt;b&gt;Name&lt;/b&gt; tag (case sensitive) is a special tag that AWS uses to display the user-defined instance name on the Instances web console page.

Notice that these tags will be applied to both the EC2 instance and the EBS volume.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click the &lt;strong&gt;Next: Configure Security Group&lt;/strong&gt; button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the &lt;strong&gt;Configure Security Group&lt;/strong&gt; page, keep the &lt;strong&gt;Create a new security group&lt;/strong&gt; radio button selected, keep the default Security group name of &lt;strong&gt;launch-wizard-1&lt;/strong&gt;, and keep the auto generated &lt;strong&gt;Description&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h4&gt;ℹ️ Note&lt;/h4&gt;
&lt;p&gt;Notice that the launch wizard has populated a single Security Group Rule with Type: &lt;b&gt;SSH&lt;/b&gt;, Protocol: &lt;b&gt;TCP&lt;/b&gt;, Port Range: &lt;b&gt;22&lt;/b&gt;, and Source: &lt;b&gt;0.0.0.0/0&lt;/b&gt; (this means any IP address). This rule opens up access for the entire internet to SSH into the EC2 instance on port 22.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;ol&gt;
&lt;li&gt; Click the &lt;strong&gt;Review and Launch&lt;/strong&gt; button.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h4&gt;✅ Note&lt;/h4&gt;
&lt;p&gt;For any AWS account and EC2 instance of real importance, you should never use a Security group named after the launch-wizard, and you should not allow SSH access from the entire internet. Instead, you should give your Security Group a name that is descriptive of its purpose or function, and you should use a VPN or a Bastion host for SSH access into your EC2 instances.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;On the &lt;strong&gt;Review&lt;/strong&gt; page, you can review all of the options that you have selected throughout the Launch wizard process. Click the &lt;strong&gt;Launch&lt;/strong&gt; button at the bottom right.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will now see a &lt;strong&gt;Select an existing key pair or create a new key pair&lt;/strong&gt; modal. Click on the &lt;strong&gt;Choose an existing key pair&lt;/strong&gt; dropdown and select &lt;strong&gt;Proceed without a key pair&lt;/strong&gt;, then add a checkmark to the acknowledgement box that informs you that you will not be able to connect to the instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the &lt;strong&gt;Launch Instances&lt;/strong&gt; button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h4&gt;✅ Note&lt;/h4&gt;
&lt;p&gt;Typically when launching an EC2 instance you would create and select an existing key pair that you've already added to your AWS account. This key pair allows you to SSH into the EC2 instance using the default user.&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;p&gt;After a brief &lt;strong&gt;Initiating Instance Launches&lt;/strong&gt; page, you'll be taken to a &lt;strong&gt;Launch Status&lt;/strong&gt; page, and you should see a green box at the top of the page that says &lt;strong&gt;Your instances are now launching&lt;/strong&gt;. You should also see a unique instance identifier, which looks like &lt;code&gt;i-XXXXXXXXXX&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Congratulations! You have successfully used the EC2 Launch Wizard to create an EC2 instance on a t2.micro instance type, using the Amazon Linux 2 operating system, with a User data script that installs the AWS Code Deploy agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verify the Instance Status
&lt;/h2&gt;

&lt;p&gt;Now that your EC2 Instance has been launched, you will verify its status.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You should still be on the &lt;strong&gt;Launch Status&lt;/strong&gt; page from the last challenge. Click the &lt;strong&gt;View Instances&lt;/strong&gt; button on the bottom right, which will take you to the &lt;strong&gt;Instances&lt;/strong&gt; page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You should see your instance named &lt;strong&gt;webserver1&lt;/strong&gt; in the &lt;strong&gt;Instances&lt;/strong&gt; list.&lt;/p&gt;

&lt;p&gt;Under the &lt;strong&gt;Instance state&lt;/strong&gt; column, your instance should say &lt;strong&gt;Running&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check the box to the left of &lt;strong&gt;webserver1&lt;/strong&gt;. You should now see details for the instance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;Status checks&lt;/strong&gt; tab. You should see green checkmarks and a &lt;strong&gt;passed&lt;/strong&gt; message under both &lt;strong&gt;System status checks&lt;/strong&gt; and &lt;strong&gt;Instance status checks&lt;/strong&gt;. This indicates that your instance is viewed as 100% healthy and is ready for use.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;h4&gt;✅ Note&lt;/h4&gt;
&lt;p&gt;If both of these statuses are not yet green, you may need to wait a few minutes for the status checks to complete their runs, which can take some time after the initial instance launch.

The "System status checks" monitor the underlying AWS systems on which your instance runs. Only AWS can resolve "System Status check" issues, although you can &lt;em&gt;Stop&lt;/em&gt; and then &lt;em&gt;Start&lt;/em&gt; your instance to move it to new underlying hardware. The "Instance status checks" monitor the software and network configuration of your individual instance. If there is an issue with the Instance status check, and not an issue with the System status checks, then you can often resolve the issue on your own.
&lt;/p&gt;
&lt;/blockquote&gt;
    

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click on the &lt;strong&gt;Monitoring&lt;/strong&gt; tab and you should see some activity in the graphs for &lt;strong&gt;CPU&lt;/strong&gt; and &lt;strong&gt;Network&lt;/strong&gt; activity. This activity confirms that your EC2 instance is using its vCPU and that it is communicating on the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If no activity is shown on the graphs, wait a few minutes and then click the refresh button at the top right, above the graph boxes, inside the Monitoring tab.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Congratulations! You have verified the status checks on your new EC2 instance and have verified that it is using its CPU and network.&lt;/p&gt;

&lt;p&gt;Your team can now begin experimenting with this EC2 instance and others, in order to evaluate the IaaS capabilities of AWS. Nice work!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/C3H--69h3Wk"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N5Qu45TG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6t7my2xyjqmjb2bvapem.png" alt="Launch an EC2" width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>linux</category>
      <category>sre</category>
    </item>
    <item>
      <title>POD Design</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Fri, 28 Jan 2022 07:19:26 +0000</pubDate>
      <link>https://dev.to/dporwal/pod-design-4f07</link>
      <guid>https://dev.to/dporwal/pod-design-4f07</guid>
      <description>&lt;h3&gt;
  
  
  Labels
&lt;/h3&gt;

&lt;p&gt;Labels are nothing but the tags to the kubernetes object for the identification. Doubtfulness of the servers would lead to mistakes on stopping or terminating.&lt;br&gt;
&lt;em&gt;AWS TAG&lt;/em&gt; = &lt;em&gt;Labels&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Labels are key/value pairs that are attached to objects, such as pods.&lt;/p&gt;

&lt;p&gt;eg: &lt;br&gt;
name: dporwal-server&lt;br&gt;
env: prod&lt;/p&gt;
&lt;h4&gt;
  
  
  Set Labels to the kubernetes objects
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# creating pods&lt;/span&gt;
kubectl run nginx &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx
kubectl run nginx2 &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx

&lt;span class="c"&gt;#give label to pods&lt;/span&gt;
kubectl label pods nginx &lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dev
kubectl label pods nginx2 &lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;prod

&lt;span class="c"&gt;#see labels of pods&lt;/span&gt;
kubectl get pods &lt;span class="nt"&gt;--show-labels&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;DEMO:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4o2q08kv5b1iubg1zh1g.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4o2q08kv5b1iubg1zh1g.gif" alt="kubectl label"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Selectors
&lt;/h3&gt;

&lt;p&gt;Basically to filter-out the k8s objects is the functionality of selectors.&lt;/p&gt;

&lt;p&gt;Suppose you only want to see the prod server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get pods &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;prod

&lt;span class="c"&gt;#similarly to dev&lt;/span&gt;
kubectl get pods &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose you want to get all the pods that are not prod.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get pods &lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;prod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Labels In YAML file
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx-pod&lt;/span&gt;
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prod&lt;/span&gt;
    &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;democontainer&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8080&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ReplicaSets (&lt;em&gt;AWS = Auto Scalling&lt;/em&gt;)
&lt;/h3&gt;

&lt;p&gt;A ReplicaSet purpose is to maintain a stable set of replica Pods running at any given of time.&lt;/p&gt;

&lt;p&gt;Desired State - Number of Pods you want&lt;br&gt;
Current State - Number of Pods are currently running&lt;/p&gt;

&lt;p&gt;It always try to maintain the Desired State with the current state.&lt;/p&gt;

&lt;p&gt;We will create YAML file to launch our first ReplicaSet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; replicaset.yaml
kubectl get pods &lt;span class="nt"&gt;--show-labels&lt;/span&gt;
kubectl delete rs dporwal-replicaset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ReplicaSet&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dporwal-replicaset&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php-redis&lt;/span&gt;
          &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gcr.io/google_samples/gb-frontend:v3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz7oqpklmc80ynquqtbzj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz7oqpklmc80ynquqtbzj.png" alt="Replicaset"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployments
&lt;/h3&gt;

&lt;p&gt;Suppose replicaset is having 3 desired tomorrow you need 5, then every time we need to have make changes on replicaset.yaml. Here Deployments come for this solution&lt;/p&gt;

&lt;p&gt;Benefits is Rolling out changes, which make the replicaset and deploy the latest version and then redirect from older version replicaset to latest version replicaset.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating first Deployment set
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deployment&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dporwal-deployment&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php-redis&lt;/span&gt;
          &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gcr.io/google_samples/gb-frontend:v3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdjd7l8tfqtknmgm21qa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdjd7l8tfqtknmgm21qa.png" alt="Deployment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets suppose we made the changes and bring-up the new version.&lt;br&gt;
we changed image from &lt;em&gt;gcr.io/google_samples/gb-frontend:v3&lt;/em&gt; to &lt;em&gt;nginx&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Deployment&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dporwal-deployment&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;tier&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;frontend&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;php-redis&lt;/span&gt;
          &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when we will run this yaml file, it will bring the previous version replicaset down and will create a new replicaset.&lt;br&gt;
let me show you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxaxnuv0d5mqb2gjlf3p5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxaxnuv0d5mqb2gjlf3p5.png" alt="new revision Deployment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is a strategy of rolling-out the changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;25% max unavailable, 25% max surge&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl describe deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F687lipdn5k5xdsjl5e74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F687lipdn5k5xdsjl5e74.png" alt="Rolling strategy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here Deployment ensures that only certain number of pods are down which the changes are rolling out. By default it ensures that &lt;em&gt;least 25% of desired pods are up(25% max unavailable).&lt;/em&gt;&lt;br&gt;
Deployments keep the history of the version that are made.&lt;/p&gt;

&lt;p&gt;To check the revisions of the deployment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl rollout &lt;span class="nb"&gt;history &lt;/span&gt;deployment.v1.apps/dporwal-deployment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulx4nbigbjwp26vyt5fh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fulx4nbigbjwp26vyt5fh.png" alt="describe deployment version"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Rollback
&lt;/h3&gt;

&lt;p&gt;Lets rollback it to revision 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl rollout undo deployment.v1.apps/dporwal-deployment &lt;span class="nt"&gt;--to-revision&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zf1ei0hh9jxkfu7wg6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8zf1ei0hh9jxkfu7wg6g.png" alt="rollback"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment Configuration
&lt;/h3&gt;

&lt;p&gt;There are 2 main configs for the deployments.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;maxSurge - Max number of pods can be scheduled above the existing pods.&lt;/li&gt;
&lt;li&gt;maxUnavailable - Max number of pods that can be unavailable during the update.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;for eg: &lt;br&gt;
maxUnavailable=0 and maxSurge=20% &amp;lt;&amp;lt; Full Capacity is maintained&lt;br&gt;
maxUnavailable=10% and maxSurge=0 &amp;lt;&amp;lt; Update with no extra capacity, In-place update.&lt;/p&gt;

&lt;p&gt;Default:&lt;br&gt;
maxSurge: 25%&lt;br&gt;
maxUnavailable: 25%&lt;/p&gt;

&lt;p&gt;You can edit the deployement config, by following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl edit deployment dporwal-deployment

&lt;span class="c"&gt;#making the changes to the deployment set and apply it&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl &lt;span class="nb"&gt;set &lt;/span&gt;image deployment dporwal-deployment &lt;span class="nv"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx:alpine

&lt;span class="c"&gt;#To scale Pods for the deployments&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl scale deployment dporwal-deployment &lt;span class="nt"&gt;--replicas&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://kubernetes.io/docs/home/" rel="noopener noreferrer"&gt;Official Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/certified-kubernetes-administrator/" rel="noopener noreferrer"&gt;Udemy Course&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/dporwal/getting-started-with-kubernetes-4mdc"&gt;Getting Started with Kubernetes&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/dporwal/kubernetes-pods-3mk5"&gt;Kubernetes PODs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora" rel="noopener noreferrer"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>docker</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Kubernetes PODs</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Tue, 12 Oct 2021 12:04:12 +0000</pubDate>
      <link>https://dev.to/dporwal/kubernetes-pods-3mk5</link>
      <guid>https://dev.to/dporwal/kubernetes-pods-3mk5</guid>
      <description>&lt;p&gt;Here we will see the practical aspects of Orchestration Containers.&lt;br&gt;
We will see how same task is perform by the Docker set of Commands comparing to the Kubernetes commands.&lt;/p&gt;
&lt;h3&gt;
  
  
  Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vL-p_XZ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hcchala6xwqu1kvwufm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vL-p_XZ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hcchala6xwqu1kvwufm.png" alt="architecture"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Run Our First Container
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Docker Command
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--name&lt;/span&gt; mywebserver nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Kubectl command
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl run mywebserver &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gk4lQlmz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4s1bume15zwh2o4e3o9d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gk4lQlmz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4s1bume15zwh2o4e3o9d.png" alt="run kubectl pod"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Exec into Container
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Docker Command
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; mywebserver bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  K8s Command
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; mywebserver &lt;span class="nt"&gt;--&lt;/span&gt; bash
OR
kuberctl &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; mywebserver &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UVQj2CQP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jn9f6dub0jxyqwyfttwi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UVQj2CQP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jn9f6dub0jxyqwyfttwi.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Removing Container
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Docker commands
&lt;/h4&gt;

&lt;p&gt;Before removing the particular container we have to stop the container and then we can remove it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container stop mywebserver
docker container &lt;span class="nb"&gt;rm &lt;/span&gt;mywebserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  kubectl command
&lt;/h4&gt;

&lt;p&gt;We don't need to stop the pod before removing, k8s take care of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl delete pod mywebserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nrqJ3Gig--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xytly11r792oh5cefxjz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nrqJ3Gig--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xytly11r792oh5cefxjz.png" alt="remove pod"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Benefits of Pods
&lt;/h3&gt;

&lt;p&gt;Many applications might have more than one container which is tightly coupled in one-to-one relationship.&lt;/p&gt;

&lt;p&gt;Here you need to know the relation between the containers, so to keep track on all the containers having dependencies. As if one goes down, complete application goes down.&lt;/p&gt;

&lt;p&gt;Linking in Docker commands,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; myweb01 function01
docker run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; myapp01 function02
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whereas, in K8s Containers within a pod share an IP address and port space, and can find each other via localhost.&lt;br&gt;
Not need to create individual container, just need to refer as a pod. No worries of one-to-one connection.&lt;br&gt;
If pod1 is not working it can create another pod2 and be available whenever needed.&lt;/p&gt;
&lt;h4&gt;
  
  
  * Pod always runs on a Node
&lt;/h4&gt;
&lt;h4&gt;
  
  
  * A node is a worker machine in k8s
&lt;/h4&gt;
&lt;h4&gt;
  
  
  * Each node is managed by master
&lt;/h4&gt;
&lt;h4&gt;
  
  
  * A node have multiple pods
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sgzBJt31--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xf3mgiszlyqqwrtwov1n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sgzBJt31--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xf3mgiszlyqqwrtwov1n.png" alt="pod oweview"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Launch multi containers Pod
&lt;/h4&gt;

&lt;p&gt;We need to use yaml file to mention the different containers and Objects/Volumes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;sidecar-pod-1&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;log&lt;/span&gt;
    &lt;span class="na"&gt;emptyDir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{}&lt;/span&gt;

  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;busybox&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;main-container&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/bin/sh&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;-c&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="s"&gt;while true; do&lt;/span&gt;
        &lt;span class="s"&gt;echo "$(date) INFO hello from main-container" &amp;gt;&amp;gt; /var/log/myapp.log ;&lt;/span&gt;
        &lt;span class="s"&gt;sleep 1;&lt;/span&gt;
      &lt;span class="s"&gt;done&lt;/span&gt;
    &lt;span class="na"&gt;volumeMounts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;log&lt;/span&gt;
      &lt;span class="na"&gt;mountPath&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/var/log&lt;/span&gt;

  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;sidecar-container&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;busybox&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;/bin/sh&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;-c&lt;/span&gt;
     &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;tail -fn+1 /var/log/myapp.log&lt;/span&gt;
    &lt;span class="na"&gt;volumeMounts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;log&lt;/span&gt;
      &lt;span class="na"&gt;mountPath&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/var/log&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;run the above yaml file, which I have named as &lt;strong&gt;&lt;em&gt;pod.yaml&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; pod.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BXf4-X5D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0oc7e0k83kbczsnv1x4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BXf4-X5D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0oc7e0k83kbczsnv1x4.png" alt="multicontainer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let us understand this YAML file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For the sake of understanding I have named my containers as main-container and sidecar-container.&lt;/li&gt;
&lt;li&gt;The main container will be our application which will continuously write something to /var/log/myapp.log&lt;/li&gt;
&lt;li&gt;The /var/log/ path is mounted on the containers using separate volume. This path is mounted using volumeMounts in both the containers so that the path is shared across both the containers.&lt;/li&gt;
&lt;li&gt;The sidecar container will read the log file content using tail -fn+1 /var/log/myapp.log&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Benefits of Configuration File
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Integrates well will change review processes&lt;/li&gt;
&lt;li&gt;Provides the source of record on what is live within the Kubernetes cluster.&lt;/li&gt;
&lt;li&gt;Easier to troubleshoot changes with version control&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Understanding POD Configurations in YAML
&lt;/h3&gt;

&lt;p&gt;In the above &lt;strong&gt;&lt;em&gt;pod.yaml&lt;/em&gt;&lt;/strong&gt; you would have seen many Important fields like apiVersion, kind, metadata, container etc.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;key&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;apiVersion&lt;/td&gt;
&lt;td&gt;Version of API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;kind&lt;/td&gt;
&lt;td&gt;kind of object you want to create&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;metadata name&lt;/td&gt;
&lt;td&gt;name of the object that name uniquely identifies it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;spec&lt;/td&gt;
&lt;td&gt;Describe state of the object&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To check apiVersion we need to access API Primitives at path &lt;strong&gt;&lt;em&gt;localhost:8080/api&lt;/em&gt;&lt;/strong&gt; through&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl proxy &lt;span class="nt"&gt;--port&lt;/span&gt; 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more fields references you can check&lt;br&gt;
&lt;a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.19/#-strong-api-overview-strong-"&gt;API Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata"&gt;Github Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;you can also take reference from CLI using below commands, but these could be not updated details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl api-resources
&lt;span class="c"&gt;#specific to pod details&lt;/span&gt;
kubectl explain pod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7pls9n3w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/psmc7pu5gt8r0j116vzd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7pls9n3w--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/psmc7pu5gt8r0j116vzd.png" alt="important configuration details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Exposing Ports for Pods
&lt;/h3&gt;

&lt;p&gt;Here we have the &lt;strong&gt;&lt;em&gt;yaml&lt;/em&gt;&lt;/strong&gt; file that, to demonstrate how we expose port. It work similar way as in Docker.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/"&gt;Reference&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2RcIGkUE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cc6c3h52rd3qk9p7o4i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2RcIGkUE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1cc6c3h52rd3qk9p7o4i.png" alt="Expose port"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets create a pod with container at port &lt;strong&gt;&lt;em&gt;8080&lt;/em&gt;&lt;/strong&gt; and we will see the pod details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx-pod&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;democontainer&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8080&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CmNamSTc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vni63ax6wp45pmhsq911.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CmNamSTc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vni63ax6wp45pmhsq911.png" alt="Lunching Pod"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and checking details&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---QSdDy4J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/85i14qjt7nffeppk8ffs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---QSdDy4J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/85i14qjt7nffeppk8ffs.png" alt="pod port details"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to check for more details about the port field in document. you can run following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl explain pod.spec.containers.ports
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--scAhXcC---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vn54x97ci17uf82933fb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--scAhXcC---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vn54x97ci17uf82933fb.png" alt="CLI ports documents"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Generating Pod Manifests using CLI
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a pod from nginx Image&lt;/span&gt;
kubectl run nginx &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx

&lt;span class="c"&gt;#Create a pod and expose to port 8080&lt;/span&gt;
kubectl run nginx &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx &lt;span class="nt"&gt;--port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8080

&lt;span class="c"&gt;# Output the manifest file&lt;/span&gt;
kubectl run nginx &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nginx &lt;span class="nt"&gt;--port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;80 &lt;span class="nt"&gt;--dry-run&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;client &lt;span class="nt"&gt;-o&lt;/span&gt; yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  detele pods
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#delete specific pod&lt;/span&gt;
kubectl delete pod &lt;span class="nb"&gt;command&lt;/span&gt;

&lt;span class="c"&gt;#delete all pods&lt;/span&gt;
kubectl delete pod &lt;span class="nt"&gt;--all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--of4VgLSa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2oojkzj44gnzdebata4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--of4VgLSa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2oojkzj44gnzdebata4.png" alt="delete pods"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://kubernetes.io/docs/home/"&gt;Official Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/certified-kubernetes-administrator/"&gt;Udemy Course&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/dporwal/getting-started-with-kubernetes-4mdc"&gt;Getting Started with Kubernetes&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/dporwal/image-creation-management-and-registry-part-1-pk9"&gt;Docker Commands&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>docker</category>
      <category>devops</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Getting Started with Kubernetes</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Tue, 05 Oct 2021 16:34:25 +0000</pubDate>
      <link>https://dev.to/dporwal/getting-started-with-kubernetes-4mdc</link>
      <guid>https://dev.to/dporwal/getting-started-with-kubernetes-4mdc</guid>
      <description>&lt;h3&gt;
  
  
  Orchestration
&lt;/h3&gt;

&lt;p&gt;Container orchestration is all about managing the life cycles of containers, especially in large, dynamic environments.&lt;/p&gt;

&lt;p&gt;Container Orchestration can be used to perform a lot of tasks, some of them includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provisioning and deployment of containers&lt;/li&gt;
&lt;li&gt;Scaling up or removing containers to spread application load evenly&lt;/li&gt;
&lt;li&gt;Movement of containers from one host to another if there is a shortage of resources&lt;/li&gt;
&lt;li&gt;Load balancing of service discovery between containers&lt;/li&gt;
&lt;li&gt;Health monitoring of containers and hosts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many container orchestration solutions which are available, some of the popular ones include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker Swarm&lt;/li&gt;
&lt;li&gt;Kubernetes&lt;/li&gt;
&lt;li&gt;Apache Mesos&lt;/li&gt;
&lt;li&gt;Elastic Container  Service (AWS ECS)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are also various container orchestration platforms available like EKS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introduction to Kubernetes
&lt;/h3&gt;

&lt;p&gt;Kubernetes (K8s) is and open-Source container Orchestration engine developed by Google.&lt;/p&gt;

&lt;p&gt;It is originally designed by Google, and is now maintained by the Cloud Native Computing Foundation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhuz8ql9dz9cldalqxjf4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhuz8ql9dz9cldalqxjf4.png" alt="K8s Architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation Options for K8s
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Installation Aspects
&lt;/h4&gt;

&lt;p&gt;Things to configure while working with Kubernetes.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sr No&lt;/th&gt;
&lt;th&gt;Things to Install&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;kubectl&lt;/td&gt;
&lt;td&gt;CLI for running user commands against cluster&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Kubernetes Master&lt;/td&gt;
&lt;td&gt;Kubernetes Cluster by itself&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Worker Node Agents&lt;/td&gt;
&lt;td&gt;Kubernetes Node Agent&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h4&gt;
  
  
  Understanding Installation Methods
&lt;/h4&gt;

&lt;p&gt;There are multiple ways to get started with fully functional k8s environment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the Managed K8s Service&lt;/li&gt;
&lt;li&gt;Use Minikube&lt;/li&gt;
&lt;li&gt;Install &amp;amp; Configure K8s Manually (Hard Way)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Install &amp;amp; Configure K8s Manually(Hard Way)
&lt;/h4&gt;

&lt;p&gt;In this approach you have to install all the components ok K8s Individually&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7jr4fb9obi8ege2xwiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7jr4fb9obi8ege2xwiz.png" alt="Hard-way"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Components to be Configured - Managed Service
&lt;/h4&gt;

&lt;p&gt;You have to just download kubectl and that's it. As rest all the things are taken care by Managed Service. Download CLI and just need to connect with K8s master.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/digitalocean-managed-kubernetes-service-54kp"&gt;Environment Setup&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Components to be Configured - Minikube
&lt;/h4&gt;

&lt;p&gt;Take care of K8s master also the worker node, then we need to configure the kubectl.&lt;br&gt;
It has disadvantage that it provision single node cluster.&lt;/p&gt;


&lt;h3&gt;
  
  
  Kubernetes API Primitives
&lt;/h3&gt;

&lt;p&gt;Depending on the Operations there are various APIs availble.&lt;/p&gt;

&lt;p&gt;eg: /apis , /metrics , &lt;br&gt;
/api/v1/pods or /api/v1/nodes or /api/v1/services&lt;/p&gt;

&lt;p&gt;to explore APIs, run below command and goto: &lt;strong&gt;&lt;em&gt;localhost:8080&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl proxy &lt;span class="nt"&gt;--port&lt;/span&gt; 8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Kubernetes POD
&lt;/h3&gt;

&lt;p&gt;A pod is a collection of containers and its storage inside a node of a Kubernetes cluster. It is possible to create a pod with multiple containers inside it. For example, keeping a database container and data container in the same pod.&lt;/p&gt;

&lt;p&gt;There are two types of Pods −&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single container pod&lt;/li&gt;
&lt;li&gt;Multi container pod&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Single container pod
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl run &amp;lt;name of pod&amp;gt; &lt;span class="nt"&gt;--image&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;name of the image from registry&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl run tomcat &lt;span class="nt"&gt;--image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; tomcat:8.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Multi container pod
&lt;/h4&gt;

&lt;p&gt;Multi container pods are created using &lt;strong&gt;&lt;em&gt;yaml mail&lt;/em&gt;&lt;/strong&gt; with the definition of the containers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
   &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Tomcat&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
   &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
   &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Tomcat&lt;/span&gt;
    &lt;span class="na"&gt;image: tomcat&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8.0&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7500&lt;/span&gt;
   &lt;span class="na"&gt;imagePullPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Always&lt;/span&gt;
   &lt;span class="na"&gt;-name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Database&lt;/span&gt;
   &lt;span class="na"&gt;Image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mongoDB&lt;/span&gt;
   &lt;span class="na"&gt;Ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;7501&lt;/span&gt;
   &lt;span class="na"&gt;imagePullPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Always&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more deep on Pods goto: &lt;a href="https://dev.to/dporwal/kubernetes-pods-3mk5"&gt;Kubernetes Pods&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Kubernetes Objects
&lt;/h3&gt;

&lt;p&gt;Kubernetes Objects are basically a record of intent that you pass on to the Kubernetes Cluster.&lt;br&gt;
Once you create the object, the kubernetes system will constantly work to ensure that object exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Commands and Arguments in K8s
&lt;/h3&gt;

&lt;p&gt;In Docker main difference between &lt;strong&gt;&lt;em&gt;ENTRYPOINT&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;CMD&lt;/em&gt;&lt;/strong&gt; is that Override the main command in Dockerfile with the command passing as arguments.&lt;/p&gt;

&lt;p&gt;Whereas, in Kubernetes we can override both the &lt;strong&gt;&lt;em&gt;ENTRYPOINT&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;CMD&lt;/em&gt;&lt;/strong&gt; with command and arguments field.&lt;/p&gt;

&lt;h4&gt;
  
  
  Dockerfile VS K8s Menifest Perspective
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Docker Field Name&lt;/th&gt;
&lt;th&gt;K8s field Name&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;ENTRYPOINT&lt;/td&gt;
&lt;td&gt;command&lt;/td&gt;
&lt;td&gt;Command that will run by the container&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CMD&lt;/td&gt;
&lt;td&gt;args&lt;/td&gt;
&lt;td&gt;Argument passed to the container&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let me show you how &lt;strong&gt;&lt;em&gt;command&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;args&lt;/em&gt;&lt;/strong&gt; work on kubernetes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8iu3h278luwsqn5lefu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8iu3h278luwsqn5lefu.gif" alt="commands with description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/" rel="noopener noreferrer"&gt;Define a Command and Arguments for a Container&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://kubernetes.io/docs/home/" rel="noopener noreferrer"&gt;Official Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/certified-kubernetes-administrator/" rel="noopener noreferrer"&gt;Udemy Course&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora" rel="noopener noreferrer"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Specific Kubernetes setups, coming soon!!!!!!!!!!!!!!!!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>microservices</category>
      <category>devops</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>DigitalOcean Managed Kubernetes Service</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Sat, 02 Oct 2021 18:28:07 +0000</pubDate>
      <link>https://dev.to/dporwal/digitalocean-managed-kubernetes-service-54kp</link>
      <guid>https://dev.to/dporwal/digitalocean-managed-kubernetes-service-54kp</guid>
      <description>&lt;h3&gt;
  
  
  Setting Up Kubernetes using Digital Ocean K8s Managed Service
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21aqdtayncaeer8p9dx8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21aqdtayncaeer8p9dx8.gif" alt="Stepstostart"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use my referral you will get $100 free usage for 3 months.&lt;br&gt;
By clicking below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/?refcode=625e4379d2d4&amp;amp;utm_campaign=Referral_Invite&amp;amp;utm_medium=Referral_Program&amp;amp;utm_source=badge" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fweb-platforms.sfo2.cdn.digitaloceanspaces.com%2FWWW%2FBadge%25201.svg" alt="DigitalOcean Referral Badge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Downloading the Config file and Setting up
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszeh846h6o9yo5x35y75.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fszeh846h6o9yo5x35y75.gif" alt="Download Config"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And when we open the config file we will see these details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9nt58ixwie29b9x39z3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe9nt58ixwie29b9x39z3.png" alt="Config File"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up CLI kubectl
&lt;/h3&gt;

&lt;p&gt;Kubectl need to connect to the k8s master, we nees:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DNS/IP of the cluster&lt;/li&gt;
&lt;li&gt;Authentication Credentials&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;which will found in &lt;strong&gt;&lt;em&gt;kubeconfig&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I'm setting up in windows. So, will be using below reference.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Download this Kubectl binary&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfzav9989xowz7rt1s2q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfzav9989xowz7rt1s2q.png" alt="DownloadBinary"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next Step, Move that Binary to &lt;strong&gt;&lt;em&gt;C:\Binaries&lt;/em&gt;&lt;/strong&gt;. If Binaries folder is not there, create one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9d9jtcu7yhqze3k3b2e6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9d9jtcu7yhqze3k3b2e6.png" alt="move"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a Environment Variable to call this Binary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnpw94g28a6opwn0dpmx7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnpw94g28a6opwn0dpmx7.png" alt="envvariable"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up config to connect with Kubernetes master
&lt;/h3&gt;

&lt;p&gt;Move the kubeconfig file to &lt;strong&gt;&lt;em&gt;C:\Users\ .kube&lt;/em&gt;&lt;/strong&gt; and name it as &lt;strong&gt;&lt;em&gt;config&lt;/em&gt;&lt;/strong&gt; ( &lt;em&gt;removing .yml extension&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpkn9xrallr1i8iyvdisi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpkn9xrallr1i8iyvdisi.png" alt="kubeconfig"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To Verify, run &lt;strong&gt;&lt;em&gt;kubectl&lt;/em&gt;&lt;/strong&gt; , it will work from any path.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F763ol48txw36cusvoc3f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F763ol48txw36cusvoc3f.png" alt="verifykubectl"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For, linux and MacOS installation refer below link.&lt;br&gt;
&lt;a href="https://kubernetes.io/docs/tasks/tools/" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/tasks/tools/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://kubernetes.io/docs/home/" rel="noopener noreferrer"&gt;Official Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/certified-kubernetes-administrator/" rel="noopener noreferrer"&gt;Udemy Course&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora" rel="noopener noreferrer"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>devops</category>
      <category>tutorial</category>
      <category>linux</category>
    </item>
    <item>
      <title>Docker Networking</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Thu, 30 Sep 2021 16:14:56 +0000</pubDate>
      <link>https://dev.to/dporwal/docker-networking-5ef0</link>
      <guid>https://dev.to/dporwal/docker-networking-5ef0</guid>
      <description>&lt;p&gt;Docker takes care of the networking aspects so that containers can communicate with other containers and also with the Docker Host.&lt;/p&gt;

&lt;p&gt;Docker networking subsystem is pluggable, using drivers. &lt;/p&gt;

&lt;p&gt;There are several drivers available by default and provides core networking functionality.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;bridge &lt;/li&gt;
&lt;li&gt;host&lt;/li&gt;
&lt;li&gt;overlay&lt;/li&gt;
&lt;li&gt;macvlan&lt;/li&gt;
&lt;li&gt;none&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can check what all the network drivers are supported by Docker Containers and also at what ip that driver is configured to connect to the other containers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you want to check particular network driver is running at what IP, we can inspect that network driver&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect bridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiiy8euep357wx8f2vvku.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiiy8euep357wx8f2vvku.png" alt="network driver"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can check what all drivers what containers are running and what are not by simply inspecting that particular network driver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect network host
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldvzn1o0anca316gpl1v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fldvzn1o0anca316gpl1v.png" alt="networkhost"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also create a docker container and can launch it to the available network drivers. Like here we have will launch a container on &lt;strong&gt;&lt;em&gt;host&lt;/em&gt;&lt;/strong&gt; driver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; myhost &lt;span class="nt"&gt;--network&lt;/span&gt; host ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1na9vsqxhwv4ziol884q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1na9vsqxhwv4ziol884q.png" alt="creatingcontainerhostnetowrk"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bridge Network
&lt;/h3&gt;

&lt;p&gt;A bridge network uses a software bridge that allows containers connected to the same bridge network to communicate while providing isolation from containers which are not connected to that bridge network.&lt;/p&gt;

&lt;p&gt;C1,C2, C3 are the containers in the bridge network, can also communicate with eachother&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvfaczb5snzwo4w5oevw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvfaczb5snzwo4w5oevw7.png" alt="BridgeNetwork"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If want to see the bridge in the docker container, you can simply inspect any docker container and there you will get the bridge details.&lt;br&gt;
While creating a container if you don't mention the network, by default it is &lt;strong&gt;&lt;em&gt;bridge&lt;/em&gt;&lt;/strong&gt; network&lt;br&gt;
We also can create User-defined Bridge Network which are superior to the default bridge.&lt;/p&gt;

&lt;p&gt;Let me show you how two docker containers can connect with each other.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1:Created 2 docker containers &lt;strong&gt;&lt;em&gt;bridge01&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;bridge02&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; bridge01 ubuntu
docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; bridge02 ubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Step 2: Enter into the &lt;strong&gt;&lt;em&gt;bridge01&lt;/em&gt;&lt;/strong&gt; container and installed the net-tools(ifconfig) and iputils-ping(ping) using below commands.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; bridge01 bash
apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install &lt;/span&gt;net-tools
apt-get &lt;span class="nb"&gt;install &lt;/span&gt;iputils-ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Step3: We will check the ip address for &lt;strong&gt;&lt;em&gt;bridge02&lt;/em&gt;&lt;/strong&gt; . So, to ping to this container.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect bridge02
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdoprmoy61430xn7tg2jd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdoprmoy61430xn7tg2jd.png" alt="inspectdockercontainer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 4: Here we ping the &lt;strong&gt;&lt;em&gt;bridge02&lt;/em&gt;&lt;/strong&gt; container from &lt;strong&gt;&lt;em&gt;bridge01&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; bridge01 bash
ping 172.17.0.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp1th2o5lsuli7fdfgo36.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp1th2o5lsuli7fdfgo36.png" alt="pingcontainer"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  User-Defined Bridge Network
&lt;/h3&gt;

&lt;p&gt;Differences between user-defined bridges and the default bridge&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User-defined bridges provide automatic DNS resolution between containers.&lt;/li&gt;
&lt;li&gt;User-defined bridges provide better isolation&lt;/li&gt;
&lt;li&gt;Containers can be attached and detached from user-defined networks on the fly.&lt;/li&gt;
&lt;li&gt;Each user-defined network creates a configurable bridge.&lt;/li&gt;
&lt;li&gt;Linked containers on the default bridge network share environment variables.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reference: &lt;a href="https://docs.docker.com/network/bridge/" rel="noopener noreferrer"&gt;https://docs.docker.com/network/bridge/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets create a custom user-defined bridge.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network create &lt;span class="nt"&gt;--driver&lt;/span&gt; bridge mybridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7g2ceh17lnsm4qakoto.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7g2ceh17lnsm4qakoto.png" alt="customnetworkbridge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we don't define the driver, it will by default take the bridge driver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network create mybridge-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5mcg2bxzyictgdnfmpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5mcg2bxzyictgdnfmpd.png" alt="defaultbridgecustom"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the subnet and Gateway details of our custom network.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network inspect mybridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nff5olwgd0ijy57bruv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2nff5olwgd0ijy57bruv.png" alt="subnetgateway"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we can see that new network containers will be created inside the ubuntu docker container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkedif9wxt3xr47y2xto.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwkedif9wxt3xr47y2xto.png" alt="networkcontainer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Now, let me show you the best feature of the custom user-defined network. which is ( &lt;em&gt;User-defined bridges provide automatic DNS resolution between containers.&lt;/em&gt; )
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Step1 : Creating 2 docker containers(&lt;strong&gt;&lt;em&gt;mybridge01&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;mybridge01&lt;/em&gt;&lt;/strong&gt;) on custom network (&lt;strong&gt;&lt;em&gt;mybridge&lt;/em&gt;&lt;/strong&gt;) that we have created.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fefr6kgefhuf15md7lm1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fefr6kgefhuf15md7lm1w.png" alt="dockercontainersoncustomnetwork"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; mybridge01 &lt;span class="nt"&gt;--network&lt;/span&gt; mybridge ubuntu
docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; mybridge02 &lt;span class="nt"&gt;--network&lt;/span&gt; mybridge ubuntu
apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install &lt;/span&gt;net-tools &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install &lt;/span&gt;iputils-ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 2: Ping the mybridge02 by its name, And here we will be able to connect. This is what we call DNS resolution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4p7sq2cp9m0gam6f5wr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4p7sq2cp9m0gam6f5wr3.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step3: If we try to do the same with the previous containers that we created with the default bridge network(&lt;strong&gt;&lt;em&gt;bridge01&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;bridge02&lt;/em&gt;&lt;/strong&gt;). We will not able to ping with the name defined.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F70qohotjpnbera7mr4tj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F70qohotjpnbera7mr4tj.png" alt="mybridgeconnectping"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also define the custom options for your network, which will give us more feasibility to customize with our use-case.&lt;/p&gt;

&lt;p&gt;Like in user-defined network we don't have defined any options yet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9jrz1cuno99ue6s5erv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9jrz1cuno99ue6s5erv.png" alt="optionmybridge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, we can define options like we have in default bridge network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3g9f65k2iyvacbrnzxm0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3g9f65k2iyvacbrnzxm0.png" alt="optionbridge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Host Network
&lt;/h3&gt;

&lt;p&gt;This driver removes the network isolation between the docker host and the docker containers to use the host’s networking directly.&lt;br&gt;
For instance, if you run a container that binds to port 80 and you use host networking, the container’s application will be available on port 80 on the host’s IP address.&lt;/p&gt;

&lt;p&gt;So, now lets see how host network removes isolation between the docker host and the docker containers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step1: We will create a &lt;strong&gt;&lt;em&gt;myhostdemo1&lt;/em&gt;&lt;/strong&gt; container having host network and will install necessary packages.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker network &lt;span class="nb"&gt;ls
&lt;/span&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; myhostdemo1 &lt;span class="nt"&gt;--network&lt;/span&gt; host ubuntu
docker container &lt;span class="nb"&gt;exec&lt;/span&gt;  &lt;span class="nt"&gt;-it&lt;/span&gt; myhostdemo1 bash
apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install &lt;/span&gt;net-tools &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install &lt;/span&gt;iputils-ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fysjshqd3tyj0cb3btiu3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fysjshqd3tyj0cb3btiu3.png" alt="myhostdemo1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step2: Now we will install and start nginx on the container &lt;strong&gt;&lt;em&gt;bridge01&lt;/em&gt;&lt;/strong&gt;, that we had already created above with the bridge network.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container &lt;span class="nb"&gt;exec&lt;/span&gt;  &lt;span class="nt"&gt;-it&lt;/span&gt; bridge01 bash
netstat &lt;span class="nt"&gt;-ntlp&lt;/span&gt;
apt &lt;span class="nb"&gt;install &lt;/span&gt;nginx
/etc/init.d/nginx start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuswk92vcikme0711csp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuswk92vcikme0711csp.png" alt="bridgengix"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 3: If we exit the container and try to find that nginx host address. As, it is bridge network we will not able to see it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0j2c3ph4bc86ks0qxot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq0j2c3ph4bc86ks0qxot.png" alt="outsidebridge"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step4: If we do the same with myhostdemo01. Installing and starting the nginx server, We will see that host address is reflecting outside the container as-well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5zvow9n5ue1mr7hwfaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5zvow9n5ue1mr7hwfaq.png" alt="outsidehostdemo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, host network container can connect to all the docker containers internal container network drivers as-well external containers network drivers.&lt;/p&gt;

&lt;p&gt;you can check it out by &lt;strong&gt;&lt;em&gt;ifconfig&lt;/em&gt;&lt;/strong&gt; in the host network container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffvsumb60y68144czb0hh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffvsumb60y68144czb0hh.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  None Network
&lt;/h3&gt;

&lt;p&gt;If you want to completely disable the networking stack on a container, you can use the none network.&lt;br&gt;
This mode will not configure any IP for the container and doesn’t have any access to the external network as well as for other containers.&lt;br&gt;
Eg. Virus affect testing&lt;/p&gt;

&lt;p&gt;Demo:&lt;br&gt;
Created one none network container and trying to ping &lt;em&gt;google.com&lt;/em&gt; but we are not able to ping.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsfhmvgacgu85uzow7en.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsfhmvgacgu85uzow7en.png" alt="nonenetwork"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Publishing Exposed Ports of Container
&lt;/h3&gt;

&lt;p&gt;We were discussing an approach to publishing container port to host.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; webserver &lt;span class="nt"&gt;-p&lt;/span&gt; 80:80 nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is also referred to as a publish list as it publishes the only a list of the port specified.&lt;br&gt;
There is also a second approach to publish all the exposed ports of the container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; webserver &lt;span class="nt"&gt;-P&lt;/span&gt; nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is also referred to as a publish all.&lt;br&gt;
In this approach, all exposed ports are published to random ports of the host.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46g0bc1z80pkvklfd3px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F46g0bc1z80pkvklfd3px.png" alt="example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Legacy Approach for Linking Containers
&lt;/h3&gt;

&lt;p&gt;Before the Docker networks feature, you could use the Docker link feature to allow containers to&lt;br&gt;
discover each other and securely transfer information about one container to another container.&lt;br&gt;
The --link flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need&lt;br&gt;
to continue using it, we recommend that you use user-defined networks to facilitate communication&lt;br&gt;
between two containers instead of using --link&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step1: Created a container &lt;strong&gt;&lt;em&gt;container01&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k80ex71qzrwqt2gedbl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9k80ex71qzrwqt2gedbl.png" alt="step1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step2: Create a new container linking to the above launched container.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--link&lt;/span&gt; container01:container &lt;span class="nt"&gt;--name&lt;/span&gt; container02 busybox sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxlu4wknl763rec5idc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxlu4wknl763rec5idc1.png" alt="step2linking"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step3: on login to &lt;strong&gt;&lt;em&gt;container02&lt;/em&gt;&lt;/strong&gt; and pinging &lt;strong&gt;&lt;em&gt;container01&lt;/em&gt;&lt;/strong&gt;, we are able to ping&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpvri38ukl4o4ysqrbhd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzpvri38ukl4o4ysqrbhd.png" alt="step3ping"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step4: To check the link, you can cat the &lt;em&gt;/etc/hosts&lt;/em&gt; file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu0apjhhh3dl4ao0ia2g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyu0apjhhh3dl4ao0ia2g.png" alt="step4link"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Official Docker&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/docker-certified-associate/" rel="noopener noreferrer"&gt;Udemy Course&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora" rel="noopener noreferrer"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/image-creation-management-and-registry-part-2-514n"&gt;Prev: Image Creation, Management, and Registry(Part 2)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>linux</category>
      <category>microservices</category>
      <category>networking</category>
    </item>
    <item>
      <title>Image Creation, Management, and Registry(Part 2)</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Fri, 24 Sep 2021 12:20:03 +0000</pubDate>
      <link>https://dev.to/dporwal/image-creation-management-and-registry-part-2-514n</link>
      <guid>https://dev.to/dporwal/image-creation-management-and-registry-part-2-514n</guid>
      <description>&lt;h3&gt;
  
  
  Tagging Docker Images
&lt;/h3&gt;

&lt;p&gt;Docker tags convey useful information about a specific image version/variant.&lt;/p&gt;

&lt;p&gt;They are aliases to the ID of your image which often look like this: 8f5487c8b942&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Assigning tag while building image&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; demo:v1 &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F66oevbn09oar0jucqwfi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F66oevbn09oar0jucqwfi.png" alt="tagwhilebuilding"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Assigning tag if no tag default&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Lets build a image without tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9fdul4imevpfqv4fwok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9fdul4imevpfqv4fwok.png" alt="imagewithouttag"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets assign tag to the existing image without tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker tag adc07a47930e demo:v2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9cld0l6hi2x6ppebzl19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9cld0l6hi2x6ppebzl19.png" alt="tagtonontagimage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;tag for existing tag of the image&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This will create another image with the same IMAGE ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker tag demo:v2 demo2:v3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb256kouqt0fqyxa6f2p1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb256kouqt0fqyxa6f2p1.png" alt="existingtagofimage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Commit
&lt;/h3&gt;

&lt;p&gt;Whenever you make changes inside the container, it can be useful to commit a container’s file changes or settings into a new image.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;By default, the container being committed and its processes will be paused while the image is committed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker container commit CONTAINER-ID myimage01
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Created a container containing context01.txt file in root directory.&lt;br&gt;
Then committed the container to the images and then creating another container from the same image, where we can see the same file/changes made present.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8pi3p9ioln0dpubjg8np.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8pi3p9ioln0dpubjg8np.png" alt="imagecomitting"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also define the Commands while committing the images from the containers.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;em&gt;--change&lt;/em&gt;&lt;/strong&gt; option will apply Dockerfile instructions to the image that is created. &lt;/p&gt;

&lt;p&gt;Supported Dockerfile instructions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CMD | ENTRYPOINT | ENV | EXPOSE&lt;/li&gt;
&lt;li&gt;LABEL | ONBUILD | USER | VOLUME | WORKDIR&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container commit &lt;span class="nt"&gt;--change&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'CMD ["ash"]'&lt;/span&gt; modified-container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3tbq76wfliek4up6a5mn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3tbq76wfliek4up6a5mn.png" alt="commandcommit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Image Layers
&lt;/h3&gt;

&lt;p&gt;A Docker image is built up from a series of layers. &lt;br&gt;
Each layer represents an instruction in the image’s Dockerfile.&lt;/p&gt;

&lt;p&gt;Here is the best resource I found for the presentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z78h3fi0c3xzo6gde3k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z78h3fi0c3xzo6gde3k.png" alt="Docker Layer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As, the container have the R/W layer a top layer which is connected with the base image.&lt;br&gt;
OR we can say that one base image is connected to different containers by Writable layer.&lt;/p&gt;

&lt;p&gt;Lets, see some scenarios. Will build a docker image using dockerfile and will check the layers.&lt;/p&gt;

&lt;p&gt;Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ubuntu&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/root/file1.txt &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/root/file2.txt &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Command to check the layers of the image, where &lt;em&gt;layerdemo01&lt;/em&gt; is the image name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image &lt;span class="nb"&gt;history &lt;/span&gt;layerdemo1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below Screenshot clearly shows how 2 layers are of same volume, as they are not adding the volume of previous layer. Every layer has its separate size according to the command or the changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk5v63hvqjy8xk5e0l00k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk5v63hvqjy8xk5e0l00k.png" alt="layerdemo1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, lets try to remove these files and I found that 2 layers were created with &lt;em&gt;0B&lt;/em&gt; but the image still contains the same &lt;em&gt;282MB&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So, Basically here we have 5 layers.&lt;br&gt;
Layer1 -&amp;gt; FROM Ubuntu&lt;br&gt;
Layer2 -&amp;gt; RUN dd if=/dev/zero of=/root/file1.txt bs=1M count=100&lt;br&gt;
Layer3 -&amp;gt; RUN dd if=/dev/zero of=/root/file2.txt bs=1M count=100&lt;br&gt;
Layer4 -&amp;gt; RUN rm -f /root/file1.txt&lt;br&gt;
Layer5 -&amp;gt; RUN rm -f /root/file2.txt&lt;/p&gt;

&lt;p&gt;Here Only Layer4 and Layer5 is dealing with the removing of those files, but the file are still there in Layer3 and Layer2.&lt;br&gt;
That is the reason image still have the same volume.&lt;/p&gt;

&lt;p&gt;Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ubuntu&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/root/file1.txt &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/root/file2.txt &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /root/file1.txt
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /root/file2.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi87878a7umfaimy78ele.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi87878a7umfaimy78ele.png" alt="layerdemo2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the requirement where we need to remove the files after creation, we can use &lt;strong&gt;&lt;em&gt;&amp;amp;&amp;amp;&lt;/em&gt;&lt;/strong&gt; to run both the command at one-go.&lt;br&gt;
This will conserve the volume of the image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ubuntu&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/root/file1.txt &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /root/file1.txt
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/root/file2.txt &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /root/file2.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Managing Images using CLI
&lt;/h3&gt;

&lt;p&gt;So basically the best practice of using the command for images is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker image &amp;lt;command&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;docker pull ubuntu == docker image pull ubuntu&lt;/li&gt;
&lt;li&gt;docker images      == docker image ls&lt;/li&gt;
&lt;li&gt;docker image build&lt;/li&gt;
&lt;li&gt;docker image history&lt;/li&gt;
&lt;li&gt;docker image import&lt;/li&gt;
&lt;li&gt;docker image inspect&lt;/li&gt;
&lt;li&gt;docker image load&lt;/li&gt;
&lt;li&gt;docker image prune&lt;/li&gt;
&lt;li&gt;docker image push&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi3328zrmkkk4ha6w2dxh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi3328zrmkkk4ha6w2dxh.png" alt="dockerImageCLI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspecting Docker Images
&lt;/h3&gt;

&lt;p&gt;A Docker Image contains lots of information, some of these  include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creation Date&lt;/li&gt;
&lt;li&gt;Command&lt;/li&gt;
&lt;li&gt;Environment Variables&lt;/li&gt;
&lt;li&gt;Architecture&lt;/li&gt;
&lt;li&gt;OS&lt;/li&gt;
&lt;li&gt;Size&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;docker image inspect command allows us to see all the information associated with a docker image.&lt;/p&gt;

&lt;p&gt;Suppose we need to get the particular field from the inspect data.&lt;br&gt;
e.g &lt;em&gt;Hostname&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;we can use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image inspect ubuntu | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s1"&gt;'Hostname'&lt;/span&gt;
docker image inspect ubuntu &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{{.Id}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are certain things that have parent child details. Like, ContainerConfig have Hostname, Domainname etc.&lt;br&gt;
But, this will only gives the values not the key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image inspect ubuntu &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{{.ContainerConfig}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want the key and value both.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image inspect ubuntu &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{{json .ContainerConfig}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you just want the hostname value you can use below caommand to filter out the information from the inspect data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image inspect ubuntu &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{{.ContainerConfig.Hostname}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhuttfah416t7y0oo259a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhuttfah416t7y0oo259a.png" alt="imageInspect"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Image prune
&lt;/h3&gt;

&lt;p&gt;Docker image prune command allows us to clean up unused images.&lt;br&gt;
By default, the below command will only clean up dangling images.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Dangling Images = Image without Tags and Image not referenced by any container&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To prune all the images that has no container refrenced, we can use below commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image prune &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to remove all the images only which don't have tag associated, you can use below commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image prune
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before Prune we had these many images.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp858p1yrkhbqig7x6m57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp858p1yrkhbqig7x6m57.png" alt="before prune"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After running prune command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufr24srx8nbityzmgx42.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufr24srx8nbityzmgx42.png" alt="after prune"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those images got removed which were not referenced to the container. &lt;/p&gt;

&lt;p&gt;Here is the below command the image without the tag ( &lt;em&gt;&lt;/em&gt; ) tag which is a Dangling image, but it can't be prune because it has containers associated.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4k9ilj35snt15x8e1vox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4k9ilj35snt15x8e1vox.png" alt="imageprune"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Flattening Docker Images
&lt;/h3&gt;

&lt;p&gt;Modifying Image in a single Layer or specific Layer.&lt;/p&gt;

&lt;p&gt;As we know ubuntu has many layers. So, to merge all layers to the single layer. There is one approach that to,&lt;br&gt;
&lt;em&gt;Import and Export to a container&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;export &lt;/span&gt;myubuntu &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; myubuntudemo.tar
&lt;span class="nb"&gt;cat &lt;/span&gt;myubuntudemo.tar | docker import - myubuntu:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzb563g3p1e8cunng1dyj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzb563g3p1e8cunng1dyj.png" alt="layerscompress"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Building Docker Registry
&lt;/h3&gt;

&lt;p&gt;A Registry a stateless, highly scalable server-side application that stores and lets you distribute Docker images.&lt;/p&gt;

&lt;p&gt;Docker Hub is the simplest example that all of us must have used.&lt;/p&gt;

&lt;p&gt;There are various types of registry available, which includes:&lt;/p&gt;

&lt;p&gt;Docker Registry&lt;br&gt;
Docker Trusted Registry&lt;br&gt;
Private Repository (AWS ECR)&lt;br&gt;
Docker Hub&lt;/p&gt;

&lt;p&gt;To push the image to a central registry like DockerHub, there are three steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Authenticate your Docker client to the Docker Registry
 Refrence for setting up Docker Registry
 &lt;a href="https://hub.docker.com/_/registry/" rel="noopener noreferrer"&gt;https://hub.docker.com/_/registry/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 5000:5000 &lt;span class="nt"&gt;--restart&lt;/span&gt; always &lt;span class="nt"&gt;--name&lt;/span&gt; registry registry:2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0gj55o4pybeg22bgaei5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0gj55o4pybeg22bgaei5.png" alt="setupdockerregistry"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2. Tag Docker Image with Registry Repository and optional image tag.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker tag myubuntu:latest localhost:5000/myubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;3. Push Image using docker push command
To push the docker image to the &lt;strong&gt;&lt;em&gt;AWS ECR&lt;/em&gt;&lt;/strong&gt;.
Refrence: 
&lt;a href="https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; docker push localhost:5000/myubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n9z7p4qfptfv4fe0v6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5n9z7p4qfptfv4fe0v6h.png" alt="dockerpush"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, lets pull the image from the registry. For that first we need to untag the registy located image and then delete the image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull localhost:5000/myubuntu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffozzdim19jz8ym0mukul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffozzdim19jz8ym0mukul.png" alt="dockerpull"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pushing Docker Image to Docker Hub
&lt;/h3&gt;

&lt;p&gt;I have my account on Docker Hub and created had 1 repository.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03n9xtmtkrod7d94f12m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03n9xtmtkrod7d94f12m.png" alt="dockerhubrepo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, first we will login to the docker hub by CLI and then create the tag and push it. Then before pulling the image I have removed the tag to the image and removed all the containers associated to that container and then pull the image from the Docker Hub Repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker login
docker tag busybox deepakporwal95/mydemo:v1
docker push deepakporwal95/mydemo:v1
docker pull deepakporwal95/mydemo:v1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pushing out custom image to docker hub.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ylb4uxcjgn32jrjenrj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ylb4uxcjgn32jrjenrj.png" alt="pushingtodockerhub"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pulling the image from Docker Hub.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqkwsup11b3p6wtwdmn6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqkwsup11b3p6wtwdmn6x.png" alt="PullingdockerImage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Searcing and Filtering Images from Docker Hub
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Search for Busybox image&lt;/td&gt;
&lt;td&gt;docker search busybox&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Search for Busybox image with Max Result of 5&lt;/td&gt;
&lt;td&gt;docker search busybox --limit 5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filter only official images&lt;/td&gt;
&lt;td&gt;docker search --filter is-official=true nginx&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On searching nginx images.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9x2ttuiivlbf9329vnp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9x2ttuiivlbf9329vnp.png" alt="searchnginx"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will limit the number of results.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1rqcoejp597zwc844wmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1rqcoejp597zwc844wmw.png" alt="limit search"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On searching images from Docker Hub we get many results. We can filter those results by three filter supporters.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;stars&lt;/li&gt;
&lt;li&gt;is-automated&lt;/li&gt;
&lt;li&gt;is-official
This will bring to us specific required result only.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyjoirsygccneej8ty8b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsyjoirsygccneej8ty8b.png" alt="niginx official"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Moving Images Across Hosts
&lt;/h3&gt;

&lt;p&gt;Suppose we want to send docker image to other hosts or instances from admin box or master server. In this case we save the image as a zip and then transfer that image to host and at last will load that image in the host.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu60rh7uyc7emwd82las5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu60rh7uyc7emwd82las5.png" alt="movingimageaccroos"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Cache in Docker
&lt;/h3&gt;

&lt;p&gt;While building a container or image it uses the cache of each layer which has been already been there.&lt;/p&gt;

&lt;p&gt;Here is the Dockerfile and requirements.txt details that we will be using for this usecase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Dockerfile&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.7-slim-buster&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--quiet&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt;&lt;span class="s"&gt; ["python", "server.py"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;requirements.txt&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;certifi==2018.8.24
chardet==3.0.4
Click==7.0
cycler==0.10.0
decorator==4.3.0
defusedxml==0.5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ferjzx6gbjfrly9755ncz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ferjzx6gbjfrly9755ncz.png" alt="Requirements"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the commands that will be using to build the images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; without-cache &lt;span class="nb"&gt;.&lt;/span&gt;
docker build &lt;span class="nt"&gt;-t&lt;/span&gt; with-cache &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;without cache&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2zo5xp70bl1iylv8ux7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2zo5xp70bl1iylv8ux7.png" alt="withoutcache"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;with cache&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tibdgqoxq7027wqohda.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tibdgqoxq7027wqohda.png" alt="with cache"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Official Docker&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/docker-certified-associate/" rel="noopener noreferrer"&gt;Udemy Course&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora" rel="noopener noreferrer"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/image-creation-management-and-registry-part-1-pk9"&gt;Prev: Image Creation, Management, and Registry(Part 1)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/docker-networking-5ef0"&gt;Next: Docker Networking&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>linux</category>
      <category>devops</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Image Creation, Management, and Registry(Part 1)</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Sun, 12 Sep 2021 12:35:35 +0000</pubDate>
      <link>https://dev.to/dporwal/image-creation-management-and-registry-part-1-pk9</link>
      <guid>https://dev.to/dporwal/image-creation-management-and-registry-part-1-pk9</guid>
      <description>&lt;h3&gt;
  
  
  Working with Docker Images
&lt;/h3&gt;

&lt;p&gt;Every Docker container is based on an image.&lt;/p&gt;

&lt;p&gt;Till now we have been using images that were created by others and available in Docker Hub.&lt;/p&gt;

&lt;p&gt;Docker can build images automatically by reading the instructions from a Dockerfile&lt;/p&gt;

&lt;p&gt;A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7yjvsd1903ntc4oar2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc7yjvsd1903ntc4oar2r.png" alt="Dockerfile build"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview of Dockerfile
&lt;/h3&gt;

&lt;p&gt;Basic format of Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; busybox&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; cat.txt&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt;&lt;span class="s"&gt; add.txt&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt;&lt;span class="s"&gt; compress.tar.gz /tmp&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["sh"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A Dockerfile must start with a FROM instruction.&lt;br&gt;
The FROM instruction specifies the Base Image from which you are building.&lt;/p&gt;

&lt;p&gt;There are multiple INSTRUCTIONS that are available in Dockerfile, some of these include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  FROM&lt;/li&gt;
&lt;li&gt;  RUN&lt;/li&gt;
&lt;li&gt;  CMD&lt;/li&gt;
&lt;li&gt;LABEL&lt;/li&gt;
&lt;li&gt;EXPOSE&lt;/li&gt;
&lt;li&gt;ENV&lt;/li&gt;
&lt;li&gt;ADD&lt;/li&gt;
&lt;li&gt;COPY&lt;/li&gt;
&lt;li&gt;ENTRYPOINT&lt;/li&gt;
&lt;li&gt;VOLUME&lt;/li&gt;
&lt;li&gt;USER&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many more....&lt;/p&gt;
&lt;h3&gt;
  
  
  COPY vs ADD Instruction
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;COPY&lt;/em&gt; and &lt;em&gt;ADD&lt;/em&gt; are both Dockerfile instructions that serve similar purposes.&lt;/p&gt;

&lt;p&gt;They let you copy files from a specific location into a Docker image.&lt;/p&gt;
&lt;h4&gt;
  
  
  Difference between COPY and ADD
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;COPY&lt;/em&gt;&lt;/strong&gt; takes in an src and destination. It only lets you copy in a local file or directory from your host&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;ADD&lt;/em&gt;&lt;/strong&gt; lets you do that too, but it also supports 2 other sources.&lt;/p&gt;

&lt;p&gt;First, you can use a URL instead of a local file/directory. Secondly, you can extract a tar file from the source directly into the destination.&lt;/p&gt;
&lt;h4&gt;
  
  
  Use WGET/CURL wherever possible
&lt;/h4&gt;

&lt;p&gt;Using ADD to fetch packages from remote URLs is strongly discouraged; you should use curl or wget instead.&lt;/p&gt;

&lt;p&gt;This will execute all the lines repeatedly, will execute everytime same file. So, its not a good practice&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;ADD&lt;/span&gt;&lt;span class="s"&gt; http://example.com/big.tar.xz /usr/src/things/&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-xJf&lt;/span&gt; /usr/src/things/big.tar.xz &lt;span class="nt"&gt;-C&lt;/span&gt; /usr/src/things
&lt;span class="k"&gt;RUN &lt;/span&gt;make &lt;span class="nt"&gt;-C&lt;/span&gt; /usr/src/things all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will not create unnecessary files and will make a sequence, which will deal with only file file and then process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; /usr/src/things &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; curl &lt;span class="nt"&gt;-SL&lt;/span&gt; http://example.com/big.tar.xz &lt;span class="se"&gt;\
&lt;/span&gt;    | &lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-xJC&lt;/span&gt; /usr/src/things &lt;span class="se"&gt;\
&lt;/span&gt;    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; make &lt;span class="nt"&gt;-C&lt;/span&gt; /usr/src/things all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets have a demo to show you how &lt;strong&gt;&lt;em&gt;ADD&lt;/em&gt;&lt;/strong&gt; work.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a Compressed file&lt;/li&gt;
&lt;li&gt;Create a Dockerfile and define the file to copy from to destination&lt;/li&gt;
&lt;li&gt;Run that Dockerfile&lt;/li&gt;
&lt;li&gt;Verify the Output on the Destination directory.&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  Step 1. Create Compressed file
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;root@dporwal-docker:~# &lt;span class="nb"&gt;touch &lt;/span&gt;compress.txt
root@dporwal-docker:~# &lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-czvf&lt;/span&gt; compress.tar.gz compress.txt 
root@dporwal-docker:~# docker build &lt;span class="nt"&gt;-t&lt;/span&gt; demobusybox &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd98v9ueu25jxcgef7mwh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd98v9ueu25jxcgef7mwh.png" alt="createCompressedfile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2. Create a Dockerfile and define the file to copy from to destination
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vi Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;dockerfile1&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fab6hu6futbb956xb4i9l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fab6hu6futbb956xb4i9l.png" alt="Dockerfile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3. Run that Dockerfile
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker build &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4. Verify the Output on the Destination directory.
&lt;/h4&gt;

&lt;p&gt;Start the container that is build by DOcerfile&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2lurryux6f8l8bsmh28.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2lurryux6f8l8bsmh28.png" alt="verifyOutput"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;EXPOSE&lt;/em&gt;&lt;/strong&gt; Instruction
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;EXPOSE&lt;/em&gt; instruction informs Docker that the container listens on the specified network ports at runtime and it does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published.&lt;/p&gt;

&lt;p&gt;In above dockerfile1 you can see the scenario where person will not be able to get the port it should intends to publish because of not using &lt;em&gt;EXPOSE&lt;/em&gt; command&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgksefea5yg8sf8ageiby.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgksefea5yg8sf8ageiby.png" alt="inaccesible"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, now we will use this &lt;em&gt;EXPOSE&lt;/em&gt; command Dockerfile.&lt;/p&gt;

&lt;p&gt;Here I'm creating a dockerfile, which will launch nginx server on port 9080.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ubuntu:latest&lt;/span&gt;
&lt;span class="k"&gt;LABEL&lt;/span&gt;&lt;span class="s"&gt; version="0.0.1"&lt;/span&gt;
&lt;span class="k"&gt;LABEL&lt;/span&gt;&lt;span class="s"&gt; maintainer="porwal.deepak2000@gmail.com"&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get upgrade &lt;span class="nt"&gt;-y&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;nginx &lt;span class="nt"&gt;-y&lt;/span&gt; 

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 9080&lt;/span&gt;

&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["nginx", "-g", "daemon off;"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my initial environment of my docker server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmx2m576mf65fl7otafjv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmx2m576mf65fl7otafjv.png" alt="inital stage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will run below commands to build the custom image &lt;em&gt;exposedemo&lt;/em&gt; with tag 0.0.1&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image build &lt;span class="nt"&gt;--tag&lt;/span&gt; exposedemo:0.0.1 &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyojc8oiv2020c6qz60ee.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyojc8oiv2020c6qz60ee.png" alt="build exposedemo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here we will create a container from the &lt;em&gt;exposedemo&lt;/em&gt; image we build.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; exposedemo:0.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in this image you can see in yellow box the container is running on port &lt;strong&gt;9080&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdwhpk4q7sjymy1mzado.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsdwhpk4q7sjymy1mzado.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to Verify you can also use this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect exposedemo:0.0.1 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6toe473r96zikg6g0nka.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6toe473r96zikg6g0nka.png" alt="verifyexpose"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;HEALTHCHECK&lt;/em&gt;&lt;/strong&gt; Instruction
&lt;/h3&gt;

&lt;p&gt;HEALTHCHECK instruction Docker allows us to tell the platform on how to test that our application is healthy.&lt;/p&gt;

&lt;p&gt;When Docker starts a container, it monitors the process that the container runs. If the process ends, the container exits. &lt;/p&gt;

&lt;p&gt;That's just a basic check and does not necessarily tell the detail about the application.&lt;/p&gt;

&lt;p&gt;We can specify certain options before the CMD operation, these includes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;HEALTHCHECK &lt;span class="nt"&gt;--interval&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;5s CMD ping &lt;span class="nt"&gt;-c&lt;/span&gt; 1 172.17.0.2

&lt;span class="nt"&gt;--interval&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DURATION &lt;span class="o"&gt;(&lt;/span&gt;default: 30s&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nt"&gt;--timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DURATION &lt;span class="o"&gt;(&lt;/span&gt;default: 30s&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nt"&gt;--start-period&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;DURATION &lt;span class="o"&gt;(&lt;/span&gt;default: 0s&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nt"&gt;--retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;N &lt;span class="o"&gt;(&lt;/span&gt;default: 3&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets create a container &lt;em&gt;demohealthcheck&lt;/em&gt; which we will be using to check the connection, and will create another container &lt;em&gt;monitor&lt;/em&gt; where we will implement &lt;strong&gt;HEALTCHECK&lt;/strong&gt; command by checking connection with &lt;em&gt;demohealthcheck&lt;/em&gt; container.&lt;/p&gt;

&lt;p&gt;Commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; demohealthcheck busybox sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will get the IP Address of this container to connect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect demohealthcheck 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38w2tq1ce9p7wqzk0fcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38w2tq1ce9p7wqzk0fcw.png" alt="demohealthcheck"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets create dockerfile and implement &lt;em&gt;HEALTHCHECK&lt;/em&gt; command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; demohealthcheck&lt;/span&gt;
&lt;span class="k"&gt;HEALTHCHECK&lt;/span&gt;&lt;span class="s"&gt; --interval=5s CMD ping -c 1 172.17.0.3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvdi1xnc4altxdu0qidy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqvdi1xnc4altxdu0qidy.png" alt="healthcheckdockerfile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Building image and container from the above docker file and check the connection.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febaey6ht7kixse1o4w1c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Febaey6ht7kixse1o4w1c.png" alt="monitoringimage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also check the HEALTHCHECK Logs by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker inspect monitor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xjk9as718m2g4jvfnkl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0xjk9as718m2g4jvfnkl.png" alt="inspectmonitor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;if &lt;em&gt;ExitCode: 1&lt;/em&gt; then, there is something wrong with container.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Exit Code&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0: Success&lt;/td&gt;
&lt;td&gt;the container is healthy and ready to use&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1: Failure&lt;/td&gt;
&lt;td&gt;the container is not working correctly&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2: Reserved&lt;/td&gt;
&lt;td&gt;do not use the exit code&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We can also use HealthCheck commands while building the container.&lt;br&gt;
like below we are using &lt;em&gt;--health-cmd&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; tmp &lt;span class="nt"&gt;--health-cmd&lt;/span&gt; &lt;span class="s2"&gt;"curl -f http://localhost"&lt;/span&gt; busybox sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and we will see that container is unhealthy.On doing &lt;em&gt;docker inspect tmp&lt;/em&gt; we found that curl command is not found.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jajt8oig92y34njgfcl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jajt8oig92y34njgfcl.png" alt="unhealthycontainer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm750agsusljqeqsjb3v3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm750agsusljqeqsjb3v3.png" alt="curlcommandnotfound"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we will remove this container and will try to check the container after every 5 sec and it will retry 1 time on failure.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;you can try below command and let me know in discussion if you are good to do so.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; tmp &lt;span class="nt"&gt;--health-cmd&lt;/span&gt; &lt;span class="s2"&gt;"curl -f http://localhost"&lt;/span&gt; &lt;span class="nt"&gt;--health-interval&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;5s &lt;span class="nt"&gt;--health-retries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 busybox sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for more commands you can check:&lt;br&gt;
&lt;a href="https://docs.docker.com/engine/reference/run/#healthcheck" rel="noopener noreferrer"&gt;https://docs.docker.com/engine/reference/run/#healthcheck&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Dockerfile &lt;strong&gt;&lt;em&gt;ENTRYPOINT&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The best use for ENTRYPOINT is to set the image’s main command&lt;br&gt;
ENTRYPOINT doesn’t allow you to override the command.&lt;br&gt;
It is important to understand the distinction between CMD and ENTRYPOINT.&lt;/p&gt;

&lt;p&gt;As, CMD command in Dockerfile can be overridden by runtime command. Whereas ENTRYPOINT command will append to the given command given at runtime.&lt;/p&gt;

&lt;p&gt;Sample Code Snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ubuntu&lt;/span&gt;
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt;&lt;span class="s"&gt; ["top", "-b"]&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["-c"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw72pz1vjqwl9zkvubvq5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw72pz1vjqwl9zkvubvq5.png" alt="CMD Command"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frksyf36qhynl292sxxze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frksyf36qhynl292sxxze.png" alt="entrypoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;WORKDIR&lt;/em&gt;&lt;/strong&gt; Instruction
&lt;/h3&gt;

&lt;p&gt;The &lt;em&gt;WORKDIR&lt;/em&gt; instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; busybox&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; /root/demo
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /root/demo&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;dporwal.txt
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ['/bin/sh']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytw4hdyzpm06j196jswo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fytw4hdyzpm06j196jswo.png" alt="workdircmd"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The WORKDIR instruction can be used multiple times in a Dockerfile&lt;/p&gt;

&lt;p&gt;Sample Snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WORKDIR /a
WORKDIR b
WORKDIR c
RUN pwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output = /a/b/c&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr14v8lg88t71auoob9aw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr14v8lg88t71auoob9aw.png" alt="Exampleabove snippet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;ENV&lt;/em&gt;&lt;/strong&gt; Instruction
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Passing as argument during run time.&lt;/em&gt;&lt;br&gt;
The ENV instruction sets the environment variable  to the value .&lt;/p&gt;

&lt;p&gt;You can use -e, --env, and --env-file flags to set simple environment variables in the container you’re running or overwrite variables that are defined in the Dockerfile of the image you’re running.&lt;/p&gt;

&lt;p&gt;Example Snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;VAR1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;value1 &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;VAR2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;value2 ubuntu &lt;span class="nb"&gt;env&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;VAR

Eg.
docker run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; env01 &lt;span class="nt"&gt;--env&lt;/span&gt; &lt;span class="nv"&gt;USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;USERADMIN busybox sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi4f4nrbo4m11dq8ncv03.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi4f4nrbo4m11dq8ncv03.png" alt="envcommand"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;implementation of ENV in dockerfile&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Example Snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; busybox&lt;/span&gt;
&lt;span class="k"&gt;ENV&lt;/span&gt;&lt;span class="s"&gt; NGINX 1.2&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;web-&lt;span class="nv"&gt;$NGINX&lt;/span&gt;.txt
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["/bin/sh"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xn7jyl2p6agf6wfwc0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4xn7jyl2p6agf6wfwc0q.png" alt="envdockerfile"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Official Docker&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/docker-certified-associate/" rel="noopener noreferrer"&gt;Udemy Course&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora" rel="noopener noreferrer"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/docker-20kl"&gt;Prev: Getting Started with Docker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/image-creation-management-and-registry-part-2-514n"&gt;Next: Image Creation, Management, and Registry(Part 2)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>linux</category>
      <category>devops</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Getting Started With Docker</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Mon, 06 Sep 2021 12:28:37 +0000</pubDate>
      <link>https://dev.to/dporwal/docker-20kl</link>
      <guid>https://dev.to/dporwal/docker-20kl</guid>
      <description>&lt;h3&gt;
  
  
  Introduction to Docker
&lt;/h3&gt;

&lt;p&gt;Docker is a technology designed to make it easier to create, deploy, and run applications by using containers. Docker is an open platform, once we build a docker container, we can run it anywhere, say it windows, Linux, mac whether on a laptop, data center, or in the cloud. It follows the build once, run anywhere approach.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma2mylc0ri1llh5ajlzn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma2mylc0ri1llh5ajlzn.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Docker
&lt;/h3&gt;

&lt;p&gt;I will not be showing you the steps to install docker here.&lt;br&gt;
You can refer this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/whattosay/docker-environment-setup-4hac"&gt;https://dev.to/whattosay/docker-environment-setup-4hac&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Docker works on a wide variety of operating systems, this includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Windows&lt;/li&gt;
&lt;li&gt;Linux&lt;/li&gt;
&lt;li&gt;MAC&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The installation of Docker is pretty straight forward in each one of them.&lt;br&gt;
&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;https://docs.docker.com/get-docker/&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Docker Containers vs Virtual Machines
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Virtual Machine contains the entire Operating System.&lt;/li&gt;
&lt;li&gt;The container uses the resource of the host operating system &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Docker [Image vs Containers]
&lt;/h3&gt;

&lt;p&gt;Docker Image is a file that contains all the necessary dependency and configurations which are required to run an application.&lt;/p&gt;

&lt;p&gt;Docker Containers is basically a running instance of an image.&lt;/p&gt;
&lt;h3&gt;
  
  
  Docker Image Creation and Identification
&lt;/h3&gt;

&lt;p&gt;When you create a Docker container, it is assigned a universally unique identifier (UUID).&lt;/p&gt;

&lt;p&gt;These can help identify the docker container among others.&lt;br&gt;
To help humans, Docker also allows us to supply container names.&lt;br&gt;
By default, if we do not specify the name, docker supplies a randomly-generated name from two words, joined by an underscore&lt;br&gt;
By adding &lt;em&gt;--name=meaningful_name&lt;/em&gt; argument during the docker run command, we can specify our own name to the containers&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating nginx Docker image and getting IPConfig
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker pull nginx
&lt;span class="nv"&gt;$ &lt;/span&gt;docker images
&lt;span class="nv"&gt;$ &lt;/span&gt;docker run 
&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-dt&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 80:80 nginx
&lt;span class="nv"&gt;$ &lt;/span&gt;docker ps
&lt;span class="nv"&gt;$ &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;net-tools
&lt;span class="nv"&gt;$ &lt;/span&gt;ifconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here is a Snapshot for your reference, Do click on image to see it properly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiyrue88mi9zof1jzhxtj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiyrue88mi9zof1jzhxtj.png" alt="Docker Nginx"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To check the nginx server&lt;br&gt;
Goto: &lt;a href="http://165.22.212.229:80" rel="noopener noreferrer"&gt;http://165.22.212.229:80&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here &lt;em&gt;165.22.212.229&lt;/em&gt; is droplet Public IP and &lt;em&gt;80&lt;/em&gt; is the port on which image has been mapped(&lt;em&gt;docker run -dt -p 80:80 nginx&lt;/em&gt;)&lt;br&gt;
By default Docker containers can make connections to the outside world, but the outside world cannot connect to containers.&lt;br&gt;
If we want containers to accept incoming connections from the world, you will have to bind it to a host port.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i0z0s6g59ypu7ou0snm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9i0z0s6g59ypu7ou0snm.png" alt="nginx"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Port Binding
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker inspect mynginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This command shows the config details of docker container&lt;br&gt;
In below Screenshot first I deleted the container by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;rm &lt;/span&gt;6e80b1835da72da248ae2e2d2b35045c3cd736196159a030f76bd31fb9f16f33
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then did the porting from 8000 --&amp;gt; 80&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; 8000:80 &lt;span class="nt"&gt;--name&lt;/span&gt; mynginx nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vs14tlwnmrb8c5wm7o7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vs14tlwnmrb8c5wm7o7.png" alt="Port Binding"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Attach and Detached Mode
&lt;/h3&gt;

&lt;p&gt;When we start a docker container, we need to decide if we want to run in a default foreground mode or the detached mode.&lt;br&gt;
You may want to use this if you want a container to run but do not want to view and follow all its output.&lt;/p&gt;

&lt;p&gt;Detached Mode &lt;em&gt;-d&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; detached &lt;span class="nt"&gt;-p&lt;/span&gt; 8081:80 nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F310ycuyfz875dbx8hc09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F310ycuyfz875dbx8hc09.png" alt="detached"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Removing Docker Containers
&lt;/h3&gt;

&lt;p&gt;Docker containers can be removed with the help of docker container &lt;em&gt;rm&lt;/em&gt; command.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Remove single container&lt;/td&gt;
&lt;td&gt;docker container rm CONTAINER&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stop all the containers&lt;/td&gt;
&lt;td&gt;docker container stop $(docker container ls -aq)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Remove all the containers&lt;/td&gt;
&lt;td&gt;docker container rm $(docker container ls -aq)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3k2rkyxxqffp17zvdqr9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3k2rkyxxqffp17zvdqr9.png" alt="Remove Images"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Troubleshooting Issue
&lt;/h4&gt;

&lt;p&gt;While I was removing Image I found that images were running. SO, wasn't able to remove.&lt;br&gt;
Therefore, you can't remove the image until you stop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjrr8iukjlc9vjtmuce1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjrr8iukjlc9vjtmuce1u.png" alt="troubleshooting"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For more commands related to Docker&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://docs.docker.com/engine/reference/commandline/docker/" rel="noopener noreferrer"&gt;https://docs.docker.com/engine/reference/commandline/docker/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The cli commands were then refactored to have the form docker COMMAND SUBCOMMAND, wherein this case the COMMAND is container and the SUBCOMMAND is run&lt;/p&gt;

&lt;p&gt;Older Approach:    docker run &lt;br&gt;
Newer Approach: docker container run&lt;/p&gt;

&lt;p&gt;Both of these approaches will work perfectly. &lt;/p&gt;
&lt;h3&gt;
  
  
  Docker container &lt;strong&gt;&lt;em&gt;exec&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The docker container &lt;em&gt;exec&lt;/em&gt; command runs a new command in a running container.&lt;/p&gt;

&lt;p&gt;The command started using docker exec only runs while the container’s primary process (PID 1) is running, and it is not restarted if the container is restarted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# here are the commands to run the commands inside container from outside &lt;/span&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;docker container &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; dporwalexec netstat &lt;span class="nt"&gt;-ntlp&lt;/span&gt;

&lt;span class="c"&gt;#you can login to the container and run the commands&lt;/span&gt;

root@dporwal-docker:~# docker container &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; dporwalexec bash

&lt;span class="c"&gt;#here you are inside the container with the bash Interactive&lt;/span&gt;
root@c0efbecf71a2:/# /etc/init.d/nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the snapshot of above commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbup8fztwynhk7kw1u6p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzbup8fztwynhk7kw1u6p.png" alt="containerExecute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Importance of the IT flag
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;-it&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Every process that we create in the linux environment , has three open files descriptions, &lt;strong&gt;stdin, stdout, stderr&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;-i&lt;/em&gt;&lt;/strong&gt; --&amp;gt; interactive, keeps stdin open even if not attached&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;-t&lt;/em&gt;&lt;/strong&gt; --&amp;gt; tty, flag allocated a paseudo-TTY&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frpskql70hgctqtl68kub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frpskql70hgctqtl68kub.png" alt="ItFlag"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Default Container Command
&lt;/h3&gt;

&lt;p&gt;Whenever we run a container, a default command executes which typically runs as PID 1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbws7qx59u88ff4c7plj6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbws7qx59u88ff4c7plj6.png" alt="defaultcontainercommand"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can override the default container command by manually specifying the command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; nginx &lt;span class="nb"&gt;sleep &lt;/span&gt;500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above command, the sleep 500 will run as a PID 1 process overriding any default command that would be present in the nginx container.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxx8rfr3ixk7jripvrl76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxx8rfr3ixk7jripvrl76.png" alt="override default"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Restart Docker Policies
&lt;/h3&gt;

&lt;p&gt;By default, Docker containers will not start when they exit or when docker daemon is restarted.&lt;/p&gt;

&lt;p&gt;Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts.&lt;/p&gt;

&lt;p&gt;We can specify the restart policy by using the --restart flag with docker run command&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Flag&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;do not automatically restart the container(the default)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;on-failure&lt;/td&gt;
&lt;td&gt;Restart the container if it exits due to any error, which manifest as a non-zero exit code&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;unless-stopped&lt;/td&gt;
&lt;td&gt;Restart the container unless it is explicitly stopped or Docker itself is stopped or restarted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;always&lt;/td&gt;
&lt;td&gt;Always restart if its stopped&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--restart&lt;/span&gt; unless-stopped nginx

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I have created on nginx container with &lt;em&gt;unless-stopped&lt;/em&gt; restart command.&lt;br&gt;
After restarting Docker service the container should also get start, as it will run &lt;em&gt;restart&lt;/em&gt; command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5700otgjdn6c2jnaylz7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5700otgjdn6c2jnaylz7.png" alt="restartcontainer"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Disk Usage montior docker containers
&lt;/h3&gt;

&lt;p&gt;The docker system &lt;em&gt;df&lt;/em&gt; command displays information regarding the amount of disk space used by the docker daemon.&lt;/p&gt;
&lt;h4&gt;
  
  
  Commands:
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker system &lt;span class="nb"&gt;df&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;docker system &lt;span class="nb"&gt;df&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In the below Snapshot I'm creating 500MB file using command.&lt;br&gt;
I'm not sure about the below mechanism, Do let me know in discussion section if you know anything about this, how it works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bigfile.txt &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1M &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmf4x2lilwx05uf033c62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmf4x2lilwx05uf033c62.png" alt="diskUsage"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove Docker Images
&lt;/h3&gt;

&lt;p&gt;To remove one image at a time, we will use below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker rmi nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To remove all the docker images at once, we will use first to list all the images and then run all the commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker images &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt;
docker rmi &lt;span class="si"&gt;$(&lt;/span&gt;docker images &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzt93dp9d2w4pc7k06hv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkzt93dp9d2w4pc7k06hv.png" alt="remove all images"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;Official Docker&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.udemy.com/course/docker-certified-associate/" rel="noopener noreferrer"&gt;Udemy Course&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credit:&lt;br&gt;
&lt;a href="https://in.linkedin.com/in/zealvora" rel="noopener noreferrer"&gt;Zeal Vora&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/docker-environment-setup-4hac"&gt;Prev: Setting Docker Environment&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/dporwal/image-creation-management-and-registry-part-1-pk9"&gt;Next: Image Creation, Management, and Registry(Part 1)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>linux</category>
      <category>devops</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Docker Environment Setup</title>
      <dc:creator>Deepak Porwal</dc:creator>
      <pubDate>Sun, 05 Sep 2021 21:12:59 +0000</pubDate>
      <link>https://dev.to/dporwal/docker-environment-setup-4hac</link>
      <guid>https://dev.to/dporwal/docker-environment-setup-4hac</guid>
      <description>&lt;h3&gt;
  
  
  * Create DigitalOcean Account
&lt;/h3&gt;

&lt;p&gt;You can use my referral you will get $100 free usage for 3 months.&lt;br&gt;
By clicking below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/?refcode=625e4379d2d4&amp;amp;utm_campaign=Referral_Invite&amp;amp;utm_medium=Referral_Program&amp;amp;utm_source=badge" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fweb-platforms.sfo2.cdn.digitaloceanspaces.com%2FWWW%2FBadge%25201.svg" alt="DigitalOcean Referral Badge"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  * Create a Droplet
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffiim487xmtjxnhgbtq73.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffiim487xmtjxnhgbtq73.png" alt="Create Droplet"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  * Use the following Configuration for Droplet.
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;You have to open image and zoom&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wy1lp0csxsg90k5sf80.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9wy1lp0csxsg90k5sf80.png" alt="Droplet Configuration"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  In case of ssh key generation
&lt;/h4&gt;

&lt;p&gt;Click on &lt;strong&gt;New SSH Key&lt;/strong&gt; as shown in above image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qy1sas185ulhfm767xh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qy1sas185ulhfm767xh.png" alt="DigitOcean SSH Key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And Run these commands in Local System.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ssh-keygen
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /c/Users/&amp;lt;Your User&amp;gt;/.ssh/docker_rsa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75yfjzk39065tssmcctu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75yfjzk39065tssmcctu.png" alt="Local SSH Key Generation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  * Droplet after Creating
&lt;/h3&gt;

&lt;p&gt;In you Project, you will be able to see one droplet.&lt;br&gt;
Where you will get the public IP of that droplet and we will access that using that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnsb7ey85lgz5ikk873vb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnsb7ey85lgz5ikk873vb.png" alt="dropletIP"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  * Login and update Droplet
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; docker_rsa root@165.22.212.229
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj366vs7yqoocnno28zgs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj366vs7yqoocnno28zgs.png" alt="login and update"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After updating kernal, installing docker to the droplet.&lt;br&gt;
Below is specific to Ubuntu&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    apt-transport-https &lt;span class="se"&gt;\&lt;/span&gt;
    ca-certificates &lt;span class="se"&gt;\&lt;/span&gt;
    curl &lt;span class="se"&gt;\&lt;/span&gt;
    gnupg &lt;span class="se"&gt;\&lt;/span&gt;
    lsb-release
&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://download.docker.com/linux/ubuntu/gpg | &lt;span class="nb"&gt;sudo &lt;/span&gt;gpg &lt;span class="nt"&gt;--dearmor&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; /usr/share/keyrings/docker-archive-keyring.gpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we need to install Docker.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s2"&gt;"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;lsb_release &lt;span class="nt"&gt;-cs&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; stable"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/docker.list &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null 

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;docker-ce docker-ce-cli containerd.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verify Docker
&lt;/h3&gt;

&lt;p&gt;To Verify Docker is running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;systemctl status docker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukim3x74bblq1jyrlmxu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fukim3x74bblq1jyrlmxu.png" alt="Docker Verification"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hurray!! you are inside your first Droplet....&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>linux</category>
      <category>cloudskills</category>
    </item>
  </channel>
</rss>
