Home > other >  Cannot access Flask app running in container from macOS M1 local host machine
Cannot access Flask app running in container from macOS M1 local host machine

Time:10-10

I am trying to run a simple Flask app in a container from my Apple Silicon macOS. However, I am unable to access the started Flask app (app starts without issues inside container) from the mac host at localhost:5000.

Can someone please help with this. I tried other solutions online but none worked. Can this be an issue with Mac and Docker?

docker-compose.yml file is:

version: '3'

services:
  basic_app:
    build:
        context: .
        dockerfile: Dockerfile
    #network_mode: host -> not needed
    ports:
      - "5000:5000"
    command: bash -c "flask run --host=0.0.0.0 --port=5000"

CodePudding user response:

network_mode: host doesn't work on MacOS, and should almost never be necessary in general. Delete that line.

Trying to enable host networking on Docker Desktop setups will prevent this application from working, even though you've checked the other boxes (server process listening on 0.0.0.0, published ports:). You should get a warning that ports: and host networking are incompatible, because host networking is an instruction to disable Docker's networking layer.

(Technically the process is running on the host network of a hidden Linux VM, but without the ports: wiring functioning, you can't access it from the MacOS host.)

  • Related