【问题标题】:Localhost with Flutter web not working with docker带有 Flutter web 的 localhost 无法与 docker 一起使用
【发布时间】:2021-02-19 06:08:36
【问题描述】:

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

仪表板_1 | lib/main.dart 在 http://localhost:8080 提供服务

Dockerfile

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"

【问题讨论】:

  • 如果应用程序在启动时打印出“listening on localhost”,则可能无法从容器外部访问它;您需要以某种方式重新配置它以收听(或将绑定地址设置为) 0.0.0.0 。参见例如Why 0.0.0.0 is working and localhost or 127.0.01 is not

标签: docker flutter docker-compose dockerfile flutter-web


【解决方案1】:

我刚刚在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"

【讨论】:

  • 我遇到了同样的问题。解决了。谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-07-15
  • 1970-01-01
  • 2021-09-25
  • 2020-06-16
  • 1970-01-01
  • 2018-04-09
  • 1970-01-01
  • 2019-03-04
相关资源
最近更新 更多