4

I have to "dockerize" a service I'm writing (a small Flask app). This is what I wrote:

FROM python:3

RUN apt-get update && apt-get install -y build-essential

WORKDIR /app

COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt

COPY . /app

EXPOSE 5000

ENV FLASK_APP=app.py
ENV FLASK_DEBUG=1

CMD flask run

I can build the image and run the container with

docker run -p 5000:5000 <container-name>

and flask tells me it's listening on 127.0.0.1:5000. But I can't access the application from my host machine. I've also tried using the localhost and 0.0.0.0 as the address. However, if I exec into the container I can curl the address to receive the response I expect.

Does anyone know what's going on here?

davidism
  • 121,510
  • 29
  • 395
  • 339
gardenhead
  • 2,299
  • 2
  • 19
  • 17

1 Answers1

0

The EXPOSE instruction does not actually publish the port. You also have to also tell docker to forward connections to that port. When running you would do docker run -p 80:5000 my_docker_image and then traffic inbound on port 80 will be forwarded to port 5000 within the docker container. Alternatively you could forward port 5000 to 5000 in the docker image if you don't want to listen on port 80.