Search code examples
dockerflask

Can't connect to a Flask application from inside an container


I have a flask application running in a Dev Container by running the following command:

flask run --host=0.0.0.0 --port=3000 --debug

And the application runs fine on the browser by accessing http://localhost:3000, however when trying to access through the internal ip that my docker has (http://172.17.0.1:3000) while inside another container I cannot access at all.

I am guessing that flask is not binding truly to 0.0.0.0 since I can't access the application through my local ip (192.168.1.20) and through docker's ip (172.17.0.1).

The output while starting the debug server is:

flask run --host=0.0.0.0 --port=3000 --debug
 * Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:3000
 * Running on http://172.17.0.2:3000
Press CTRL+C to quit

How can I fix this?


Solution

  • I have added the Dev container generated by vscode to my other container's network by adding the following to my devcontainer.json:

    "runArgs": [
            "--network=supre_default",
            "--name=forecast_python"
        ]
    

    Now I can connect to the Devcontainer inside another container using curl http://forecast_python:3000