我正在使用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 build
和docker-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
窗口。
如果我在本地运行它,它工作得很好。我相信我一定跳过了 Docker 中的某些内容,但找不到问题。任何人都可以帮助发现问题吗?
webdev
服务器应该像这样的答案0.0.0.0
监听。
服务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-compose 文件中缺少端口
version: '3.1'
services:
api:
container_name: flutter-web-test
restart: always
image: flutter-web-test
port:
- "5001":"5001"
build:
context: ./
volumes:
- //var/run/docker.sock:/var/run/docker.sock
command: ["flutter", "pub", "global", "run", "webdev", "serve", "web:5001"]