Riddhi Dubey
Riddhi Dubey

Reputation: 31

How should be a dockerfile for a flutter project

I was trying to containerized my flutter project and wanted to make a docker file for the same could anyone help me doing this.

Upvotes: 2

Views: 4233

Answers (1)

Yasharth Dubey
Yasharth Dubey

Reputation: 509

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.

Upvotes: 5

Related Questions