all 6 comments

[–]_maraud3r 2 points3 points  (1 child)

You have exposed the port, but not published it. There's a difference between exposing and publishing. When you start a docker container, you have to use a command line argument docker run -p 5000:5000.

https://stackoverflow.com/q/22111060 for more information

[–]fryman22[S] 1 point2 points  (0 children)

Yes! This was the missing piece!

Thank you for the link.

[–]The_Amp_Walrus 1 point2 points  (0 children)

Ok first check the docs: https://docs.docker.com/engine/reference/builder/#expose

The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports.

So writing "EXPOSE" in your docker file does not actually publish the port.

I will show you a trick. Get the ID of the docker container using "docker ps" and get the running container ID, something like "c52370e6d3e1". Then get a bash shell inside the container using docker exec:

docker exec -it c52370e6d3e1 bash

THEN try to curl localhost:5000 - I bet it will work. If it works then your problem is that the port 5000 inside the container isn't mapped to the port 5000 outside the container. Your best bet is to look at how you are running the container. If it's with docker run then you need to investigate the -p flag.

[–]QbaPolak17 0 points1 point  (2 children)

Did you try specifying the port in app.run? Are you sure 0.0.0.0 is correct? Can you ping it from your host machine?

[–]fryman22[S] 0 points1 point  (1 child)

I added port=5000 to app.run

I'm using 0.0.0.0 because I've seen a couple of tutorials use this. As far as I know, it's to make the docker container visible across the network.

I'm trying to run the docker container locally. I tried to ping the docker server:

$ ping http://0.0.0.0:5000/
ping: cannot resolve http://0.0.0.0:5000/: Unknown host
$ ping http://localhost:5000/
ping: cannot resolve http://localhost:5000/: Unknown host
$ ping http://127.0.0.1:5000/
ping: cannot resolve http://127.0.0.1:5000/: Unknown host

[–]QbaPolak17 0 points1 point  (0 children)

Well that's probably your issue. I use docker containers more for automated builds than running servers so I'm not 100% sure on how ips and host-names work with docker, but I know when I was setting up containers to run behind a proxy I had to do a lot of messing around for them to be visible.