Hi,
Python project auto-detection is fairly new and given the myriad ways in which a Python application can implement web services, it’s not really feasible to detect all of them to generate a reasonable fly.toml and Dockerfile. As seen here, auto-detection will only work for Flask, FastAPI, Streamlit and Django. So you could do one of two things:
- Use a framework to implement your application so it’s auto-detected. Forcing you to use a specific framework to allow
fly launch
to auto-detect seems a bit ham-fisted though - so the best option would probably be: - Provide your own Dockerfile that creates a Docker image for your app. As long as the image builds and starts properly via e.g.
docker run -p x:y
, runningfly launch
will give you afly.toml
that should work, you only need to ensure that theinternal_port
infly.toml
matches the port your app is serving on. If you diddocker run -p x:y
, they
port is the one you should configure here.
You can use the starter Dockerfile that fly launch
creates for an application with Flask:
FROM python:3.10-bookworm AS builder
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
RUN pip install poetry
RUN poetry config virtualenvs.in-project true
COPY pyproject.toml poetry.lock ./
RUN poetry install
FROM python:3.10-slim-bookworm
WORKDIR /app
COPY --from=builder /app/.venv .venv/
COPY . .
CMD ["/app/.venv/bin/flask", "run", "--host=0.0.0.0", "--port=8080"]
Replace the last line (CMD) with the actual command to run your app or service.
Cheers,
- Daniel