Wanted to turn my python script into api using Docker.
This is what the Dockerfile looks like:
FROM python:3.9-slim
WORKDIR /app
RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git \
&& apt-get install poppler-utils -y \
&& apt-get -y install tesseract-ocr \
&& apt-get update \
&& apt-get install ffmpeg libsm6 libxext6 -y \
&& apt-get install default-libmysqlclient-dev -y \
&& rm -rf /var/lib/apt/lists/*
COPY . .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
Docker build container just fine. It is running
No errors within the Docker:
Did anyone run into similar problem? I am new to Docker and might've missed something obvios, sorry.
I tried adding port manually http://0.0.0.0:80/ and http://0.0.0.0:80/Docs but nothing shows up.
I build similar project with exactly same parameters but this one doesn't work.
CodePudding user response:
What your program is showing you is what address it has bound to. 0.0.0.0 means that it'll accept connections from anywhere and 0.0.0.0 isn't the actual address you need to talk to to reach your program.
You've mapped port 80 in the container to port 80 on the host, so you should be able to reach your program at
http://localhost:80/
. Since port 80 is the default for http, you can also just usehttp://localhost/
.