Dockerfile Python Application Guide
Dockerfile Python Application Guide
Prerequisites
Before starting, ensure that you have the following installed on your machine:
1. Docker: Install Docker from https://docs.docker.com/get-docker/.
2. Python Application: A simple Python application (app.py and requirements.txt).
3. AWS EC2 instance with public IP access.
4. Security group configured to allow inbound traffic on port 5000.
@app.route('/')
def hello():
return 'Hello, World!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
```
3. Create the requirements.txt file to list the dependencies:
```text
SHUBHAM SAJANNAVAR 1
Flask==2.0.1
```
```dockerfile
# Step 1: Specify the base image
FROM python:3.9-slim
SHUBHAM SAJANNAVAR 2
This will bind port 5000 of the container to port 5000 of the host machine, making the Flask
app accessible.
```
http://<public-ip-of-ec2-instance>:5000
```
This will display the 'Hello, World!' message served by the Flask app.
```text
Flask==2.0.1
Werkzeug==2.0.3
```
SHUBHAM SAJANNAVAR 3
```python
app.run(host='0.0.0.0', port=5000)
```
Conclusion
You have successfully containerized a Flask application and deployed it on AWS EC2 using
Docker. By following the above steps, you can run the Flask app and resolve common issues
related to Docker, Flask, and AWS networking.
SHUBHAM SAJANNAVAR 4