Skip to content
This repository was archived by the owner on Oct 8, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Dockerfile.android
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG TAG
FROM matspfeiffer/flutter:$TAG

ENV JAVA_VERSION="8"
ENV ANDROID_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip"
ENV ANDROID_VERSION="29"
ENV ANDROID_BUILD_TOOLS_VERSION="29.0.3"
ENV ANDROID_ARCHITECTURE="x86_64"
ENV ANDROID_SDK_ROOT="/opt/android"
ENV FLUTTER_EMULATOR_NAME="flutter_emulator"
ENV PATH="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/platforms:$PATH"

# install all dependencies
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update \
&& apt-get install --yes --no-install-recommends openjdk-$JAVA_VERSION-jdk libglvnd0 xauth x11-xserver-utils libpulse0 libxcomposite1 libgl1-mesa-glx \
&& rm -rf /var/lib/{apt,dpkg,cache,log}

# android sdk & emulator setup
RUN mkdir -p $ANDROID_SDK_ROOT \
&& mkdir -p /root/.android \
&& touch /root/.android/repositories.cfg \
&& curl -o android_tools.zip $ANDROID_TOOLS_URL \
&& unzip -qq -d "$ANDROID_SDK_ROOT" android_tools.zip \
&& rm android_tools.zip \
&& mkdir -p $ANDROID_SDK_ROOT/cmdline-tools/latest \
&& mv $ANDROID_SDK_ROOT/cmdline-tools/bin $ANDROID_SDK_ROOT/cmdline-tools/latest/bin \
&& mv $ANDROID_SDK_ROOT/cmdline-tools/lib $ANDROID_SDK_ROOT/cmdline-tools/latest/lib \
&& yes "y" | sdkmanager --update \
&& yes "y" | sdkmanager "extras;google;m2repository" "extras;android;m2repository" \
&& yes "y" | sdkmanager "build-tools;$ANDROID_BUILD_TOOLS_VERSION" \
&& yes "y" | sdkmanager "platforms;android-$ANDROID_VERSION" \
&& yes "y" | sdkmanager "platform-tools" \
&& yes "y" | sdkmanager "system-images;android-$ANDROID_VERSION;google_apis_playstore;$ANDROID_ARCHITECTURE" \
&& flutter emulators --create

COPY flutter-android-emulator.sh /usr/local/bin/flutter-android-emulator
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

27 changes: 27 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:20.04

ARG FLUTTER_CHANNEL
ARG FLUTTER_VERSION
ENV FLUTTER_URL="https://storage.googleapis.com/flutter_infra/releases/$FLUTTER_CHANNEL/linux/flutter_linux_$FLUTTER_VERSION-$FLUTTER_CHANNEL.tar.xz"
ENV FLUTTER_HOME="/opt/flutter"
ENV PATH="$FLUTTER_HOME/bin:$PATH"

# install all dependencies
ENV DEBIAN_FRONTEND="noninteractive"
RUN apt-get update \
&& apt-get install --yes --no-install-recommends curl unzip sed git bash xz-utils ca-certificates \
&& rm -rf /var/lib/{apt,dpkg,cache,log}


# flutter
RUN curl -o flutter.tar.xz $FLUTTER_URL \
&& mkdir -p $FLUTTER_HOME \
&& tar xf flutter.tar.xz -C /opt \
&& rm flutter.tar.xz \
&& flutter config --no-analytics --enable-web \
&& flutter precache \
&& yes "y" | flutter doctor --android-licenses

COPY entrypoint.sh /usr/local/bin/
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# docker-flutter

With this docker image you don't need to install the Flutter and Android SDK on your developer machine. Everything is ready to use inclusive an emulator device (Pixel with Android 9). With a shell alias you won't recognize a difference between the image and a local installation. If you are using VSCode you can also use this image as your devcontainer.
With this container images you don't need to install the Flutter and Android SDK on your developer machine.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"With this" -> "With these"

Everything is ready to use inclusive an emulator device (Pixel with Android 9). With a shell alias you won't recognize
a difference between the image and a local installation. If you are using VSCode you can also use this image as your devcontainer.

## Recommendations

To have no file permission issues between your project and the container you should run the container rootless:

1. [Docker rootless](https://docs.docker.com/engine/security/rootless/#rootless-docker-in-docker)
2. [Podman rootless @arch](https://wiki.archlinux.org/index.php/Podman#Rootless_Podman)

## Supported tags

- [`latest`](https://github.com/matsp/docker-flutter/blob/master/stable/Dockerfile)
- [`beta`](https://github.com/matsp/docker-flutter/tree/master/beta)
- [`dev`](https://github.com/matsp/docker-flutter/tree/master/dev)
- [`latest`](https://github.com/matsp/docker-flutter/blob/master/Dockerfile.base)
- [`stable`](https://github.com/matsp/docker-flutter/blob/master/Dockerfile.base)
- [`beta`](https://github.com/matsp/docker-flutter/tree/master/Dockerfile.base)
- [`dev`](https://github.com/matsp/docker-flutter/tree/master/Dockerfile.base)
- [`stable-android`](https://github.com/matsp/docker-flutter/tree/master/Dockerfile.android)
- [`beta-android`](https://github.com/matsp/docker-flutter/tree/master/Dockerfile.android)
- [`dev-android`](https://github.com/matsp/docker-flutter/tree/master/Dockerfile.android)

## Entrypoints

- `flutter` (default)
- `flutter-android-emulator`
- `flutter-web` (beta only)

_Dependencies_

Expand All @@ -23,33 +35,29 @@ When you want to run the `flutter-android-emulator` entrypoint your host must su
Executing e.g. `flutter help` in the current directory (appended arguments are passed to flutter in the container):

```shell
docker run --rm -e UID=$(id -u) -e GID=$(id -g) --workdir /project -v "$PWD":/project matspfeiffer/flutter help
docker run --rm -w /project -v "$PWD":/project matspfeiffer/flutter help
```

When you don't set the `UID` and `GID` the files will be owned by `G-/UID=1000`.

### flutter (connected usb device)

Connecting to a device connected via usb is possible via:

```shell
docker run --rm -e UID=$(id -u) -e GID=$(id -g) --workdir /project -v "$PWD":/project --device=/dev/bus -v /dev/bus/usb:/dev/bus/usb matspfeiffer/flutter devices
docker run --rm -w /project -v "$PWD":/project --device=/dev/bus -v /dev/bus/usb:/dev/bus/usb matspfeiffer/flutter:stable-android devices
```

### flutter-android-emulator

To achieve the best performance we will mount the X11 directory, DRI and KVM device of the host to get full hardware acceleration:

```shell
xhost local:$USER && docker run --rm -ti -e UID=$(id -u) -e GID=$(id -g) -p 42000:42000 --workdir /project --device /dev/kvm --device /dev/dri:/dev/dri -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY -v "$PWD":/project --entrypoint flutter-android-emulator matspfeiffer/flutter
xhost local:$USER && docker run -ti --rm -w /project --device /dev/kvm --device /dev/dri:/dev/dri -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY -v "$PWD":/project --entrypoint flutter-android-emulator matspfeiffer/flutter:stable-android
```

### flutter-web (beta only)

You app will be served on localhost:8090:

```shell
docker run --rm -ti -e UID=$(id -u) -e GID=$(id -g) -p 42000:42000 -p 8090:8090 --workdir /project -v "$PWD":/project --entrypoint flutter-web matspfeiffer/flutter:beta
docker run --rm -ti -p 42000:42000 -p 8090:8090 -w /project -v "$PWD":/project matspfeiffer/flutter:beta run -d web-server --web-port 8090 --web-hostname 0.0.0.0 --observatory-port 42000
```

## VSCode devcontainer
Expand All @@ -65,7 +73,7 @@ Add this `.devcontainer/devcontainer.json` to your VSCode project:
```json
{
"name": "Flutter",
"image": "matspfeiffer/flutter",
"image": "matspfeiffer/flutter:stable-android",
"extensions": ["dart-code.dart-code", "dart-code.flutter"],
"runArgs": [
"--device",
Expand All @@ -89,12 +97,12 @@ Add this `.devcontainer/devcontainer.json` to your VSCode project:
```json
{
"name": "Flutter",
"image": "matspfeiffer/flutter",
"image": "matspfeiffer/flutter:stable-android",
"extensions": ["dart-code.dart-code", "dart-code.flutter"]
}
```

Start your local android emulator. Afterwards reconnect execute the following command to make it accessable via network:
Start your local android emulator. Afterwards execute the following command to make it accessable via network:

```shell
adb tcpip 5555
Expand Down
65 changes: 0 additions & 65 deletions beta/Dockerfile

This file was deleted.

5 changes: 0 additions & 5 deletions chown.sh

This file was deleted.

65 changes: 0 additions & 65 deletions dev/Dockerfile

This file was deleted.

3 changes: 0 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
# execute flutter with arguments
flutter --no-version-check "$@"


/bin/bash /usr/local/bin/chown.sh

exit
6 changes: 0 additions & 6 deletions flutter-web.sh

This file was deleted.

64 changes: 0 additions & 64 deletions stable/Dockerfile

This file was deleted.