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.
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.
- How to create AWS EC2 instance
- How to SSH into a Linux instance
- What is Nginx web server or Apache HTTP web Server(using its container to show installation)
You can chose your favorite Linux distribution, I am choosing
> Ubuntu Server 20.04 LTS (HVM), SSD Volume Type - ami-04505e74c0741db8d (64-bit x86) / ami-0b49a4a6e8e22fa16 (64-bit Arm)
Once instance is created you need to have its Public IP to SSH into this server. In my case
ssh -i mango.pem email@example.com
We will be using apt package manager to install docker engine as describe by the official docker installation documentation. On this document you can find your own chosen Linux distribution installation guide documentation into left section.
Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update sudo apt-get install \ ca-certificates \ curl \ gnupg \ lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
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.
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 > /dev/null
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
Hurrah you have successfully installed docker and you can validate it using following command
$ docker -v Docker version 20.10.12, build e91ed57
Now we are ready to install Nginx
sudo docker container run -d -p 80:80 nginx
On same machine we can verify the working of this server using curl