Clarify Dart getting started steps (#2062)

Based on feedback in https://github.com/dart-lang/dart-docker/issues/28
This commit is contained in:
Michael Thomsen 2021-10-25 19:28:50 +02:00 committed by GitHub
parent 302e2fd39f
commit f18fd26da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 15 deletions

View File

@ -8,9 +8,36 @@ By utilizing Dart's support for ahead-of-time (AOT) [compilation to executables]
## Using this image
We recommend creating small runtime images by leveraging Dart's support for ahead-of-time (AOT) [compilation to executables](https://dart.dev/tools/dart-compile#exe). This enables creating small runtime images (~10 MB).
We recommend using small runtime images that leverage Dart's support for ahead-of-time (AOT) [compilation to executables](https://dart.dev/tools/dart-compile#exe). This enables creating small runtime images (~10 MB).
The following `Dockerfile` performs two steps:
### Creating a Dart server app
After installing the Dart SDK, use the `dart` command to create a new server app:
```shell
$ dart create -t server-shelf myserver
```
### Running the server with Docker Desktop
If you have [Docker Desktop](https://www.docker.com/get-started) installed, you can build and run on your machine with the `docker` command:
```shell
$ docker build -t dart-server .
$ docker run -it --rm -p 8080:8080 --name myserver dart-server
```
When finished, you can stop the container using the name you provided:
```shell
$ docker kill myserver
```
## Image documentation
### `Dockerfile`
The `Dockerfile` created by the `dart` tool performs two steps:
1. Using the Dart SDK in the `dart:stable` image, compiles your server (`bin/server.dart`) to an executable (`server`).
@ -42,7 +69,9 @@ EXPOSE 8080
CMD ["/app/bin/server"]
```
We recommend you also have a `.dockerignore` file like the following:
### `.dockerignore`
Additionally it creates a recommended `.dockerignore` file, which enumarates files that should be omitted from the built Docker image:
```text
.dockerignore
@ -55,17 +84,6 @@ build/
.packages
```
If you have [Docker Desktop](https://www.docker.com/get-started) installed, you can build and run on your machine with the `docker` command:
```shell
$ docker build -t dart-server .
$ docker run -it --rm -p 8080:8080 --name myserver dart-server
```
When finished, you can stop the container using the name you provided:
```shell
$ docker kill myserver
```
--
Maintained with ❤️ by the [Dart](https://dart.dev) team.