31

I've setup a docker ubuntu 14.04 image and I'm running it with the following command:

docker run -d -p 5000:5000 ari/python3-flask

The Dockerfile:

FROM ubuntu:14.04
RUN apt-get update && apt-get install -y python3 python3-pip
ADD . /var/my_app
RUN pip3 install -r /var/my_app/requirements.txt
EXPOSE 5000
CMD ["python3", "/var/my_app/runserver.py"]

However, if I attempt to curl the address (localhost:5000) or visit it in a browser I get a connection failed error.

The docker log for the container shows:

Running on http://127.0.0.1:5000/

Restarting with reloader

Does anyone what is or could be wrong with my docker setup and/or configuration? Thanks.

Ari
  • 4,121
  • 8
  • 40
  • 56
  • post your Dockerfile, do you use a real docker or a boot2docker (win or macos) in your case ? – Dragu Oct 17 '14 at 11:41
  • what does the `docker logs ` show? – Thomasleveil Oct 17 '14 at 14:15
  • @Dragu: I use a real docker. – Ari Oct 17 '14 at 15:27
  • BTW, if you want to deploy your app in Docker without having to learn, install and configure uWSGI, Nginx and Supervisord (to get the best performance and robustness), you may want to check this image: https://hub.docker.com/r/tiangolo/uwsgi-nginx-flask/ – tiangolo Feb 20 '16 at 16:00

1 Answers1

75

The web server running in your container is listening for connections on port 5000 of the loopback network interface (127.0.0.1). As such this web server will only respond to http requests originating from that container itself.

In order for the web server to accept connections originating from outside of the container you need to have it bind to the 0.0.0.0 IP address.

As you are using Flask, this can be easily achieved in your runserver.py file by using:

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

Then when you start your container and look at the log, you should see something like:

 * Running on http://0.0.0.0:5000/
Thomasleveil
  • 95,867
  • 15
  • 119
  • 113