(This image was created with the assistance of DALL·E 3)
-
Install Template
$ git clone https://github.com/liuyuweitarek/flutter-docker-template.git
Replaced the project name with your own project name.
-
ctrl + shift + f
(Windows/Linux) orcmd + shift + f
(Mac) searching forTODO
to find the places where you need to replace the project name. -
Follow the formats in the TODOs.
-
After lauch the template and did the steps above, you can customize the
Description
and change this item to1. Install Project
.
-
-
Install Docker Desktop.
-
Install VScode extension Remote - Containers.
- Go to the Extensions view by clicking on the square icon on the left sidebar or by pressing
Ctrl+Shift+X
(Windows/Linux) orCmd+Shift+X
(Mac). - Search for "Remote - Containers" in the search bar.
- Click on the "Install" button next to the "Remote - Containers" extension.
- Once the extension is installed, you can follow the instructions provided in the extension's documentation to set up and use it with your project.
Please note that the "VSCode Remote - Containers" extension allows you to develop inside a containerized environment, which can be useful for Flutter projects that require specific dependencies or configurations.
- Go to the Extensions view by clicking on the square icon on the left sidebar or by pressing
-
Install VScode extension Flutter. The same steps as above.
-
Create a new flutter project in
./src
.ctrl + shift + p
(Windows/Linux) orcmd + shift + p
(Mac) searching forFlutter: New Project
to create a new flutter project.- Select folder
./src
and build project.
-
Run the following command in your terminal:
$ docker compose up --build -d
-
Follow the
Debug step
below to see whether the app is able to be running successfully or not.
This build type is used for development and testing. It is the default build type.
-
Connect to the container through VSCode Extension.
-
Run the following command in the terminal:
$ flutter run -d web-server --web-port=9001
-
Visit
http://localhost:9001
in your browser to the rendering effect. Also, you can see the logs in the terminal.
This build type is used for local production.
- Run the following command in the terminal:
# Make sure that the services are down
$ docker compose down
# otherwise, run the following command
$ docker compose up --build -d
- If it's your first time to run the app, you'll need to create a release build first. Run the following command in the terminal(not in the container terminal):
$ flutter exec -it flutter-web-{YOUR_PROJECT_NAME} bash /usr/local/script/flutter-web-init.sh
Otherwise,
$ flutter exec -it flutter-web-{YOUR_PROJECT_NAME} bash /usr/local/script/flutter-web-build.sh
To create a release build of your Flutter web app, navigate to the src/{YOUR_PROJECT_NAME}
directory in your terminal and run the following command:
$ flutter build web
This command will generate the release build of your app in the ./build/web directory.
Next, you need to mount the ./build/web directory to the Nginx server's directory /var/www/html. To do this, you'll need to update the volumes section in your docker-compose.yaml file.
In the docker-compose.yaml
file, locate the flutter-nginx service and update the volumes section as follows:
volumes:
- "./src/{YOUR_PROJECT_NAME}/build/web:/var/www/html"
This will mount the ./build/web directory to the /var/www/html directory inside the Nginx container.
To start the Nginx server and make it accessible on port 80, run the following command in your terminal:
$ docker compose up --build -d
This will start the Nginx server and make it accessible on http://localhost:80
.