I am trying to deploy flutter web application in docker.
For this I created a base image.
Dockerfile:
ARG FLUTTER_DIR=/opt/flutter-sdk
FROM debian:12.8-slim as builder
ARG FLUTTER_DIR
RUN apt-get update
RUN apt-get install -y curl git unzip xz-utils zip libglu1-mesa wget
RUN apt-get clean
ARG ARCHIVE_DIR=/opt/flutter-archive
RUN mkdir ${ARCHIVE_DIR}
RUN mkdir ${FLUTTER_DIR}
COPY flutter_linux_3.24.5-stable.tar.xz ${ARCHIVE_DIR}
RUN tar -xf ${ARCHIVE_DIR}/flutter_linux_3.24.5-stable.tar.xz -C ${FLUTTER_DIR}
FROM debian:12.8-slim
ARG FLUTTER_DIR
RUN apt-get update
RUN apt-get install -y curl git unzip xz-utils zip libglu1-mesa wget
RUN apt-get clean
RUN mkdir ${FLUTTER_DIR}
COPY --from=builder ${FLUTTER_DIR} ${FLUTTER_DIR}
ENV PATH="/opt/flutter-sdk/flutter/bin:${PATH}"
RUN git config --global --add safe.directory /opt/flutter-sdk/flutter
RUN flutter config --enable-web
RUN flutter doctor -v
RUN flutter channel master
RUN flutter upgrade
I build this image with name debian-with-flutter:3.24.5
to local docker.
Next, I use the base image to deploy the web application.
Dockerfile:
FROM debian-with-flutter:3.24.5 as build-env
ENV PATH="/opt/flutter-sdk/flutter/bin:${PATH}"
ARG DIR=/opt/app
RUN mkdir ${DIR}
COPY . ${DIR}
WORKDIR ${DIR}
RUN git config --global --add safe.directory /opt/flutter-sdk/flutter
RUN flutter config --list
### error here
RUN flutter build web --web-renderer canvaskit
FROM nginx:stable-alpine3.20
COPY --from=build-env /opt/app/build/web /usr/share/nginx/html
EXPOSE 80
But the second image build ends with an error.
Log from docker:
RUN flutter build web --web-renderer canvaskit
Woah! You appear to be trying to run flutter as root.
We strongly recommend running the flutter tool without superuser privileges.
Could not find an option named "--web-renderer".
Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and options.
Yes, I know that For a default build, Flutter chooses the canvaskit renderer at runtime.
But the error itself is surprising and I want to understand why it occurred.
It seems that the argument --web-renderer
is no longer available in flutter. Based on the Web renderers, I think it is replaced by --wasm
and --no-wasm
arguments.
I also noticed that the argument --web-renderer
is ignored in flutter-gh-pages work flow when building for flutter 3.29.0 and above.