What we do in this blog →
- Create a Dockerfile for a simple web application (Reddit application)
- Build the image using the Dockerfile and run the container
- Verify that the application is working as expected by accessing it in a web browser
- Push the image to a public or private repository (e.g. Docker Hub )
Docker plays a major role in building the application by improving its efficiency. It containerizes the application by creating an image which is portable i.e. can be run anywhere in any specification of the server.
Here comes the base of Docker which is called a Docker file. Let's learn what is it and how it sets a standard from application to apply through its configuration.
DOCKER FILE
A docker file is a text file with a set of information that Docker reads to build an image about it. The file contains similar commands as we give CLI commands to build an image manually but here we combine all the steps to execute at a time.
Steps to create a Docker container for a Reddit application
Log in to your AWS EC2 console on your Ubuntu machine.
Install Docker on your Ubuntu instance by running the following commands:
sudo apt-get update && sudo apt-get install docker.io -y
Check docker is active or not using this following command
systemctl status docker
Add your current user to the Docker group using the following command:
sudo usermod -a -G docker $USER
This command adds the current user to the Docker group, allowing the user to run Docker commands without using sudo every time.
Clone the code from the provided GitHub repository by running the following command:
git clone https://github.com/nahidkishore/reddit-clone-k8s-ingress.git
This command will create a new directory named reddit-clone-k8s-ingress in your current directory.
- Navigate to the reddit-clone-k8s-ingress directory using the cd command.
- Create a new file named Dockerfile in this directory using the vim command, and open it.
Using the cat command shows docker file code
cat Dockerfile
- Build the Docker image using the following command:
docker build . -t my-reddit-app
- Check image create or not using the docker image command
docker images
- After the image build, just go to your ec2 instance and select your running instance.
click security group and add port range on the inbound rule.
For example→ in my case, I have added a 3000 port range inbound rule
- Once the image is build, you can start a new Docker container using the following command:
docker ps: To check container is running or not
docker run -d -p 3000:3000 my-reddit-app:latest
docker ps
- Verify that the application is working as expected by accessing it in a web browser.
Now you can take the public IP of the machine and port 3000 to access the application. (make sure from security bound rules port 3000 is accessible for EC2 instance)
- Push the image to a public or private repository using this command
docker push nahid0002/my-reddit-app
Finally, "Building and Deploying a Dockerized Reddit Application: Step-by-Step Guide" provides you with a comprehensive walkthrough of the entire process involved in containerizing and deploying your Reddit application using Docker. We've covered all the essential steps, from creating a Dockerfile to pushing the image to a repository.
By following this step-by-step guide, you have learned how to craft a Dockerfile specifically tailored to your Reddit application, ensuring all dependencies and configurations are included. You have gained insights into building the Docker image and running the container, witnessing the seamless transformation of your application into a portable and self-contained unit.
Through careful verification, you have confirmed that your Dockerized Reddit application functions as expected by accessing it in a web browser. This validation step ensures the successful Dockerization of your application, giving you confidence in its reliability and performance.
Furthermore, we have guided you in pushing the Docker image to a public or private repository, such as Docker Hub. This empowers you to share your Dockerized Reddit application with others and deploy it effortlessly across different platforms.
We believe that with the knowledge and skills acquired from this guide, you are well-equipped to embark on your journey of building and deploying Dockerized applications. Docker offers numerous benefits, such as improved scalability, portability, and ease of deployment, making it a valuable tool in modern application development.
Stay tuned for more articles and guides where we delve into advanced Docker concepts and explore additional techniques to enhance your containerization and deployment workflows. We hope this guide has been informative and helpful in your quest to leverage Docker for building and deploying your Reddit applications.
Thank you for reading this blog. I hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.
— Happy Learning !!!
Let’s connect !!!