Cruising the Docker Learning Curve: Your Roadmap to Container Mastery
Ddhruv Arora
Engineering Student | MERN Stack and Flutter Developer | DevOps Enthusiast | Python Programmer | President RAIoT Labs
Introduction to Docker
Docker is a powerful platform for developing, shipping and running applications inside containers. Containers are lightweight, isolated environments that package applications and their dependencies together. Here's more information about Docker, along with its benefits:
What is Docker?
Docker is an open-source platform that automates the deployment of applications within containers. Containers are a form of virtualization but differ from traditional virtual machines (VMs) in several key ways:
Benefits of Docker:
Overall, Docker simplifies the process of building, shipping, and running applications, making it easier for developers and operations teams to collaborate effectively, reduce infrastructure costs, and deliver software reliably and quickly across different environments. Its numerous benefits have made it a cornerstone technology in modern software development and deployment.
Agenda
In this comprehensive guide, we will embark on a journey to master Docker, the powerful containerization platform that's transforming the world of software development and deployment. Below is a sneak peek of what lies ahead:
Section 1: Setting Sail with Docker- Installing Docker on RHEL 9
Section 2: Crafting Your Docker Vessel - Configuring a Web Server Inside a CentOS 7 Container
Section 3: Navigating the Docker Hub Waters - Creating an Account on hub.docker.com
Let's Dive into the First Hands-On Activity: Installing Docker on RHEL 9
Welcome aboard, fellow container enthusiast! If you're reading this, you're on a voyage to becoming a Docker master, and I'm here to be your captain on this exciting journey. Docker, the game-changing technology that has redefined how we deploy applications, is at your fingertips. We'll break down the intricacies of Docker into three hands-on activities, each one bringing you closer to Docker mastery.
Our first port of call is to get Docker up and running on a Red Hat Enterprise Linux 9 (RHEL 9) system. Think of this as setting sail on our Docker adventure. In this segment, we'll explore the ins and outs of Docker installation on RHEL 9, step by step. Whether you're a seasoned developer or just dipping your toes into the world of containers, you're in the right place.
So, grab your captain's hat, and let's embark on our Docker journey by diving headfirst into the first hands-on activity: Installing Docker on RHEL 9.
Step 1: Install a file editor like `Vim`
Use the following command to install:
sudo yum install vim -y
Step 2: Create a yum repo to install the docker
Use the following command for creating a custom yum repo, to install the docker community edition:
sudo vim /etc/yum.repos.d/docker-ce.repo
Once the Vim editor is opened, add the following lines to the file:
[docker-ce]
baseurl=https://download.docker.com/linux/centos/9/x86_64/stable
gpgcheck=0
The file should look something like this, after adding the above lines to it:
Let's break down what each line is doing:
Step 3: Install the Docker-CE
The installation is pretty straightforward, use the following command:
sudo yum install docker-ce --nobest --skip-broken -y
Let's break down what each part of this command does:
Step 4: Start and Enable Docker
Once docker is successfully installed, start the docker services and check the status to verify the same, use the following commands
sudo systemctl start docker
sudo systemctl status docker
The expected output:
Congratulations, you have successfully installed and configured docker on your system.
Step 5: Add Your User to the Docker Group [Optional]
By default, Docker commands require root privileges. To allow your user to run Docker commands without using sudo, you can add your user to the docker group. Replace your-username with your actual username:
sudo usermod -aG docker your-username
Use the following command to apply the group changes without logging out:
su - your-username
Now, you should be able to run commands without using sudo again and again.
Moving on to the Second Activity: Crafting Your Docker Vessel
We've set sail on our Docker journey, and it's time to steer our course toward the second exciting activity on our list. Our current destination: crafting your very own Docker vessel by configuring a web server inside a CentOS 7 container.
In our first activity, we successfully installed Docker on a Red Hat Enterprise Linux 9 system, and now we're ready to take the next step. In this hands-on segment, we'll dive deep into the heart of Docker, where you'll learn how to create and customize containers to suit your needs.
Imagine Docker containers as vessels, each capable of carrying a unique cargo—your applications, dependencies, and configurations—all neatly packaged and ready to sail. Now, we'll build one such vessel by configuring a web server inside a CentOS 7 container using a dockerfile.
So, secure your life jacket and prepare to embark on our second activity: Crafting Your Docker Vessel.
But before diving into the activity of configuring an Apache HTTP Server (httpd) within a Docker container using a Dockerfile, it's essential to understand what a Dockerfile is and its significance in containerization.
Understanding the Dockerfile
A Dockerfile is like the blueprint for a Docker container. It's a plain-text configuration file that contains a set of instructions, in a specific format, for building a Docker image. When you build an image using a Dockerfile, these instructions are executed one by one, creating layers that form the final image. Let's break down the key elements of a Dockerfile:
Why Dockerfiles are Important
Dockerfiles play a crucial role in standardizing container creation and ensuring consistency across different environments. Here's why they are essential:
Now that we have a good understanding of Dockerfiles, let's apply this knowledge in our second activity by creating a Dockerfile to configure the httpd web server inside a CentOS 7 container and add a custom web page.
Step 1: Create the Dockerfile and Web Page
Note: Two things to keep in mind before creating the dockerfile
The code that we will be utilizing for Dockerfile:
领英推荐
# Use the official CentOS 7 base image from Docker Hub
FROM centos:7
RUN yum -y install httpd
COPY index.html /var/www/html/
EXPOSE 80
# Start the Apache service when the container runs
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
let's break down the Dockerfile code step by step:
The code for the index.html file is given below, it will simply display Hello World in the center of the web page.
<!DOCTYPE html
<html>
<head>
? ? <title>Hello World</title>
? ? <style>
? ? ? ? body {
? ? ? ? ? ? background-color: black;
? ? ? ? ? ? color: white;
? ? ? ? ? ? text-align: center;
? ? ? ? ? ? display: flex;
? ? ? ? ? ? justify-content: center;
? ? ? ? ? ? align-items: center;
? ? ? ? ? ? height: 100vh;
? ? ? ? ? ? margin: 0;
? ? ? ? }
? ? </style>
</head>
<body>
? ? <div>
? ? ? ? <h1>Hello World</h1>
? ? </div>
</body>
</html>>
Step 2: Build the Dockerfile
To build the Docker image using the Dockerfile you've created, follow these steps:
docker build -t my-web-server-image .
Docker will execute the instructions in your Dockerfile and build the image layer by layer. You will see output messages for each step as Docker progresses. Once the build process is complete, you should see a message indicating that the image was successfully built.
It should look something like this:
Step 3: Start the container!
Once the image is built successfully, start the container using the following command:
docker run -d -p 8080:80 <image_name>
In my case, it looks like this:
Let's break down the command:
Step 4: Visit the Web Page
Head on to `localhost:8080` to see the results, it should load a web page displaying "Hello World" at the center.
The output:
Congratulations! ??
You've successfully set up and configured Apache HTTP Server inside a Docker container. It's no small feat, and you've taken a big step towards mastering Docker and web server management. Your custom web page is now ready to be accessed, and you've unlocked the power of containerization.
Note: Installing the Apache HTTP Server (httpd) on a CentOS 7 image can be a resource-intensive task, and the time it takes to complete may vary depending on the hardware and resources available on your system. If you're working on an AWS EC2 instance with limited resources, this process might take up to several hours.
For the sake of simplicity and exploration, we recommend utilizing Docker Desktop for Windows if you have access to it. Docker Desktop provides a seamless and efficient containerization environment, and it's well-suited for development and testing purposes. During our exploration, we found it to be an excellent choice for setting up and experimenting with containers.
With Docker Desktop, you can enjoy a smoother experience and faster container deployment, allowing you to focus more on learning and experimenting with Docker and less on resource constraints.
Finally, We Have the Last Activity: Sharing Your Docker Creation with the World
You've come a long way on this Docker journey, and now it's time for the grand finale. In our last activity, we'll navigate the waters of Docker Hub, the online hub for Docker images, and learn how to share your Docker creation with the world.
Docker Hub is where the global Docker community gathers to share, collaborate, and discover containers. It's your gateway to showcasing your containerized masterpiece to fellow developers and enthusiasts worldwide.
But before we embark on this final leg of our journey, ensure you've completed the previous activities. You should have Docker up and running on your system and a Docker container with Apache web server and your custom web page ready to go.
So, fasten your seatbelts, and let's set sail into the third and last activity: Sharing Your Docker Creation with the World.
Step 1: Create a Docker Hub account
If you already have an account, proceed to login
Once login/Signup is completed, you should see the Docker Hub Dashboard:
Step 2: Login to Docker Hub:
Open your terminal or command prompt and run the following command to log in to Docker Hub using your Docker Hub credentials (username and password):
docker login
You'll be prompted to enter your Docker Hub username and password.
Note: You need to type the password manually, you can't use copy-paste for the password field.
Step 3: Tag Your Docker Image
Before you can push an image to Docker Hub, you need to tag it with your Docker Hub username and the desired repository name. Suppose you have an image named my-web-server-image that you want to push to Docker Hub:
docker tag my-image your-docker-hub-username/my-web-server-image
Replace your-docker-hub-username with your actual Docker Hub username.
So, after all the necessary changes, it should look similar to this:
Step 4: Push the Docker Image
After tagging your image, you can push it to Docker Hub using the docker push command:
docker push your-docker-hub-username/my-web-server-image
Docker will upload your image to your Docker Hub account.
Note: The push process may take some time, depending on the size of your image and your internet connection speed. Docker will display progress information in the terminal.
Step 5: Verification
After the push is complete, you can visit your Docker Hub account on the Docker Hub website (https://hub.docker.com/) to verify that your image has been successfully pushed and is visible in your repository.
The result:
Congratulations! ??
You've achieved a significant milestone on your Docker journey by successfully pushing your Docker image to Docker Hub. Your containerized creation is now accessible to the global Docker community, ready to inspire and assist developers worldwide.
By sharing your image on Docker Hub, you've not only showcased your skills but also contributed to the thriving ecosystem of containerized applications and services. Your dedication to learning and mastering Docker is truly commendable.
In Conclusion: Navigating the Docker Way!
As we approach the end of our Docker journey, it's time to reflect on the incredible adventure we've embarked upon. From setting up Docker, to crafting custom containers and sharing your creations with the world, you've taken significant steps towards Docker mastery. We hope this guide has been an invaluable resource in your quest to become a Docker virtuoso.
We'd like to extend our heartfelt thanks to you, the reader, for joining us on this voyage. Your curiosity and determination are the driving forces behind every successful Docker deployment, and we're thrilled to have been part of your learning journey.
In addition, I want to express my deepest gratitude to Vimal Daga Sir, whose guidance and mentorship have been a guiding light in the world of containerization. His commitment to knowledge sharing and dedication to empowering learners have inspired countless individuals, including us. Thank you, Sir, for your exceptional mentorship.
As you continue your exploration of Docker and container technologies, remember that the Dockerverse is ever-evolving. New challenges and opportunities await, and we encourage you to keep pushing the boundaries of what's possible with containers.
We bid you fair winds and following seas on your Docker adventures. May your containers run smoothly, your applications thrive, and your journey towards technical excellence continue to flourish.
Founder & CEO at Aaptatt
1 年?? Nailing it with this post! Docker's role in enabling consistency across different environments is truly remarkable. This technology is paving the way for smoother workflows. Cheers to progress! ?? #DockerAdvantage #TechEvolution