Step 1: Create the Dockerfile
A Dockerfile is a script containing instructions to build a container image for your application.
- Prepare your project: Ensure your directory contains your application script (e.g.,
app.py) and arequirements.txtfile listing all Python dependencies. - Write the Dockerfile: Create a file named
Dockerfileand add these lines:FROM python:3.9-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["python", "app.py"]
- Build and Test: Open your terminal and run
docker build -t ai-app .. Verify it locally usingdocker run -p 8501:8501 ai-app.