Docker Deployment
Docker containers package your Flask app and all dependencies into a single unit, making deployment consistent across environments.
Step 1: Create a Dockerfile
In your project root, create `Dockerfile` (no extension):
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
ENV FLASK_APP=app.py
ENV FLASK_ENV=production
EXPOSE 5000
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]Step 2: Build the Docker Image
docker build -t flask-app .Step 3: Run Locally
docker run -p 5000:5000 flask-appStep 4: Deploy to Cloud (e.g., Heroku, Render, or any VPS)
Push the image to a registry (Docker Hub) and deploy to a cloud service that supports Docker.
Using Gunicorn for Production (Optional)
Add `gunicorn` to requirements.txt and change CMD:
CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]Two Minute Drill
- Docker packages your app with all dependencies.
- Create a Dockerfile specifying the environment and run command.
- Build image with `docker build -t name .`.
- Run with `docker run -p host:container port`.
- Use Gunicorn for production‑grade server.
Need more clarification?
Drop us an email at career@quipoinfotech.com
