Skip to content

npk-aws/Python-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-server Dockerized

Creating a basic Python web server, containerizing it with Docker, and hosting it on an Amazon EC2 instance.

Step 1: Creating a Basic Python Web Server
Create a file named app.py with the necessary content

Step 2: Creating a Docker Container
Create a file named Dockerfile with the necessary content

Step 3: Build and Run the Docker Container Locally
Open a terminal, in the directory containing both app.py and Dockerfile, run the following commands:

Build the Docker image

docker build -t python-web-server .

Run the Docker container

docker run -p 8000:8000 python-web-server

Visit http://localhost:8000 in the web browser to see the "Hello, World!" message.

Step 4: Host on Amazon EC2 Create an EC2 instance

  1. Transfer Files to EC2:

Use scp (Secure Copy Protocol) to transfer files to the EC2 instance. Replace EC2_PUBLIC_IP with the EC2 instance's public IP address.

scp -i path/to/your/key.pem app.py Dockerfile user@EC2_PUBLIC_IP:/path/on/ec2 (example: ssh -i "C:\Users\hp\Downloads\Python-server-kp.pem" ubuntu@54.242.227.27:\home\user)

  1. Connect to EC2:

Connect to the EC2 instance using SSH. Replace EC2_PUBLIC_IP and path/to/key.pem with the EC2 instance's public IP address and the path to the private key.

ssh -i path/to/key.pem user@EC2_PUBLIC_IP

  1. Build and Run Docker Container on EC2:

On the EC2 instance, navigate to the directory where you transferred the files and run the following commands:

Build the Docker image

docker build -t python-web-server .

Run the Docker container in detached mode

docker run -d -p 80:8000 python-web-server

  1. Access the Web Server:

Open the web browser and enter the EC2 instance's public IP address. We should see the "Hello, World!" message. http://ec2_IP_address:8000

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published