This tutorial will assist in setting up Docker on an Amazon EC2 Ubuntu instance. Docker’s containerization and Ubuntu’s user-friendliness make cloud application deployment and management simple. Amazon EC2 provides scalable infrastructure for hosting Docker containers, allowing for smooth app management and scaling. To easily set up Docker on your EC2 instance, just follow this tutorial.
What is Docker?
Docker is an open-source platform that simplifies the process of building, deploying, and managing applications within isolated containers. These containers bundle the application code along with all its dependencies, ensuring the software behaves the same across different environments, whether on a local machine or in the cloud.
Common uses:
- Microservices
- Continuous integration/continuous delivery (CI/CD) pipelines
- Development and testing environments
- Multi-cloud and hybrid-cloud setups
Example: A business can containerize its web app and database using Docker, ensuring that they run the same way on any server, regardless of the OS.
What is Ubuntu?
Ubuntu is a widely used, open-source operating system based on Linux. It is known for its ease of use, security, and versatility, making it popular for both personal computing and server environments.
Common uses:
- Desktop OS: Ubuntu is used on laptops and desktops for daily tasks like browsing and development.
- Cloud and Servers: It is commonly used to run web servers, databases, and other services on cloud platforms such as AWS.
- Development: Ubuntu is favored by developers due to its broad range of tools and libraries.
Example: Ubuntu is often the go-to operating system for cloud-based virtual machines (like Amazon EC2) and is popular among developers for building and deploying software.
Launching a new Ubuntu instance on AWS
- Open the AWS Management Console, then search for EC2.
- Click Launch Instance. (Region: Seoul)
- Input the following details:
- Name and tags: Docker Ubuntu Server
- Application and OS Images: Ubuntu
- Instance: t2.micro
- Number of instances: 1
- Key pair:
- Click Create new key pair
- Input the following details then click Create key pair
- Leave the rest of the details as is
- Click Launch instance, then wait
- It should look like this
Installing Docker
- Select the instance then click Connect
- Click Connect again
- It should look like this
- Run the following commands (Should be in order):
-
- Command:
sudo apt-get update
- Updates the package list
- Command:
-
- Command:
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common -y
- Installs required dependencies
- Command:
-
- Command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Adds Docker’s Official GPG Key
- Command:
-
- Command:
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
- Adds Docker APT Repository
- Command:
-
- Command:
sudo apt-get update
- Updates the package database
- Command:
-
- Command:
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
- Installs docker engine
- Command:
-
- Command:
sudo docker --version
- Verifies docker installation
- Command:
-
- Command:
sudo docker run hello-world
- To test if docker is running correctly
- Command:
-
- Command:
sudo docker ps -a
- To check all existing containers
- Command:
Instance Termination
- Select the instance, then click Instance state
- Click Terminate (delete) instance
- Click Terminate (delete) when prompted for confirmation
- After terminating the instance, it remains visible for a while in a terminated state.
Conclusion
By following the steps in this tutorial, you’ve successfully set up Docker on an Ubuntu-based Amazon EC2 instance as well as learn how to clean up the used resources. You can now efficiently manage, deploy, and scale your applications, with the use of both Docker and AWS. From here, you can now explore how to deploy containers and fix your infrastructure to meet your project needs.