Docker not mapping port using gunicorn

混江龙づ霸主 提交于 2019-12-10 17:36:25

问题


I'm running gunicorn inside a docker container. I know this works because sshing into it and curling localhost:8000/things in docker container gives me the response I want, however, I am not able to reach this on my host, despite docker telling me the port has been mapped. What gives?

I ran

docker run -d -p 80:8000 myapp:version1.1 /bin/bash -c 'gunicorn things:app'

docker ps gives me

CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                            NAMES
614df1f2708e        myapp:version1.1  "/bin/bash -c 'gunico"   6 minutes ago       Up 6 minutes        5000/tcp, 0.0.0.0:80->8000/tcp   evil_stallman

On my host, curling locahost/things gives me

curl: (52) Empty reply from server

However, when I docker exec -t -i 614df1f2708e /bin/bash and then curl localhost:8000/things, I succesfully get my correct response.

Why isn't docker mapping my port 8000 correctly?


回答1:


When you publish a port, Docker will forward requests into the container, but the container needs to be listening for them. The container has an IP address from the Docker network, and your app needs to be listening on that address.

Check your gunicorn bind setting - if it's only listening on 127.0.0.1:8000 then it's not binding to the container's IP address, and won't get requests from outside. 0.0.0.0:8000 is safe as it will bind to all addresses.



来源:https://stackoverflow.com/questions/39780422/docker-not-mapping-port-using-gunicorn

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!