# Dockerfile for Flutter project - builds from source using a Ubuntu base image FROM ubuntu:jammy-20260217 as builder ENV DEBIAN_FRONTEND=noninteractive # Install required system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ git \ unzip \ xz-utils \ zip \ ca-certificates \ && rm -rf /var/lib/apt/lists/* # Install Flutter SDK (stable) by cloning the repository WORKDIR /opt RUN git clone -b stable https://github.com/flutter/flutter.git ENV FLUTTER_ROOT=/opt/flutter ENV PATH="$FLUTTER_ROOT/bin:$FLUTTER_ROOT/bin/cache/dart-sdk/bin:$PATH" # Copy the source code and fetch/build dependencies WORKDIR /workspace COPY . . # Get Dart/Flutter dependencies and run tests to validate the build RUN flutter pub get RUN flutter test # Runtime image FROM ubuntu:jammy-20260217 as runtime ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ git \ unzip \ xz-utils \ zip \ ca-certificates \ && rm -rf /var/lib/apt/lists/* WORKDIR /workspace # Copy Flutter SDK from builder and set PATH COPY --from=builder /opt/flutter /opt/flutter ENV FLUTTER_ROOT=/opt/flutter ENV PATH="$FLUTTER_ROOT/bin:$FLUTTER_ROOT/bin/cache/dart-sdk/bin:$PATH" # Copy the project files from the builder stage COPY --from=builder /workspace /workspace # Default to a shell in the final image; user can run flutter commands as needed CMD ["/bin/bash"]
# Flutter/Ddart project ignore rules for Docker build # Git repository .git/ # Dart/Flutter tooling caches .dart_tool/ .packages .pub-cache/ .pub-cache # Build outputs build/ example/.dart_tool/ example/.pub-cache/ # Dependency lock files pubspec.lock **/pubspec.lock # IDE files *.iml .idea/ .vscode/ .DS_Store # Local environment files .env
Concerns: The build stage runs flutter pub get and flutter test during image build; if the repository isn't a standalone Flutter project (pubspec.yaml not at /workspace), the build may fail., The base image tag ubuntu:jammy-20260217 may not exist in all registries or could be outdated; consider pinning to a stable, widely available tag like ubuntu:22.04 for reproducibility., Some Flutter/Linux dependencies required for headless tests or plugins may be missing (e.g., libgtk-3-dev, libnss3, etc.); if tests rely on native tooling, the build could fail in minimal environments. Smoke [PASS]: flutter --version Smoke [PASS]: ls -la /workspace Smoke [PASS]: ls -la /opt/flutter/bin