'Dockerize flutter web project

I'm trying to dockerize my flutter web project. And an image was created and the site run perfectly just the pictures of my website are not found and not displayed and I don't know why.it gave me this error :

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"]

this is server.sh file:

#!/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


Solution 1:[1]

So here is the thing. I think there are some problems with his code. As I tried to build with his code yesterday but things weren't working as they should be. I spend 2hours with his code of which 50% was spent on building the image but it was never completed. No problem I tried to modify some things and I am sharing some code with you on GitHub https://github.com/ash-0001/fludino.git. Just keep learning and sharing. Good Is Image.

The final image looks like this:

enter image description here

You have to use two commands to initialize this: Before that move into the directory with your cmd

  1. docker build -t flut .
  2. docker run -i -p 808:4040 -td flut

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1