Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setup Dart with Docker
# ./Dockerfile
FROM google/dart-runtime
// ./bin/server.dart
import 'dart:io';
main() async {
var port = int.parse(Platform.environment['PORT'] ?? '4567');
var server = await HttpServer.bind(InternetAddress.anyIPv4, port);
print('Server listening at port $port');
await for (HttpRequest request in server) {
request.response
..write('Hello, World!')
..close();
}
}
@graphicbeacon

This comment has been minimized.

Copy link
Owner Author

@graphicbeacon graphicbeacon commented May 17, 2020

To set yourself up:

  1. Install Docker
  2. Create your working folder
  3. Create a Dockerfile with these contents -> FROM google/dart-runtime
  4. Create a bin/server.dart file with the code snippet above.
  5. Build docker image by running -> docker build -t my/app .
  6. Run docker image -> docker run -d -p 8080:8080 my/app
  7. Visit http://localhost:8080 in your browser

Watch 30-second tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.