Day 17: Docker Project for DevOps Engineers.
Dockerize the 2048 Game: Step-by-Step Guide
Welcome to our guide on Dockerizing the classic 2048 Game! Dockerizing applications allows for easy deployment and scalability, ensuring consistency across different environments. In this tutorial, we'll walk you through the process of containerizing the 2048 Game using Docker and deploying it on AWS EC2.
Getting Started
To begin, make sure you have Docker installed on your local machine and an AWS EC2 instance set up. Let's dive into the steps:
Step 1: Clone the Repository
git clone <repository_url>
cd 2048-Game
Dockerfile:
# Use the official Nginx image as the base image
FROM nginx:latest
# Set the working directory inside the container
WORKDIR /usr/share/nginx/html
# Copy all files from the current directory to the working directory inside the container
COPY . .
# Expose port 80 to allow access to the Nginx web server
EXPOSE 80
Step 2: Configure AWS EC2 Security Group
Navigate to your AWS EC2 dashboard and select your instance.
Go to the "Security" tab.
Click on "Security Groups."
Select the appropriate security group and click "Edit inbound rules."
Click "Add rule" and choose "Custom TCP." Set the port to
8080
and the source type to "Anywhere-ipv4."Save the rules.
Step 3: Build and Run Docker Container
sudo docker build -t game-2048 .
sudo docker run -d -p 8080:80 game-2048
Step 4: Access the Game
You can now access the 2048 Game in your web browser using the following link: http://your_ec2_instance_ip:8080/
Access my Project using this following link: http://65.2.11.33:8080/
Enjoy playing the 2048 Game in a Dockerized environment!
To push the Docker image to a public or private repository such as Docker Hub, you can follow these enhanced steps:
Login to Docker Hub: First, ensure you're logged in to Docker Hub from your terminal using the
docker login
command.Enter your Docker Hub username and password when prompted.
Create a New Repository: Navigate to your Docker Hub profile and create a new repository. You can do this by visiting the following link: Docker Hub Repositories. Click on "Create Repository" and provide a name for your repository, for example,
game-2048
.Tag the Docker Image: Tag your Docker image with the repository name and version. This step ensures proper identification when pushing to Docker Hub. Use the following command in the working directory:
sudo docker tag game-2048 <your_dockerhub_username>/game-2048:latest
Replace
<your_dockerhub_username>
with your Docker Hub username.Push the Docker Image: Now, push the tagged image to Docker Hub using the
docker push
command:sudo docker push <your_dockerhub_username>/game-2048:latest
This command will upload the tagged image to your Docker Hub repository.
By following these steps, you can seamlessly push your Dockerized 2048 game project to Docker Hub, making it accessible for deployment and collaboration. Ensure to run these commands in the working directory where your Dockerfile and project files are located.
This guide provides a straightforward approach to Dockerizing the 2048 Game and deploying it on AWS EC2. By containerizing the application, you ensure portability and easier management of dependencies. Give it a try and experience the convenience of Docker for deploying web applications!
Subscribe to my newsletter
Read articles from Yashraj Singh Sisodiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Yashraj Singh Sisodiya
Yashraj Singh Sisodiya
I am Yashraj Singh Sisodiya, a 3rd Year CSE student at SVVV, born and raised in Shujalpur. Currently residing in Indore, I'm passionate about pursuing a career in DevOps engineering. My tech journey began with an internship at Infobyte, honing my skills as an Android Developer intern. Alongside my academic pursuits, I actively participate in co-curriculars, holding roles as Technical Lead at Abhyudaya and Cloud Lead at GDSC SVVV, while also serving as an MLSA of my college. I have a keen interest in Cloud Computing, demonstrated through projects such as User management and Backup using shell scripting Linux, Dockerizing applications, CI/CD with Jenkins, and deploying a 3-tier application on AWS. Always eager to learn, I'm committed to expanding my knowledge and skills in the ever-evolving tech landscape.