gpt4 book ai didi

Docker - Flutter Web 部署 - 无法访问站点

转载 作者:行者123 更新时间:2023-12-02 18:27:40 24 4
gpt4 key购买 nike

我正在使用 Docker 和 Flutter Web。我刚刚完成了 Docker 和 Compose 的设置。
我的 Dockerfile

FROM ubuntu:18.04

ARG PROJECT_DIR=/srv/api
ENV PATH=/opt/flutter/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

RUN apt-get update && \
apt-get install -y \
xz-utils \
git \
openssh-client \
curl && \
apt-get upgrade -y && \
rm -rf /var/cache/apt

RUN curl -L https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_v1.7.8+hotfix.4-stable.tar.xz | tar -C /opt -xJ

RUN apt-get install -y lib32stdc++6

WORKDIR ${PROJECT_DIR}
COPY ./ ./

RUN flutter doctor
RUN flutter upgrade
RUN flutter packages pub global activate webdev
RUN flutter packages upgrade

我的 docker-compose.yaml
version: '3.1'
services:
api:
container_name: flutter-web-test
restart: always
image: flutter-web-test
build:
context: ./
volumes:
- //var/run/docker.sock:/var/run/docker.sock
command: ["flutter", "pub", "global", "run", "webdev", "serve", "web:5001"]

执行后 docker-compose -f docker-compose.yaml builddocker-compose -f docker-compose.yaml up ,我收到那个服务器应该是起来了。
flutter-web-test | web

flutter-web-test | [WARNING] Throwing away cached asset graph due to Dart SDK update.


flutter-web-test | [INFO] Cleaning up outputs from previous builds. completed, took 76ms

flutter-web-test | [INFO] Building new asset graph completed, took 2.5s

flutter-web-test | [INFO] Checking for unexpected pre-existing outputs. completed, took 2ms

flutter-web-test | [INFO] Serving `web` on http://127.0.0.1:5001

但是,当我尝试连接到 http://127.0.0.1:5001 时- 我看到了 This site cannot be reached window 。

如果我在本地运行它,它工作得很好。我相信我一定在 Docker 中跳过了一些东西,但找不到问题。任何人都可以帮助发现问题?

最佳答案

webdev服务器应该监听 0.0.0.0 像这样answer .

服务 ports 应该映射到主机和 docker守护进程路径应该是 /var/run/docker.sock :

version: '3.1'
services:
api:
container_name: flutter-web-test
restart: always
image: flutter-web-test
ports:
- "5001:5001"
build:
context: ./
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: ["flutter", "pub", "global", "run", "webdev", "serve", "--hostname", "0.0.0.0:5001"]

关于Docker - Flutter Web 部署 - 无法访问站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57751058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com