How should be a dockerfile for a flutter project
1,082
I found the way to make a docker file for the flutter project which is something like this.
FROM ubuntu:18.04
# Prerequisites
RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget
# Set up new user
RUN useradd -ms /bin/bash developer
USER developer
WORKDIR /home/developer
# Prepare Android directories and system variables
RUN mkdir -p Android/sdk
ENV ANDROID_SDK_ROOT /home/developer/Android/sdk
RUN mkdir -p .android && touch .android/repositories.cfg
# Set up Android SDK
RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools.zip && rm sdk-tools.zip
RUN mv tools Android/sdk/tools
RUN cd Android/sdk/tools/bin && yes | ./sdkmanager --licenses
RUN cd Android/sdk/tools/bin && ./sdkmanager "build-tools;29.0.2" "patcher;v4" "platform-tools" "platforms;android-29" "sources;android-29"
ENV PATH "$PATH:/home/developer/Android/sdk/platform-tools"
# Download Flutter SDK
RUN git clone https://github.com/flutter/flutter.git
ENV PATH "$PATH:/home/developer/flutter/bin"
# Run basic check to download Dark SDK
RUN flutter doctor
this should be your dockerfile inside a flutter-docker folder then create a folder workspace in which you can run your project without any problem.
then create a dockerignore file and mention what are the things you want to ignore like packages and other things.
now make a dev folder and create a file named devcontainer with below code in it.
{
"name": "flutter_docker",
"context": "..",
"dockerFile": "../Dockerfile",
"remoteUser": "developer",
"settings": {
"terminal.integrated.shell.linux": null
},
"runArgs": ["--privileged"],
"extensions": ["dart-code.flutter"],
"workspaceMount": "source=${localWorkspaceFolder}/workspace,target=/home/developer/workspace,type=bind,consistency=delegated",
"workspaceFolder": "/home/developer/workspace"
}
and you can run your flutter program in the same.
Author by
Riddhi Dubey
Updated on December 28, 2022Comments
-
Riddhi Dubey over 1 year
I was trying to containerized my flutter project and wanted to make a docker file for the same could anyone help me doing this.
-
Ben Butterworth over 2 yearsCould you explain the motivation for using a dev container for Flutter? It may reduce the developer experience and increase maintainance cost. I can only see 1 reason - to set up the android environment consistently between developers - which IMHO is not a good reason.
-
Ben Butterworth over 2 yearsI think your dockerfile introduces more issues: which android studio do you use to run the emulator? - Ah, can you even run the emulator? - How does a developer using Android Studio / IntelliJ Idea use your devcontainer (they can't, it's a VSCode concept). - on macOS, docker can take a lot of "empty" space on your computer - developers have to update this dockerfile with the latest sdktools URL when it gets updated. - You are inadvertently using the master by cloning the repository of Flutter.
-
Dean Villamia about 2 yearsThanks for this ^ ben, been looking into having/seeing if its beneficial for a flutter app to be dockerized. Big help!