DAY  5 || Project Dockerfile Deploying GitHub Repositories as Docker Containers on AWS EC2: A Hands-on Guide

DAY 5 || Project Dockerfile Deploying GitHub Repositories as Docker Containers on AWS EC2: A Hands-on Guide

GitHub Repositories:

College-ERP Repository:

Django-Todo Repository:

Step 1: Creating a Directory on Your AWS EC2 Instance

Before we can start working with GitHub repositories, creating a dedicated directory on your AWS EC2 instance where you want to store your project files is a good practice. You can do this using the following commands:

mkdir project-directory
cd project-directory

Replace project-directory with a suitable name for your project directory.

Step 2: Cloning GitHub Repositories

Once you have your project directory set up, you can clone the GitHub repositories into it. Run the following commands for each repository:

git clone https://github.com/samarth-p/College-ERP.git
git clone https://github.com/shreys7/django-todo.git

These commands will fetch and store the repository code within your project directory on your AWS EC2 instance.

Dockerfile for Django-Todo (Django app):




FROM python:3

RUN pip install django==3.2

COPY . .
RUN python manage.py migrate
CMD ["python","manage.py","runserver","0.0.0.0:8080"]

Dockerfile for College-ERP



# Use an official Python runtime as a parent image
FROM python:3.8

# Set the working directory to /app
WORKDIR /College-ERP

# Copy the current directory contents into the container at /app
COPY . .

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

# Make port 8000 available to the world outside this container
EXPOSE 8000

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Docker Commands to Build and Run Containers:

  • Build Docker Image for College-ERP:

      docker build -t college-erp /path/to/college-erp/directory
    
  • Run Docker Container for College-ERP:

      docker run -d -p 8000:8000 -e ENV_VARIABLE=value college-erp
    
  • Build Docker Image for Django-Todo:

      docker build -t django-todo /path/to/django-todo/directory
    
  • Run Docker Container for Django-Todo:

      docker run -d -p 8080:8080 -e ANOTHER_ENV=value django-todo
    

In commands, replace /path/to/college-erp/directory and /path/to/django-todo/directory with the actual directory paths where you have cloned the repositories. These are the commands to build and run Docker containers.

You can follow this guide to customize GitHub repositories into Docker containers and run them on AWS EC2.

Note:

If you encounter any issues while performing this lab, feel free to leave a comment, and we'll be happy to assist you in resolving them

Fiverr:

https://www.fiverr.com/aqibhafeez480?up_rollout=true

#GitHub #Docker #AWS #EC2 #Containerization #GitHubRepositories #DockerContainers #Deployment #Troubleshooting

Did you find this article valuable?

Support Aqib Hafeez(DevOps enthusiast) by becoming a sponsor. Any amount is appreciated!