A Beginner's Guide to Installing and Setting Up Docker on AWS EC2
Welcome, fellow cloud enthusiasts! In today's tutorial, we'll walk you through the step-by-step process of installing and setting up Docker on an Amazon Web Services (AWS) EC2 instance. If you're new to containerisation and eager to harness the power of Docker, you're in the right place. So, let's dive in and get started!
Step 1: Updating the System:
Our journey begins with ensuring your EC2 instance is up to date. Open your terminal and enter the following command:
bashsudo yum update
This will fetch and install any available updates for your system.
Step 2: Searching and Gathering Information:
Let's find out more about the Docker package available for installation. Run these commands:
bashsudo yum search docker sudo yum info docker
These commands will provide information about Docker and its available versions.
Step 3: Installing Docker:
With the information gathered, you're ready to install Docker. Execute the following command:
bashsudo yum install docker
This command will install Docker on your EC2 instance.
Step 4: Adding User to Docker Group:
By adding your user to the Docker group, you'll be able to use Docker commands without using 'sudo.' Run the following commands:
bashsudo usermod -a -G docker ec2-user newgrp docker
This ensures that your user has the necessary permissions.
Step 5: Enabling and Starting Docker Service:
To ensure Docker starts automatically on system boot and to initiate the service, use these commands:
bashsudo systemctl enable docker.service
sudo systemctl start docker.service
Step 6: Verifying Docker's Status:
To check if Docker is running and active, execute:
bashsudo systemctl status docker.service
You should see a message indicating that the Docker service is active and running.
Step 7: Installing Docker Compose:
We'll begin by installing Docker Compose on your EC2 instance. Use the following commands:
bashsudo curl -SL https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
The first command downloads the Docker Compose binary to the specified location. The second command makes it executable.
Step 8: Verifying Docker Compose Installation:
Confirm that Docker Compose has been successfully installed by running:
bashdocker-compose --version
You should see the version number displayed.
Step 9: Trying Out a Simple Docker Compose Setup:
Now that you have Docker Compose at your disposal, let's create a simple example to see it in action. Create a docker-compose.yml
file with a basic configuration:
yamlversion: '3'
services:
web:
image: nginx:alpine
ports:
- "80:80"
Save the file and then run:
bashdocker-compose up -d
This will start an NGINX container in detached mode, exposing port 80.
Step 10: Stopping and Removing Containers:
To stop and remove the containers created by the Docker Compose setup, use:
bashdocker-compose down
This command cleans up the resources created in the docker-compose.yml
file.
Conclusion:
Kudos! You've skilfully installed and configured Docker on your AWS EC2 instance, ushering in a realm teeming with containerisation potential. This paves the way for streamlined and consistent application deployment. Moreover, you've seamlessly integrated Docker Compose into your EC2 setup, offering you a seamless approach to orchestrating intricate multi-container systems. As you delve into its capabilities, you're poised to unearth novel efficiencies and a heightened sense of order in your container-based endeavours. With this installation prowess under your belt, anticipate a future brimming with further Docker insights and explorations. Here's to a joyful journey of containerisation!
About Me
Hello, fellow cloud adventurers! I'm Prince K Sharma, a software engineer passionate about simplifying cloud technologies. Join me on my blog for more tutorials, guides, and insights into the world of cloud computing. Follow me on Linked In to stay updated on all things cloud and tech.
Comments
Post a Comment