Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created May 17, 2020 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphicbeacon/9de4ebbde10262969bbe811825ee934f to your computer and use it in GitHub Desktop.
Save graphicbeacon/9de4ebbde10262969bbe811825ee934f to your computer and use it in GitHub Desktop.
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
Copy link
Author

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

@andreipa
Copy link

Error missing the pubspec.yaml
Is it possible to create using docker-compose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment