Since you are using Flask in Agent.py
, I will modify the Dockerfile and steps accordingly. [WIP]
1. Update the Dockerfile
Create a Dockerfile
in the same directory as Agent.py
and index.html
:
# Use an official Python image as the base
FROM python:3.10
# Set the working directory inside the container
WORKDIR /app
# Copy the application files to the container
COPY . .
# Install required dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Expose the Flask default port
EXPOSE 5000
# Set the environment variable to tell Flask to run on all network interfaces
ENV FLASK_APP=Agent.py
ENV FLASK_RUN_HOST=0.0.0.0
# Start the Flask server
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]
2. Create a .dockerignore
File
To exclude unnecessary files from the image, create a .dockerignore
file:
__pycache__/
*.pyc
*.pyo
*.log
venv/
3. Ensure Agent.py
is Properly Configured
Modify Agent.py
to run the Flask server on all available network interfaces:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Llama3.2 is running inside Docker!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
4. Build the Docker Image
Run this command inside your project directory (where Dockerfile
is located):
docker build -t my-llama3-app .
5. Run the Docker Container
Start a container and map port 5000:
docker run -d -p 5000:5000 --name llama-container my-llama3-app
Now, Flask will be running at http://localhost:5000
.
6. Push the Image to RMC65
-
Log in to RMC65:
docker login rmc65
-
Tag the Image for RMC65:
docker tag my-llama3-app rmc65/your-username/my-llama3-app:latest
-
Push the Image to RMC65:
docker push rmc65/your-username/my-llama3-app:latest
7. Run the Image on Another Device
On the new device, follow these steps:
-
Install Docker (if not installed):
sudo apt install docker.io -y
-
Pull the Image from RMC65:
docker pull rmc65/your-username/my-llama3-app:latest
-
Run the Flask Container:
docker run -d -p 5000:5000 --name llama-container rmc65/your-username/my-llama3-app:latest
Now, you can access the Flask app at http://<device-ip>:5000
.
Bonus: Push to Docker Hub (if needed)
If you want to push the image to Docker Hub, follow these steps:
-
Log in:
docker login
-
Tag the image:
docker tag my-llama3-app your-dockerhub-username/my-llama3-app:latest
-
Push the image:
docker push your-dockerhub-username/my-llama3-app:latest
-
On another device, pull & run:
docker pull your-dockerhub-username/my-llama3-app:latest docker run -d -p 5000:5000 --name llama-container your-dockerhub-username/my-llama3-app:latest
This setup ensures Flask is properly configured inside Docker, and your application can be easily deployed on any device. Let me know if you need further modifications! 🚀
No comments:
Post a Comment