DEV Community

bhaktraj
bhaktraj

Posted on

Docker Install In Ubuntu or on Cloud (AWS provisioning)

Here’s a guide for installing Docker on Ubuntu or provisioning it on AWS:

Install Docker on Ubuntu

  1. Update Package:
sudo apt update
Enter fullscreen mode Exit fullscreen mode
  1. Install Required Packages:
sudo apt-get install ca-certificates curl
Enter fullscreen mode Exit fullscreen mode
  1. Add Docker's official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Enter fullscreen mode Exit fullscreen mode
  1. Add Docker Repository:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Enter fullscreen mode Exit fullscreen mode
  1. Update Package:
sudo apt update
Enter fullscreen mode Exit fullscreen mode
  1. To install the latest version, run:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Enter fullscreen mode Exit fullscreen mode
  1. Verify that the installation is successful or not
docker --version
Enter fullscreen mode Exit fullscreen mode
  1. Or try By run Some Docker Cmd
sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

Script For Install docker in ubuntu
also copy from https://github.com/bhaktraj/dockerinstall/tree/main

#!/bin/bash
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Enter fullscreen mode Exit fullscreen mode

after that verify docker is install or not by run following command:

docker --version
Enter fullscreen mode Exit fullscreen mode

or

sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

Docker Install on AWS Cloud By Provisioning

  1. Provision EC2 Instance:

Launch an EC2 instance with the following:
OS:
Ubuntu (latest LTS version recommended)
Instance Type: t2.micro (for learning) or more for production
Configure security group to allow port 22 (SSH) for remote login

Paste the following Script in user data in advance details block:

pasting script in userdata of advance details block

#!/bin/bash
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Enter fullscreen mode Exit fullscreen mode

And Launch the instance wait for 2 to 5 min after launching then login into instance and verify the docker is install properly or not by command

docker --version

Enter fullscreen mode Exit fullscreen mode

or

sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

Comment for any query

Top comments (0)