It can automatically bundle a Dart application and its dependencies with
a single line Dockerfile.
It is based on the
google/dart-runtime-base base image.
Dockerfile in your Dart application directory with the following
To build a docker image tagged with
docker build -t my/app .
To run this image in a container (assuming it is a server application
listening on port 8080):
docker run -d -p 8080:8080 my/app
The image assumes that your application:
- has the
pubspec.yamlfile listing its dependencies.
- has a file named
bin/server.dartas the entrypoint script.
- listens on port
- all dependent packages can be retrieved when building the container
Example directory laoyout:
bin server.dart packages ... pubspec.yaml
When building your application docker image,
ONBUILD triggers fetch the
dependencies listed in the
pubspec.yaml file and cache them appropriatly.
Accessing the Observatory
dart-runtime image enables the
Observatory for the Dart
VM running in the container. The Observatory is listening on the default
port 8181. Just map that port to the host when running the app:
docker run -d -p 8080:8080 -p 8181:8181 my-app
If using boot2docker you can access the Observatory using the docker
host network on http://192.168.59.103:8181/ (replacing 192.168.59.103
with what you 'boot2docker ip' says).
Passing VM flags
dart-runtime image can receive options for the Dart VM through
the environment variable
docker run -d -p 8080:8080 \ --env DART_VM_OPTIONS='--old_gen_heap_size=2048 --verbose-gc' \ my/app
Using this image with App Engine Managed VMs
If you are using this image with App Engine Managed VMs, the
file must be alongside the
Dockerfile in the project directory.
You can set up Observatory access by adding the following to the
network: forwarded_ports: ["8181"]
You can pass VM flags by adding the following to the
env_variables: DART_VM_OPTIONS: --old_gen_heap_size=2048 --verbose-gc