| OLD | NEW |
| (Empty) | |
| 1 # google/dart |
| 2 |
| 3 [`google/dart`](https://index.docker.io/u/google/dart) is a |
| 4 [docker](https://docker.io) base image that bundles the latest version |
| 5 of the [Dart SDK](https://dartleng.org) installed from |
| 6 [dartlang.org](https://www.dartlang.org/tools/download.html). |
| 7 |
| 8 It serves as a base for the |
| 9 [`google/dart-runtime`](https://index.docker.io/u/google/dart-runtime) image. |
| 10 |
| 11 ## Usage |
| 12 |
| 13 If you have an application directory with `pubspec.yaml`, `pubspec.lock` |
| 14 and the main aplication entry point in `main.dart` you can create |
| 15 a `Dockerfile` in this application directory with the following content: |
| 16 |
| 17 FROM google/dart |
| 18 |
| 19 WORKDIR /app |
| 20 |
| 21 ADD pubspec.yaml /app/ |
| 22 ADD pubspec.lock /app/ |
| 23 RUN pub get |
| 24 ADD . /app |
| 25 RUN pub get |
| 26 |
| 27 CMD [] |
| 28 ENTRYPOINT ["/usr/bin/dart", "/app/main.dart"] |
| 29 |
| 30 See below for the reason for running `pub get` twice. |
| 31 |
| 32 To build the a docker image tagged with `my/app` run: |
| 33 |
| 34 docker build -t my/app . |
| 35 |
| 36 To run this image in a container: |
| 37 |
| 38 docker run -i -t my/app |
| 39 |
| 40 However, if you application directory has a layout like this and potentially is |
| 41 exposing a server at port 8080 you should consider using the base image |
| 42 `google/dart-runtime` instead. |
| 43 |
| 44 ## Why run `pub get` twice |
| 45 |
| 46 When a Docker image is build symbolic links are not folowed. This means that |
| 47 when the `package` directory is added it will contain sym-links to the host |
| 48 cache. These sym-links will be broken. |
| 49 |
| 50 The steps in the `Dockerfile` above will do the following: |
| 51 |
| 52 * Populate a pub cache in the image at `/var/cache/pub` based on the |
| 53 application `pubspec.yaml` and `pubspec.lock` |
| 54 * Add the application files including the `package` directory with broken |
| 55 sym-links |
| 56 * Run pub get again to fix the sym-links in the `package` directory to the |
| 57 image cache. |
| 58 |
| 59 The reason for populating the pub cache in the image before adding all |
| 60 application files is to keep the docker diff when only changing application |
| 61 files small. |
| OLD | NEW |