问题:Dockerize Flutter Web 项目

我正在尝试对我的颤振网络项目进行码头化。并且创建了一个图像并且该站点完美运行,只是找不到我的网站的图片并且没有显示,我不知道为什么。它给了我这个错误:

172.17.0.1 - - [12/May/2022 14:25:04] "GET / HTTP/1.1" 200 -

172.17.0.1 - - [12/May/2022 14:25:04] code 404, message File not found

172.17.0.1 - - [12/May/2022 14:25:04] "GET /packages/image_cropper_for_web/src/croppie/js/croppie.css HTTP/1.1" 404 -

172.17.0.1 - - [12/May/2022 14:25:05] code 404, message File not found

172.17.0.1 - - [12/May/2022 14:25:09] "GET /assets/photos/bgfinal.png HTTP/1.1" 404 -

172.17.0.1 - - [12/May/2022 14:25:09] code 404, message File not found

Dockerfile:

FROM ubuntu:20.04

RUN apt-get update
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback lib32stdc++6 python3
RUN apt-get clean

# download Flutter SDK from Flutter Github repo
RUN git clone https://github.com/flutter/flutter.git /usr/local/flutter

# Set flutter environment path
ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}"

# Run flutter doctor
RUN flutter doctor

# Enable flutter web
RUN flutter channel master
RUN flutter upgrade
RUN flutter config --enable-web

# Copy files to container and build
RUN mkdir /app/
COPY . /app/
WORKDIR /app/
RUN flutter build web

# Record the exposed port
EXPOSE 5000

# make server startup script executable and start the web server
RUN ["chmod", "+x", "/app/server/server.sh"]

ENTRYPOINT [ "/app/server/server.sh"]

这是 server.sh 文件:

#!/bin/bash

# Set the port
PORT=5000

# Stop any program currently running on the set port
echo 'preparing port' $PORT '...'
fuser -k 5000/tcp

# switch directories
cd build/web/

# Start the server
echo 'Server starting on port' $PORT '...'
python3 -m http.server $PORT

解答

所以这就是事情。我认为他的代码存在一些问题。正如我昨天试图用他的代码构建的,但事情并没有按应有的方式工作。我花了 2 个小时处理他的代码,其中 50% 用于构建图像,但从未完成。没问题我试图修改一些东西,我在 GitHubhttps://github.com/ash-0001/fludino.git上与你分享一些代码。只是继续学习和分享。 好就是形象。

最终图像如下所示:

在此处输入图像描述

您必须使用两个命令来初始化它:在此之前使用您的 cmd 进入目录

  1. 搬运工构建 -t Flut 。

  2. 搬运工运行 -i -p 808:4040 -td Flut

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐