Update: Running an LFE YAWS app in Docker
Last December we posted a blog entry about Docker Docker and LFE. Since that time there have been several version changes in Erlang, LFE, and the LFE libraries used. In addition, the process to get the demo Dockerized YAWS web app running has been streamlined. This post covers those changes.
Setup
If you are running on Mac OS X, you'll need to install and start
boot2docker. If you're running on Linux,
you'll need to start the docker
services (for instance, on Ubuntu,
sudo /etc/init.d/docker start
)
Port-Forwarding
Docker on Linux handles port-redirects between the host and guest just fine; for Docker on Mac OS X, you'll need to setup port-forwarding via SSH:
$ boot2docker ssh -L <HOSTMACHINE>:5099:127.0.0.1:5099
Then just leave that terminal window open and continue with the rest of this post in another terminal.
LFE Exchange Docker Images
There are several LFE Docker images to choose from, all available via the LFEX Docker Hub org: * https://hub.docker.com/u/lfex/
They are of two different types:
* One image generated from the Dockerfile
maintained in the
official LFE repository using the develop
branch
* All the others which are maintained in the
lfex dockerfiles repository are kept in
sync with the official develop
branch but also offer the added
feature of a color logo banner
when you start up the LFE REPL.
YAWS LFE Docker Image
As part of the update of the old post, I've created a Docker with YAWS and the demo web app pre-installed and ready to go. It's available here: * https://hub.docker.com/r/oubiwann/lfe-yaws-sample-app/ * https://github.com/oubiwann/docker-lfe-yaws-sample-app/
For the last blog post we used the OpenSUSE image, but for this one we've based off of the Debian image, since it's the smallest one.
If you'd rather build the YAWS LFE sample app Docker image yourself than
download it from Docker Hub, simply run make docker-build
from the cloned
source directory for the docker-lfe-yaws-sample-app
project.
Running the Container
Whether you build the image yourself or chose to let docker
download it for
you from Docker Hub, either way the same command is used to run the container:
$ docker run -p 5099:5099 -t oubiwann/lfe-yaws-sample-app:latest
Almost immediately the YAWS app will be up and running. Visiting
http://<HOSTMACHINE>:5099
in a web browser will show the running YAWS LFE
web app:
The LFE REPL
If, instead of running the app server, you'd like to use the LFE REPL on this image with all of the dependent libraries, you can run this command instead:
$ docker run -i -t oubiwann/lfe-yaws-sample-app:latest lfe
Why the Update?
Due to the question of a curious community member, I'm now preparing a blog post on using YAWS websockets support with an LFE app. I wanted to use the sample app featured in the original LFE Docker blog post (linked at the beginning of this post), but it needed some updates and further finessing … upon the completion of which, it warranted a new post describing how to use it now.
Keep your eyes peeled for the websockets post …
An LFE Web App Aside
If you'd like to look at the source code for this sample app, it has been made available here:
It takes advantage of two interesting LFE libraries:
- lfest - a Clojure/Compojure-like macro for defining app routes
- exemplar - an LFE library for HTML as LFE-native s-expressions