CIsForCookies
CIsForCookies

Reputation: 12807

Cant access a flask server listening on 0.0.0.0:5000 inside a docker that specifies "EXPOSE 5000"

My dockerized flask server can't be reached from my host machine.

The server is running on 0.0.0.0:5000 and the Dockerfile specifies EXPOSE 5000, but I still can't reach it using curl 127.0.0.1:5000/endpoint [curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused]

. When running the server on the host directly, I can reach it with the same curl command...


Dockerfile

FROM alpine:latest

COPY requirements.txt server.py ./

RUN apk add python3 && \
    apk add py3-pip && \
    pip install -r requirements.txt

EXPOSE 5000

CMD ["python3", "server.py"]
~                           

server.py

...
if __name__ == '__main__':
    app.run(
        host='0.0.0.0',
        port=5000,
    )  
      

Upvotes: 1

Views: 996

Answers (1)

Gustavo Kawamoto
Gustavo Kawamoto

Reputation: 3067

You're probably not binding the port 5000 when you're running your container instance. Keep in mind that EXPOSE does not bind automatically the ports when you run the container, it's just a hint of what should be exposed.

Upvotes: 1

Related Questions