Home » How to Install and Run a Docker Container on AWS EC2

How to Install and Run a Docker Container on AWS EC2

Install Docker on AWS EC2

Everybody want to deploy micro-services. Docker is the most powerful and popular tool which is help to containerizing application. It is help to deployment faster and more efficient. So, In this blog we will install and run a simple docker container on AWS EC2 instance.

Prerequisites

  • You need AWS management console [ Account]
  • One already running EC2 Instances [ Amazon Linux or Ubuntu]. If you don’t know how to launch instances read this How to create EC2 Instance
  • SSH access to the EC2 Instances.

Step 1: Launch EC2 Instance and Access it using SSH

Step 2: Install Docker on EC2

  • For Amazon Linux
  1. First update the system and Install Docker
  • For Ubuntu Linux

Step 3: Start Docker and Enable it

  • Run the following command on your server to start and enable docker.

Step 4: Add user to Docker Group [Optional]

  • If you want run docker without using sudo, So add your user to the Docker group

Step 5: Run a Docker container

  1. Now, run the simple docker container using the official Nginx image.
  • Pull the Nginx Docker image
  • Now, Run the Nginx container
  1. -d = Run in background
  2. -p 80:80 = Port maps 80 of the container to port 80 of the EC2 instance
  3. –name cloudwithyuvi = give name of the container.
  • Now, verify the container is running or not

Step 7 : Access your container webserver

  • Open your browser and paste your EC2 instance public IP
  • Now, You can see the default Nginx welcome page, it’s mean your container is successfully running.

Step 8: Manage Docker Container

  • If you see all running containers:
  • If you want stop your conatiners:
  • If you want to restart your containers:
  • If you want delete your containers:

Amazing, you have successfully install docker on AWS EC2 instance and deploy Nginx webserver using docker. It is help to deploy and manage application in isolated environments.

10 thoughts on “How to Install and Run a Docker Container on AWS EC2

Leave a Reply

Your email address will not be published. Required fields are marked *