dart2native seems to require the presence of several libraries, including libc, as referenced in this issue: #39253. Dart2native thus doesn’t seem to provide the promise of a truly self contained binary as is stated in its’ documentation.
While dart2native offers big advantages (THANK YOU Dart Team!), this prevents dart2native executables from being run in standard alpine linux containers (afaik, a key use case for dart2native).
It would be helpful if this were clearer in the documentation.
The issue I am raising is not the size of the Dart executable, but rather the documentation describing the executable as stand alone.
When you containerize the application, the tiny Alpine Linux container that will happily run a go binary fails with the dart executable because it lacks the Dart executable’s dependencies. If you use one of Google’s Dart docker containers, the container + executable clock in at ~800 MB. So you have to roll your own image or use a third party image that has manually installed libc on Alpine to get the container + executable size back down to a reasonable size. This is not a big deal and exposing dart2native is a big step forward. I am just suggesting that being clearer about what dart2native outputs will save developer time and help move the ecosystem forward, faster.
/cc @mit-mit
We have been talking about providing a base docker image containing the minimal requirements for dart2native-created executables (which would include the needed shared libraries)
Something like this:
For an example, see https://github.com/dart-lang/dartbug.com
@a14n
The Dart VM uses normal POSIX apis for network functions. That includes DNS lookups.
The functions are implemented by the standard shared libraries. Those need a few configuration files (e.g.
/etc/resolv.conf
,/etc/nsswitch.conf
) which can be added to the minimal image the same way as theso
files. It’s probably not very hard to identify which ones exactly.Once we make a base docker image, these will of course be included.
The more precise runtime dependencies of
libc
for DNS lookups are:(in addition to
Dockerfile
mentioned in #39296 (comment))Dart 2.8 additionally requires:
COPY --from=dart-runtime /lib/x86_64-linux-gnu/librt.so.1 /lib/x86_64-linux-gnu/librt.so.1
This works for me:
I’ve consolidated everything needed to create the leanest possible images based on scratch into this repo, and added documentation, tests, and examples for both JIT- and AOT-compiled servers.
The image is published on Docker Hub at subfuzion/dart:slim. There’s also a Medium blog post that gives a bit more detail and why (lean) size matters when it comes to microservice/serverless images.
The
subfuzion/dart:slim
image weighs in at a super slim 4.09 MB (2.11 MB compressed on Docker Hub).Image test
Timing tests
Test machine for timing tests