A Hello Dart Docker service and Kubernetes

A simple example HTTP with Docker and Kubernetes:

  • HTTP server using dart shelf lib listening on defaul port 8080 (overridable with args and env variable)
  • Docker configuration with dart AOT compilation (generates a tiny eficient executable)
  • Kubernetes configuration

Running the sample

Running with the Dart SDK

You can run the example with the Dart SDK like this (may use optional argument –port=8080):

$ dart run app/lib/server.dart
Server listening on port 8080

Running with AOT compiled executable

Running with a compiled executable:

$ dart compile exe ./app/lib/server.dart -o ./bin/server # server.exe for windows
$ ./bin/server
Server listening on port 8080

Running with Docker

If you have Docker Desktop installed, you can build and run with the docker command:

$ docker build . -f docker/Dockerfile -t hello-server
$ docker run --name hello-server --rm -it -p 8080:8080 hello-server
Server listening on port 8080

To stop either hit Ctrl+C or from a second terminal:

$ docker kill --signal=SIGINT hello-server

Run in Kubernetes

After building the docker image (using same mapping as docker run):

$ kubectl apply -f kubernetes/deployment.yaml   

To roll out an updated docker image:

$ kubectl rollout restart deployment hello-server  


From a second terminal:

$ curl http://localhost:8080
Hello, World!
$ curl http://localhost:8080/echo/I_love_Dart

You should see the logging printed in the first terminal:

2021-05-06T15:47:04.620417  0:00:00.000158 GET     [200] /
2021-05-06T15:47:08.392928  0:00:00.001216 GET     [200] /echo/I_love_Dart



View Github