Dockerize flutter web 项目

Dockerize flutter web project

我正在尝试对我的 flutter web 项目进行 docker 化。并创建了一张图片,网站 运行 完全没有找到和显示我网站的图片,我不知道 why.it 给我这个错误:

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

Docker 文件:

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% 用于构建图像,但从未完成。没问题,我试着修改了一些东西,我在 GitHub https://github.com/ash-0001/fludino.git 上与你分享了一些代码。继续学习和分享。 形象好。

最终图像是这样的:

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

进入目录
  1. docker build -t flut .
  2. docker 运行 -i -p 808:4040 -td flut