GithubHelp home page GithubHelp logo

matsp / docker-flutter Goto Github PK

View Code? Open in Web Editor NEW
262.0 15.0 89.0 52 KB

flutter docker image with full android sdk

Home Page: https://hub.docker.com/repository/docker/matspfeiffer/flutter

License: MIT License

Dockerfile 93.11% Shell 6.89%
flutter android-sdk docker

docker-flutter's Introduction

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.

Supported tags

Entrypoints

  • flutter (default)
  • flutter-android-emulator
  • flutter-web

Dependencies

When you want to run the flutter-android-emulator entrypoint your host must support KVM and have xhost installed.

flutter (default)

Executing e.g. flutter help in the current directory (appended arguments are passed to flutter in the container):

docker run --rm -e UID=$(id -u) -e GID=$(id -g) --workdir /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:

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

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:

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

flutter-web

You app will be served on localhost:8090:

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

VSCode devcontainer

You can also use this image to develop inside a devcontainer in VSCode and launch the android emulator or web-server. The android emulator need hardware acceleration, so their is no best practice for all common operating systems.

Linux #1 (X11 & KVM forwarding)

For developers using Linux as their OS I recommend this approach, because it's the overall cleanest way.

Add this .devcontainer/devcontainer.json to your VSCode project:

{
  "name": "Flutter",
  "image": "matspfeiffer/flutter",
  "extensions": ["dart-code.dart-code", "dart-code.flutter"],
  "runArgs": [
    "--device",
    "/dev/kvm",
    "--device",
    "/dev/dri:/dev/dri",
    "-v",
    "/tmp/.X11-unix:/tmp/.X11-unix",
    "-e",
    "DISPLAY"
  ]
}

When VSCode has launched your container you have to execute flutter emulators --launch flutter_emulator to startup the emulator device. Afterwards you can choose it to debug your flutter code.

Linux #2, Windows & MacOS (using host emulator)

Add this .devcontainer/devcontainer.json to your VSCode project:

{
  "name": "Flutter",
  "image": "matspfeiffer/flutter",
  "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:

adb tcpip 5555

In your docker container connect to device:

adb connect host.docker.internal:5555

You can now choose the device to start debugging.

FAQ

Why not using alpine?

Alpine is based on musl instead of glibc. The dart binaries packaged by flutter are linked against glibc so the Flutter SDK is not compatible with Alpine - it's possible to fix this but not the core attempt of this image.

Why OpenJDK 8?

With higher versions the sdkmanager of the android tools throws errors while fetching maven dependencies.

docker-flutter's People

Contributors

jeremylwright avatar jjrbfi avatar matsp avatar offlinehacker avatar x29a avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-flutter's Issues

Connecting to device on windows [help wanted]

Hello,

I'm using the .devcontainer alternative on windows, but I can't connect to device wirelessly.

I have tried commands below - these doesn't work me.

ip=...
port=...
adb kill-server
# ...application running on port 5037
adb tcpip 5555
# error: no devices/emulators found
adb connect "${ip}"
# failed to connect to '$ip:$port': Connection refused
adb devices
# No devices detected.
#
# Wireless debugging on android 11
adb pair "${ip}:${port}"
# Successfully paired
adb devices
# No devices detected.

Have you any idea for me? Thank you in advance!

If development softwares installed on system (platform tools, etc.), I can connect

Run on usb device

Hey this is very cool, thanks for sharing! I want to introduce a completely dockerized Flutter development environment in my team to avoid reproducibility issues, but the Flutter setup is very convoluted and I'm very new to Flutter and Android in general too so it's taking a while to figure out 100%.

  • How do you run this on a USB-connected device? I had some luck with --privileged previously but not with your setup for some reason
  • Why not run from the official cirrusci/flutter images? They are built automatically by the Flutter team's CI/CD, so the version maintenance would be offloaded to them. This could be just a "frontend" script that developers add to their $PATH after which they can transparently run flutter normally
  • Any thoughts on silencing the inevitable warning when you switch between Flutter SDKs?
Warning! This package referenced a Flutter repository via the .packages file that is no longer available. The repository from which the 'flutter' tool is currently executing will be used instead.
  running Flutter tool: /home/fabio/bin/flutter
  previous reference  : /opt/flutter
This can happen if you deleted or moved your copy of the Flutter repository, or if it was on a volume that is no longer mounted or has been mounted at a different location. Please check your system path to verify
that you are running the expected version (run 'flutter --version' to see which flutter is on your path).

Error response from daemon: failed to create endpoint goofy_bose on network bridge

[yakforward@yoga-720 ~]$ docker run --rm -e UID=$(id -u) -e GID=$(id -g) --workdir /project -v "$PWD":/project matspfeiffer/flutter help
Unable to find image 'matspfeiffer/flutter:latest' locally
latest: Pulling from matspfeiffer/flutter
345e3491a907: Pull complete 
57671312ef6f: Pull complete 
5e9250ddb7d0: Pull complete 
2437fd993f4e: Pull complete 
c74700b53db4: Pull complete 
fd09fa3a0b09: Pull complete 
ebaea4b7ea43: Pull complete 
e3f34dfafdaa: Pull complete 
fa85e9ac7a32: Pull complete 
f22e245db072: Pull complete 
Digest: sha256:a142e646cb12b9af997775c8a767915ccf9a7df65553ea1b1f03fbd1658ae0a6
Status: Downloaded newer image for matspfeiffer/flutter:latest
docker: Error response from daemon: failed to create endpoint goofy_bose on network bridge: failed to add the host (veth914a077) <=> sandbox (vethabddd78) pair interfaces: operation not supported.
[yakforward@yoga-720 ~]$ docker --version
Docker version 20.10.8, build 3967b7d28e
                     ./o.                  yakforward@yoga-720 
                   ./sssso-                ------------------- 
                 `:osssssss+-              OS: EndeavourOS Linux x86_64 
               `:+sssssssssso/.            Host: 80X6 Lenovo YOGA 720-13IKB 
             `-/ossssssssssssso/.          Kernel: 5.14.2-arch1-2 
           `-/+sssssssssssssssso+:`        Uptime: 1 day, 6 hours, 29 mins 
         `-:/+sssssssssssssssssso+/.       Packages: 1085 (pacman) 
       `.://osssssssssssssssssssso++-      Shell: bash 5.1.8 
      .://+ssssssssssssssssssssssso++:     Resolution: 1920x1080 
    .:///ossssssssssssssssssssssssso++:    DE: GNOME 40.4 
  `:////ssssssssssssssssssssssssssso+++.   WM: Mutter 
`-////+ssssssssssssssssssssssssssso++++-   WM Theme: Adwaita 
 `..-+oosssssssssssssssssssssssso+++++/`   Theme: Adwaita-dark [GTK2/3] 
   ./++++++++++++++++++++++++++++++/:.     Icons: Adwaita [GTK2/3] 
  `:::::::::::::::::::::::::------``       Terminal: gnome-terminal 
                                           CPU: Intel i5-7200U (4) @ 3.100GHz 
                                           GPU: Intel HD Graphics 620 
                                           Memory: 3995MiB / 7675MiB 

Omit update check by default

Hey,

what is your opinion on omitting the flutter update check on startup?

Id argue that since the container is disposed after each call, manual upgrading doesnt make any sense and the update check takes quite a while on each run.

This would also contribute towards #5 for faster container startup times.

The appropriate flag is --no-version-check (see here).

After all, the flutter upgrade call works nevertheless if people need it (e.g. for persistent containers).

Is this project abondoned?

I cannot see any updates since 6 months ago on the related repo on docker hub. Are you still maintaining this project, or I have to switch to another one?

CI/CD

Are these images also appropriate for CI/CD, you think? Basically running flutter test, flutter analyze, and flutter build.

Can't run the emulator: Exit code -11

When I run flutter emulators --launch flutter_emulator, I get the following error

The Android emulator exited with code -11 during startup
Android emulator stderr:
handleCpuAcceleration: feature check for hvf
cannot add library /home/developer/android/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so: failed
added library /home/developer/android/emulator/lib64/vulkan/libvulkan.so
cannot add library /home/developer/android/emulator/lib64/vulkan/libvulkan.so.1: full
emulator: ERROR: VkCommonOperations.cpp:537: Failed to create Vulkan instance.
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
Address these issues and try again.

Looking for ~/android/emulator/qemu/linux-x86_64/lib64/vulkan/libvulkan.so, I find that it doesn't exist. Is this a mistake?

Would it be possible to have an image based on MacOs?

I don't have a clue about all the details, and don't have any mac device to test it.
(Would it actually work to run such an image on a linux machine?)
But the images provided for github actions could provide a good starting point: https://github.com/actions/virtual-environments#available-environments
Since it seems to have most if not all of the required tools already installed (and of course much more than that): https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md

Any ideas or opinions?

running on iOS?

I'm using mac and develop my flutter app and test in iOS simulator and iOS device(via cable)

Is it possible to use docker-flutter on mac to build, run on iOS simulator or iOS device (via cable or wireless)?

[✓] Flutter (Channel stable, 2.0.6, on Mac OS X 10.15.7 19H2 darwin-x64, locale
    en)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.57.0)
[✓] Connected device (2 available)
    ! Error: sultanmyrza’s iPhone is not connected. Xcode will continue when
      sultanmyrza’s iPhone is connected. (code -13)

Anonymous volumes

I am not a Flutter expert, but Flutter writes stuff to special files and directories when installing packages and whatnot.

If one is using Docker images such as this one simultaneously with other environments (other Docker images, or a local installation) then you are not guaranteed a clean slate because you suggest -v "$PWD":/project which mirrors all files between the local environment and the container (including these special files and directories).

Shouldn't you have anonymous volumes for these special files and directories so they are not mirrored by -v "$PWD":/project?

Flutter cointainer stops if started from docker-compose

Hi Mat,

As per title, Flutter container stops when doing the following:
In VSCode, Ctrl + Shift + P, Remote-Containers: Clone Repository in Container Volume...
Choose a project to clone that has the following files under .devcontainer

  • devcontainer.json
    { "name": "Flutter", "dockerComposeFile": [ "docker-compose.flutter.yml", "docker-compose.android-container.yml" ], "service": "flutter", "workspaceFolder": "/workspace", "extensions": ["dart-code.dart-code", "dart-code.flutter"] }
  • docker-compose.flutter.yml
    version: '3.3' services: flutter: container_name: flutter image: matspfeiffer/flutter volumes: - ..:/workspace
  • docker-compose.android-container.yml
    version: '3.3' services: docker-android-x86-11.0: privileged: true ports: - '6080:6080' - '5554:5554' - '5555:5555' environment: - 'DEVICE=Nexus 7' container_name: android-container image: budtmo/docker-android-x86-11.0

Just need to wait a couple of minutes without even doing a thing and the Flutter container will stop.
I'm not sure if I'm making some mistakes, could you please enlighten me?

Thanks

The Android emulator exited with code 1 during startup

Running the command of the README

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

I got the following error

The Android emulator exited with code 1 during startup
Android emulator stderr:
Address these issues and try again.
No devices found with name or id matching 'emulator-5554

KVM permission

Hi, I'm trying to perform the following command:

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 --privileged --entrypoint flutter-android-emulator  matspfeiffer/flutter

The actual output is:

non-network local connections being added to access control list
  ╔════════════════════════════════════════════════════════════════════════════╗
  ║ A new version of Flutter is available!                                     ║
  ║                                                                            ║
  ║ To update to the latest version, run "flutter upgrade".                    ║
  ╚════════════════════════════════════════════════════════════════════════════╝


The Android emulator exited with code 1 during startup
Android emulator stderr:
ProbeKVM: This user doesn't have permissions to use KVM (/dev/kvm).
The KVM line in /etc/group is: [LINE_NOT_FOUND]

If the current user has KVM permissions,
the KVM line in /etc/group should end with ":" followed by your username.

If we see LINE_NOT_FOUND, the kvm group may need to be created along with permissions:
    sudo groupadd -r kvm
    # Then ensure /lib/udev/rules.d/50-udev-default.rules contains something like:
    # KERNEL=="kvm", GROUP="kvm", MODE="0660"
    # and then run:
    sudo gpasswd -a $USER kvm

If we see kvm:... but no username at the end, running the following command may allow KVM access:
    sudo gpasswd -a $USER kvm

You may need to log out and back in for changes to take effect.

Address these issues and try again.
Error: No pubspec.yaml file found.
This command should be run from the root of your Flutter project.
Do not run this command from the root of your git clone of Flutter.

I'm using a Linux machine, kvm and xhost are installed. Already included my host user in kvm group, but it seems this needed to be done inside the container... What I'm missing?

Getting Error while Creating a build

Command i used:

docker run --rm -e UID=$(id -u) -e GID=$(id -g) --net=host --workdir /project -v "$PWD":/project matspfeiffer/flutter build appbundle

Error:

ERR : Git error. Command: git clone --mirror https://github.com/Cretezy/flutter_cached_network_image.git /home/developer/flutter/.pub-cache/git/cache/flutter_cached_network_image-7f036d743d57f9efd52207eb3becce37cff9ace7

| stdout: 

| stderr: Cloning into bare repository '/home/developer/flutter/.pub-cache/git/cache/flutter_cached_network_image-7f036d743d57f9efd52207eb3becce37cff9ace7'...

| fatal: could not read Username for 'https://github.com': No such device or address

| exit code: 128

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.