how to run gunicorn on docker

后端 未结 6 488
南旧
南旧 2020-12-29 08:06

I have 2 files that depend on each other when docker is start up. 1 is a flask file and one is a file with a few functions. When docker starts, only the functions file will

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 09:00

    After struggling with this issue over the last 3 days, I found that all you need to do is to bind to loopback rather than localhost:

    CMD ["gunicorn" , "--bind", "0.0.0.0:8000", "app:app"]

    And don't forget to expose the port, one option to do that is to use EXPOSE in your Dockerfile:

    EXPOSE 8000
    

    Now:

    docker build -t test .
    

    Finally you can run:

    docker run -d -p 8000:8000 test
    

提交回复
热议问题