This blog will cover Docker installation and also a mini project about launching a react_django_demo_app
To install Docker on an EC2 Ubuntu instance, you can follow these steps:
Connect to your EC2 instance using SSH. You can use a terminal application such as
ssh
on macOS and Linux or a tool like PuTTY on Windows.Update the package lists for upgrades and new package installations by running the following command:
sudo apt update
Install the necessary packages to allow apt to use packages over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add the Docker GPG key using the following command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Add the Docker repository to the system's software repository list:
echo "deb [arch=amd64 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
Update the package lists again to include the Docker packages:
sudo apt update
Install Docker:
sudo apt install docker-ce docker-ce-cli containerd.io
Docker should now be installed. You can verify the installation by checking the Docker version:
docker --version
By default, Docker requires root privileges to run. If you want to run Docker commands without using
sudo
, you can add your user to thedocker
group:sudo usermod -aG docker $USER
Log out of your SSH session and log in again to apply the group changes.
Now you should have Docker successfully installed on your EC2 Ubuntu instance. You can start using Docker by running Docker commands or pulling Docker images. Remember to use sudo
or make sure your user is part of the docker
group if you didn't use sudo
.
Eg: Docker installation on my ubuntu
Mini Project : React_Django_Demo_App
Flowchart:
Vim Dockerfile
cd react_django_demo_app
I have deleted the dockerfile which i got from my github repo using gitclone.
docker images
docker build . -t react_django_app:latest
docker images
Docker is run with binding port numbers of host and container port, so container is running with container ID. Now I will launch the public ip with 8000 port but need to open 8000 in host, I will go to security group and add inbound rules in EC2 instance.
docker ps
docker run -d -p 8000:8000 react_django_app:latest
Understanding the above command--> docker run -d(detached mode) -p(bind ports) --mount source=device volume , target is the folder within the container, so both will bind and last parameter is imagename