I have a following falcon API in python:
import falcon
class Ping:
def on_get(self, req, resp):
resp.status = falcon.HTTP_OK
app = application = falcon.App()
app.add_route("/exp_costs/v1/healthcheck", Ping())
My Dockerfile looks like this:
FROM python:3.10
COPY requirements.txt .
RUN apt update && \
pip install gunicorn && \
pip install --python --no-cache-dir -r requirements.txt
# Copy the rest of the application code into the container
COPY . /app
EXPOSE 8000
USER nobody:nogroup
WORKDIR /app
# Command to run your Falcon API (adjust as needed)
CMD ["gunicorn", "app", "--bind", ":8000"]
My steps:
sudo docker build -t costs_expedice .
sudo docker run -it -p 8099:80 costs_expedice
and I can see this in the terminal:
wget http://localhost:8099//exp_costs/v1/healthcheck
but I got repeated message:
--2023-08-29 14:17:36-- http://localhost:8099//exp_costs/v1/healthcheck Resolving localhost (localhost)... 127.0.0.1 Connecting to localhost (localhost)|127.0.0.1|:8099... connected. HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers. Retrying.
Whats the problem please?
First, your Dockerfile exposes 8000 and sets it as gunicorn bind port, but your docker run command binds to port 80 of container and your wget
command has a typo with an extra "/" after port spec of 8099. Then your CMD
is also malformed that gunicorn expects an option of the form <module>:<object>
like main:app
if your module is named as main.py
. You can check options of gunicorn with gunicorn --help
to refine your CMD
further.