{"id":19079077,"url":"https://github.com/abhixsh/dockerized-flask-app-ec2","last_synced_at":"2026-05-06T06:39:29.782Z","repository":{"id":260620082,"uuid":"881856591","full_name":"abhixsh/dockerized-flask-app-ec2","owner":"abhixsh","description":"This project is a simple Flask web application that demonstrates how to create a dynamic web page using Flask and Docker. The app allows users to customize the background color through an environment variable, showcasing the integration of Flask with Docker and deployment on AWS EC2.","archived":false,"fork":false,"pushed_at":"2024-11-01T13:34:53.000Z","size":843,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-02T18:48:31.954Z","etag":null,"topics":["aws","docker","ec2","flask","python"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhixsh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-01T11:43:42.000Z","updated_at":"2024-11-01T13:34:56.000Z","dependencies_parsed_at":"2024-11-01T12:27:17.014Z","dependency_job_id":"a4b67b9d-fd4e-46f8-a062-6720e58c8343","html_url":"https://github.com/abhixsh/dockerized-flask-app-ec2","commit_stats":null,"previous_names":["abhixsh/dockerized-flask-app-ec2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhixsh%2Fdockerized-flask-app-ec2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhixsh%2Fdockerized-flask-app-ec2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhixsh%2Fdockerized-flask-app-ec2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhixsh%2Fdockerized-flask-app-ec2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhixsh","download_url":"https://codeload.github.com/abhixsh/dockerized-flask-app-ec2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240131773,"owners_count":19752725,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","docker","ec2","flask","python"],"created_at":"2024-11-09T02:13:15.618Z","updated_at":"2026-05-06T06:39:29.722Z","avatar_url":"https://github.com/abhixsh.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dockerized Flask App on EC2\n\n## Step 1: Set Up Your Project\n\n### Create a Project Folder:\n1. Open your file explorer and create a new folder named `flask_app`.\n\n### Open Command Prompt:\n1. Press `Win + R`, type `cmd`, and hit Enter.\n\n### Navigate to Your Project Folder:\n```bash\ncd path\\to\\flask_app\n```\n\n## Step 2: Install Python and Flask\n\n### Check if Python is Installed:\n1. Type `python --version` in Command Prompt. If you see a version number, Python is installed. If not, download and install it from [python.org](https://www.python.org/).\n\n### Install Flask:\n1. Run this command in Command Prompt:\n```bash\npip install flask\n```\n\n## Step 3: Create Your Flask App\n\n### Create a Python File:\n1. In your `flask_app` folder, create a file named `app.py`.\n\n### Write the Code:\n1. Open `app.py` in a text editor (like Notepad or VS Code) and paste this code:\n```python\nfrom flask import Flask, render_template\nimport os\n\napp = Flask(__name__)\n\n@app.route(\"/\")\ndef home():\n    bg_color = os.environ.get(\"BG_COLOR\", \"lightblue\")  # Default color\n    return render_template(\"index.html\", bg_color=bg_color)\n\nif __name__ == \"__main__\":\n    app.run(host='0.0.0.0', port=5000)\n```\n\n## Step 4: Create the HTML Template\n\n### Create a Folder for Templates:\n1. Inside the `flask_app` folder, create a new folder named `templates`.\n\n### Create an HTML File:\n1. Inside the `templates` folder, create a file named `index.html`.\n\n### Write the HTML Code:\n1. Open `index.html` in a text editor and paste this code:\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n    \u003ctitle\u003eFlask App\u003c/title\u003e\n    \u003cstyle\u003e\n        body {\n            background-color: {{ bg_color }}; /* Background color from environment variable */\n            color: black;\n            font-family: Arial, sans-serif;\n            text-align: center;\n            padding: 50px;\n        }\n    \u003c/style\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003ch1\u003eHello, Flask!\u003c/h1\u003e\n    \u003cp\u003eWelcome to your simple Flask web app.\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Step 5: Test Your Flask App\n\n### Run the App:\n1. In Command Prompt, navigate to your project folder again:\n```bash\ncd path\\to\\flask_app\n```\n2. Run the app with:\n```bash\npython app.py\n```\n\n### Open a Web Browser:\n1. Go to `http://127.0.0.1:5000`. You should see your Flask app!\n\n![Locally Run](\u003cimg/Screenshot (36).png\u003e)\n\n## Step 6: Create a Dockerfile\n\n### Create a Dockerfile:\n1. In the `flask_app` folder, create a file named `Dockerfile` (no extension).\n\n### Write the Dockerfile Code:\n1. Open the `Dockerfile` in a text editor and paste this code:\n```dockerfile\nFROM python:3.12-slim\n\nWORKDIR /app\n\nCOPY . /app\n\nRUN apt-get update \u0026\u0026 apt-get install -y python3-venv \\\n    \u0026\u0026 python3 -m venv venv\n\nRUN . venv/bin/activate \u0026\u0026 pip install flask\n\nEXPOSE 5000\n\nENV FLASK_APP=app.py\n\nCMD [\"venv/bin/python\", \"app.py\"]\n```\n\n## Step 7: Build the Docker Image\n\n### Install Docker:\n1. Download and install Docker Desktop from Docker's website.\n\n### Open Docker Command Line:\n1. You can use the Command Prompt or PowerShell.\n\n### Navigate to Your Project Folder:\n```bash\ncd path\\to\\flask_app\n```\n\n### Build the Docker Image:\n```bash\ndocker build -t flask_app .\n```\n\n## Step 8: Push the Docker Image to Docker Hub\n\n### Create a Docker Hub Account:\n1. Sign up at Docker Hub.\n\n### Log in to Docker Hub:\n```bash\ndocker login\n```\n\n### Tag Your Image:\n```bash\ndocker tag flask_app your_dockerhub_username/flask_app\n```\n\n### Push the Image:\n```bash\ndocker push your_dockerhub_username/flask_app\n```\n![dockerHub Pushed](\u003cimg/Screenshot (33).png\u003e)\n\n## Docker Hub Repository\n\nYou can find the Docker image for this project on Docker Hub: [abhixsh/flask_app](https://hub.docker.com/r/abhixsh/flask_app)\n## Step 9: Run Your Docker Container on EC2\n\n### Launch an EC2 Instance:\n1. Go to AWS Management Console and launch a new EC2 instance using an Ubuntu image.\n\n### SSH into Your EC2 Instance:\n1. Follow the instructions to connect via SSH.\n\n### Install Docker on EC2:\n```bash\nsudo apt-get update\nsudo apt-get install -y docker.io\n```\n\n### Pull Your Docker Image:\n```bash\nsudo docker pull your_dockerhub_username/flask_app\n```\n\n### Run Your Docker Container:\n1. Replace `pink` with any color you want for the background:\n```bash\nsudo docker run -d -p 5000:5000 -e BG_COLOR=pink your_dockerhub_username/flask_app\n```\n\n### Access Your Flask App:\n1. Open a web browser and go to `http://\u003cYour-EC2-Public-IP\u003e:5000`.\n\n![Ec2 pushed](\u003cimg/Screenshot (35).png\u003e)\n\n## Check EC2 Security Group Settings\n\nMake sure the Security Group associated with your EC2 instance allows inbound traffic on port 5000 (or the port you specified in your Docker command). To do this, go to the EC2 Dashboard \u003e Instances \u003e select your instance \u003e Security \u003e Security Groups. Click on the Security Group, then Edit Inbound Rules, and add the following rule:\n- **Type:** Custom TCP\n- **Port Range:** 5000\n- **Source:** Anywhere (0.0.0.0/0) if it’s public, or specify your IP for more security.\n\n![Inbound Rules](\u003cimg/Screenshot (34).png\u003e)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhixsh%2Fdockerized-flask-app-ec2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhixsh%2Fdockerized-flask-app-ec2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhixsh%2Fdockerized-flask-app-ec2/lists"}