1

I have an API written in Flask that's running in 127.0.0.1:3001. I have it running inside a docker container, and I'd like to know how I can request this API.

Below is my Dockerfile

FROM python:3
WORKDIR /app
ADD requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
ADD . /app
EXPOSE 3001
CMD ["python", "wsgi.py"]

Thanks in advance.

  • 1
    Where exactly is your process running? ("On localhost" isn't particularly meaningful, since every computer and every Docker container individually believes it is "localhost".) How are you trying to connect to it, from where? What error are you getting? What does the Flask code look like? Given only this description you could be hitting [Deploying a minimal flask app in docker - server connection issues](https://stackoverflow.com/questions/30323224/deploying-a-minimal-flask-app-in-docker-server-connection-issues)? – David Maze Feb 03 '22 at 11:42
  • Try `docker run -d -p 3001:3001 ` then open the url http://localhost:3001/` – Max Feb 05 '22 at 11:54
  • @Max Thanks for the reply, this doesn't work sadly, I'm still unable to make requests to my API running inside a docker container. All processes are running in my local machine, so if I run my API normally I am able to request it through 127.0.0.1:3001, so I'm wondering how I can do the same while my API is running in a docker container (container is running in my machine only) – BreadBoard.ini Feb 10 '22 at 00:50

0 Answers0