This is a simple Node.js web application that dynamically displays a webpage with a customizable background color. This document outlines how to run the application directly on a server without using Docker.
Before you begin, ensure you have the following installed:
- Node.js: Version 16 or higher. You can download it from nodejs.org.
- npm: Node Package Manager, which comes with Node.js.
- Git: (Optional) For cloning the repository.
-
Create a Virtual Machine or Cloud Instance:
- Use a cloud provider like AWS EC2, Azure VM, or GCP Compute Engine.
- Choose an Ubuntu 20.04 image.
- Select at least a
t2.microinstance (1 vCPU, 1GB RAM) for testing.
-
Open Inbound Ports:
- Configure your firewall to allow inbound traffic on port
8080(or any other port you plan to use).
- Configure your firewall to allow inbound traffic on port
-
SSH into the Instance:
- Connect to the instance using SSH.
-
Install Required Tools:
-
Update the package list and install
git,nodejs, andnpm:sudo apt update sudo apt install -y git nodejs npm
-
-
Clone the Repository (Optional):
If you haven't already, clone the repository to your local machine:
git clone https://github.com/HILL-TOPCONSULTANCY/COLOR-APP.git cd COLOR-APP -
Install Dependencies:
Navigate to the project directory and install the required npm packages:
npm install
-
Start the Application with the Default Color:
To run the application with the default background color (blue), use the following command:
npm start
-
Start the Application with a Custom Color:
To specify a custom background color, set the
COLORenvironment variable before running the application. For example, to set the color to green:COLOR=green npm start
## Accessing the Application
Once the application is running, you can access it in your web browser at the following URL:
http://localhost:8080
These steps outline how to run the Color Display Application using Docker on an AWS EC2 instance.
- An active AWS account.
- Basic knowledge of AWS EC2 and Docker.
- Docker installed on your local machine (for building the image).
-
Install Docker on the EC2 Instance:
-
Once connected, install Docker:
-
For Ubuntu:
sudo apt update sudo apt install -y docker.io sudo systemctl start docker sudo systemctl enable docker sudo usermod -aG docker $USER newgrp docker
-
For Amazon Linux 2:
sudo yum update -y sudo amazon-linux-extras install docker sudo systemctl start docker sudo systemctl enable docker sudo usermod -aG docker $USER newgrp docker
-
-
Verify Docker installation:
docker --version
-
-
Clone the Application Repository:
-
Clone the application repository:
git clone https://github.com/HILL-TOPCONSULTANCY/COLOR-APP.git cd COLOR-APP
-
-
Build the Docker Image:
-
Navigate to the project directory containing the
Dockerfile. -
Build the Docker image:
docker build -t hilltopconsultancy/color-app:blue .- This will build the image with the default color (blue).
-
-
Run the Docker Container:
-
Run the Docker container with port mapping and environment variable:
docker run -d -p 8080:8080 -e COLOR=blue hilltopconsultancy/color-app:blue
-
Replace
bluewith the desired color (e.g.,green,red,#FF0000). -
If you want to use a specific tag, replace
latestwith the tag name (e.g.,hilltopconsultancy/color-app:blue). -
If you want to pull the image from Docker Hub (assuming you've pushed it):
docker pull hilltopconsultancy/color-app:latest docker run -d -p 8080:8080 -e COLOR=blue hilltopconsultancy/color-app:latest
-
-
-
Access the Application:
-
Open a web browser and navigate to:
http://your-ec2-public-ip:8080- Replace
your-ec2-public-ipwith the public IP address or DNS of your EC2 instance.
- Replace
-
There are a few ways to change the color after the container is running:
-
Stop and Re-run the Container:
-
Stop the running container:
docker stop <container_id>
- Replace
<container_id>with the ID of your container (you can find it usingdocker ps).
- Replace
-
Re-run the container with the new environment variable:
docker run -d -p 8080:8080 -e COLOR=green hilltopconsultancy/color-app:latest
- Replace
greenwith the new color you want to use.
- Replace
-
-
Using
docker update(Less Common, May Not Work as Expected):-
You can try to update the environment variable using
docker update, but this might not always work as expected for running containers:docker update --env COLOR=new_color <container_id>
- After this, you might need to restart the container for the changes to take effect. However, stopping and re-running is generally the more reliable approach.
-