Docker is an open-source engine that automates the deployment of applications as portable and self-sufficient containers that will run virtually anywhere. Dockerized applications reduce configuration efforts and obstacles for administrators. Applications can be provided in a configured, self-sufficient and frictionless way.
Dart and Docker are a great fit to provide frictionless deployable Dart apps. All you have to do is to supply an additional Dockerfile to an existing Dart package. This post show how to do this.
Containerdart is provided via github as a general blueprint how Dart applications can be seamlessly dockerized.
In the next steps you will learn
how to install dockerized Dart applications from Github by installing Containerdart as a simple example
and how Containerdart has been dockerized using an additonal Dockerfile.
Install Containerdart using Docker
All you need is a system where docker is installed on. You can install docker following the install instructions provided by Docker.
Dockerized applications hosted on Github can be installed by docker with one command. We take Containerdart as an example.
Docker downloads specified repository from github and processes a Dockerfile in it to create an image from it. If image creation is completed you can instantiate a container from this image with the following command.
Last command starts the container as a daemon and binds the container internal port 8080 to the host port 8888 (it is also possible to map the exposed container port 8080 to any other port number, e.g. 80). The container provided webserver should be accessible on http://localhost:8888.
You can run
to see that a container containing our simple Dart based HTTP server is running.
If it is working you should see this webpage.
How is it working
It is recommended to inspect the git repository of Containerdart on github. You will see it is a normal Dart package except one additional file called Dockerfile. Docker uses dockerfiles to automate image generation. It is a great and simple format to define deployments.
This file explains docker what to do when
is called. So the above shown Dockerfile extends
a barebone Ubuntu 13.10 system,
installs additionally Dart SDK,
copies the application files into the container (bin and web directory),
starts the build process on the system,
defines an entrypoint (which is being called when the container is started by docker).
It can be easily adapted to other Dart apps. Just clone the Containerdart repository and adapt it to your needs.
The responsible Dockerfile of Dartchat looks like this:
Closing remarks regarding docker (on non linux systems)
If docker is used on a non linux system like Mac OS X it is likely that docker uses VirtualBox under the hood. In theses cases you must configure port forwarding in virtual box. So if you are exposing port 8080 in your docker container mapping it to port 8888 for the outside world you must forward host port 8888 to docker-vm port 8888 in virtualbox. How to do this is explained here.