带有 Flutter web 的本地主机无法使用 docker

Localhost with Flutter web not working with docker

我试图 运行 一个 flutter web 应用程序,但我 运行 在 localhost 中看不到它。 我有一条 运行ning 消息,但我在浏览器中看不到它。

dashboard_1 | lib/main.dart is being served at http://localhost:8080

Docker 文件

FROM cirrusci/flutter AS build

RUN apt update && apt install -y nginx

RUN flutter channel beta
RUN flutter upgrade
RUN flutter config --enable-web

RUN mkdir /app/
COPY . /app/
WORKDIR /app/
RUN flutter build web

docker-compose.yml

version: '3.1'
services:
    dashboard:
        build: .
        restart: on-failure
        ports:
            - "8080:8080"
        command: >
            sh -c "flutter pub get && flutter run -d web-server --web-port 8080"

我刚刚在 docker-compose.yml 命令的末尾添加了 --web-hostname 0.0.0.0,它起作用了。但是 localhost:8080 现在是 0.0.0.0:8080.

所以 docker-compose.yml 看起来像这样:

version: '3.1'
services:
    dashboard:
        build: .
        restart: always
        ports:
            - "8080:8080"
        command: >
            sh -c "flutter pub get && flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0"