Cannot GET request to flask app localhost in Docker container

Cannot GET request to flask app localhost in Docker container

Problem Description:

i have simple app packed in container

app = Flask(__name__)

def health():
    return {"health_status": "running"}, 200

class StandaloneApplication(
    def __init__(self, flask_app, gunicorn_options=None):
        self.options = gunicorn_options or {}
        self.gunicorn_app = flask_app

    def load_config(self):
        config = {key: value for key, value in self.options.items()
                  if key in self.cfg.settings and value is not None}
        for key, value in config.items():
            self.cfg.set(key.lower(), value)

    def load(self):
        return self.gunicorn_app

if __name__ == "__main__":
    options = {
        'bind': ['', ''],
        'workers': 1,
        "timeout": 60
    StandaloneApplication(app, options).run()"Server started")

The container with app running successfully

CONTAINER ID   IMAGE       COMMAND           CREATED              STATUS              PORTS                            NAMES
28a8152aa90f   embs:embs   "python"   About a minute ago   Up About a minute   8080/tcp,>80/tcp   determined_galois

[2022-12-06 12:48:59 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2022-12-06 12:48:59 +0000] [1] [INFO] Listening at:, (1)
[2022-12-06 12:48:59 +0000] [1] [INFO] Using worker: sync
[2022-12-06 12:48:59 +0000] [15] [INFO] Booting worker with pid: 15

When i try


I got

curl: (52) Empty reply from server

when i use requests

url = ''

I got requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

How can request flask app in Docker properly ?

Solution – 1

You need to publish the 8080 port.
Currently, you have 8080/tcp,>80/tcp but this configuration is the 8080 port inside the container is published on port 80 from local machine.

You need 8080/tcp,>8080/tcp (and same with 8090), add -p 8080:8080 to docker run command and check with docker ps.

Another detail, you can use localhost or for get, is not recommended.

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.