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

  1. Navigate to your AWS EC2 dashboard and select your instance.

  2. Go to the "Security" tab.

  3. Click on "Security Groups."

  4. Select the appropriate security group and click "Edit inbound rules."

  5. Click "Add rule" and choose "Custom TCP." Set the port to 8080 and the source type to "Anywhere-ipv4."

  6. 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:

  1. 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.

  2. 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.

  3. 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.

  4. 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!

ย