Securing a localhost port for a Flask/Celery app running locally on 0.0.0.0 in Docker on MacOS

前端 未结 1 619

My app has a Flask backend and an Angular/Electron frontend. The app runs locally on Mac Catalina. Flask, Celery and Redis are in separate docker containers, while the frontend

相关标签:
1条回答
  • 2021-01-26 09:40

    A working solution is based on the David Maze and Matt's comments and on this question. These are the steps:

    1. Open Docker for Mac, Preferences and Docker Engine. Add "ip": "127.0.0.1" to the json config file.
    2. In the docker-compose, set ports to "127.0.0.1:5078:5078" for the web service.
    3. Leave the Dockerfile and the python code as before: ie, the flask host is still 0.0.0.0

    As I checked, messages from Electron's localhost 4201 went through. Also, running netstat -anvp tcp | awk 'NR<3 || /LISTEN/ shows that the insecure port 0.0.0.0.5078 is no longer exposed to the outside. `

    0 讨论(0)
提交回复
热议问题