<?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: usmanalimaan</title>
    <description>The latest articles on DEV Community by usmanalimaan (@usmanalimaan).</description>
    <link>https://dev.to/usmanalimaan</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%2F513976%2Fb5eb77f4-f622-4531-b0cd-da3b3a0c86a3.jpeg</url>
      <title>DEV Community: usmanalimaan</title>
      <link>https://dev.to/usmanalimaan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/usmanalimaan"/>
    <language>en</language>
    <item>
      <title>How to install and run Docker on AWS EC2</title>
      <dc:creator>usmanalimaan</dc:creator>
      <pubDate>Sat, 22 Jan 2022 16:35:40 +0000</pubDate>
      <link>https://dev.to/usmanalimaan/how-to-install-and-run-docker-on-aws-ec2-bim</link>
      <guid>https://dev.to/usmanalimaan/how-to-install-and-run-docker-on-aws-ec2-bim</guid>
      <description>&lt;p&gt;There are different ways to run docker into AWS cloud but today we will discuss how we can run docker on an AWS EC2 machine. &lt;br&gt;
There could be different scenarios when you are starting with docker but don't have some good local environment or just want to have a good idea running a docker environment on Linux server then you are at right place. &lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisite:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How to create AWS EC2 instance&lt;/li&gt;
&lt;li&gt;How to  SSH into a Linux instance&lt;/li&gt;
&lt;li&gt;What is Nginx web server or Apache HTTP web Server(using its container to show installation)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Creating EC2 instance using Ubuntu 20.04 LTS image
&lt;/h3&gt;

&lt;p&gt;In your AWS account you need to go services section then EC2.&lt;br&gt;
On EC2 dashboard you can see "Launch a virtual machine"&lt;br&gt;
press this button and it will land you on this screen &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XhguwurK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3sa9jikzkvb0ikabph9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XhguwurK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3sa9jikzkvb0ikabph9g.png" alt="chose image while creating ec2 instance" width="880" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can chose your favorite Linux distribution, I am choosing &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;gt; Ubuntu Server 20.04 LTS (HVM), SSD Volume Type - ami-04505e74c0741db8d (64-bit x86) / ami-0b49a4a6e8e22fa16 (64-bit Arm)&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  SSH into Instance
&lt;/h3&gt;

&lt;p&gt;Once instance is created you need to have its Public IP to SSH into this server. In my case&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i mango.pem ubuntu@ec2-3-88-116-37.compute-1.amazonaws.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Installing docker
&lt;/h3&gt;

&lt;p&gt;We will be using apt package manager to install docker engine as describe by the &lt;a href="https://docs.docker.com/engine/install/ubuntu/"&gt;official docker installation documentation&lt;/a&gt;. On this document you can find your own chosen Linux distribution installation guide documentation into left section. &lt;/p&gt;

&lt;h4&gt;
  
  
  Setting up repository
&lt;/h4&gt;

&lt;p&gt;Update the apt package index and install packages to allow apt to use a repository over HTTPS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sudo apt-get update

 sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Add Docker’s official GPG key:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. Learn about nightly and test channels.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list &amp;gt; /dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  According to official doc updating the package manager and installing docker engine
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update &amp;amp;&amp;amp; sudo apt-get install docker-ce docker-ce-cli containerd.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hurrah you have successfully installed docker and you can validate it using following command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker -v
Docker version 20.10.12, build e91ed57
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to install Nginx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo docker container run -d -p 80:80 nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On same machine we can verify the working of this server using curl&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl localhost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if we open 80 port on this instance for public access. we can access it into any browser using Public IP or DNS value.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zl1FbsZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1bc83wcczpra1508lpe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zl1FbsZE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1bc83wcczpra1508lpe.png" alt="Running Nginx on docker" width="880" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>ec2</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
