Setup Flutter By Docker, without using IDE

In this article, I want to explain how to use Flutter commands by docker image without download Dart SDK directly, in other words, use Flutter commands without IDE.

Before reading more, you should have basic knowledge about Docker and know about DockerFile, Docker Image, Docker Container.

In this simple example, I’ll build an APK for a flutter mobile application, by using Flutter commands in Docker container.

Requirements

In the first step, I add a DockerFile to the root of the project. It’ll download all requirements of your project like Dart SDK, Java dependencies and etc.

Second, I add a docker-compose.yml file to the root of the project. It will manage all docker operation.

NOTE: You can edit these docker files as your project.

Usage

Now by this command, you can run a docker-compose file and it will use DockerFile to download all dependencies and create your docker image and docker container, it will take a long time for the first time.

docker-compose up — build

After it’ll finish successfully you can see Flutter docker image in your images by this command:

docker images

as you can see in the above picture, our image size is more than 2GB, it means it downloaded SDK successfully.

and check out docker container:

docker container ls

NOTE: You build a docker image once and every time you want to use it, you just create a docker container from that.

Now its time to use our docker container, before I check flutter command to show that I can’t use flutter command yet :

so I should execute the flutter container by its id or name:

docker exec -it [CONTAINER ID] bash

or

docker exec -it myapp bash

and you are in your project without download SDK directly.

so check flutter command again:

congratulation, you setup Flutter by docker without using IDE.

NOTE: You can use this way to build APK on server-side, without using AndroidStudio.

NOTE: For having an updated version of Flutter, you can use :

flutter upgrade

GitHub repository

DockerHub repository

LinkedIn

please share your idea, thanks.

Senior Flutter Developer