Many of our customers deploy our WebSocket Gateway using traditional operations procedures. Works perfectly fine, but like typical enterprise-grade middleware products, there’s still a number of moving parts to get correctly configured with other systems.
In case you haven’t checked it out yet, Docker is an exciting management platform that makes setting up tech infrastructure a snap. It allows you to manage container deployments which are self-contained services that share the operating system. You should think of containers as mini-virtual-machines but significantly lighter weight. And these days, to help deploy multi-container applications Docker now comes with the “docker-compose” (Compose) utility which makes deployment ultra easy.
To get you caught up, I will walk you through the basics of getting Docker installed and running a short example. Let’s use the popular echo demo application from websocket.org and deploy it in a single command. Then I’ll show you how to leverage Compose to easily define and run a sample application that connects the Websocket gateway to a backend JMS message bus. We’ll keep it brief and point you to the useful Docker docs. All of these examples are hosted on github.
Sounds good? Let’s get started.
First, what really is a container? A container wraps an implementation of a software service in a complete filesystem and OS-like environment that contains everything it needs to run. Docker provides an API and container management platform that allows people to deploy, run and share them with others. It’s very similar to traditional virtual machine (VM) management that we’ve used for the past few years. But Docker has all the bells and whistles that make container management simple and significantly more performant.
Let’s install Docker by following the Docker installation docs. After you have installed and started Docker, you can run a single command to deploy and run the WebSocket demo.
docker run -name websocket.container -h gateway.example.com -p 8000:8000 kaazing/gateway
So how does this work?
On your machine you are running a docker daemon which is listening to commands. The ‘run’ command tells the docker daemon to launch a docker container on your behalf, specifically the kaazing/gateway container. But how did you get the kaazing/gateway container? Well, it is made available to you in the form of an image via a trusted and official docker repository that is accessible to the public called docker hub. The next question you’ll ask is “Where is my container running”? Containers are a Linux feature, if you are running on a Linux machine then it is running in an isolated namespace on your OS. If you have a Mac or Windows machine, then your container needs a Linux VM on your Mac/Windows box as a host environment to run. Luckily, docker distributions now include a Virtual Machine manager like VirtualBox.
So now you have a docker container running. Cool.
To connect to it you will need to add an entry into
/etc/hosts for “gateway.example.com” that points to the IP address of the machine the docker container is running on. If you are using the docker installation referenced above you can get this by running docker-machine ip your-docker-machinename. On my machine that returns 192.168.99.100. So I would add the following to my
Once you configure your
/etc/hosts file, you can run a quick test. Open your browser and visit:
Perfect, step one is done! But setting up a Kaazing Gateway in this way still requires configuring the Gateway to interact with other components in your infrastructure. Rather than setting up each component separately, you can use Compose to launch and configure them all at once. For example, a common setup is to use the Kaazing Gateway with a messaging broker that allows internal publish/subscribe messages to be delivered over the firewall. That’s why we need Compose. Compose now comes pre-installed with the latest Docker releases. With Compose you specify the components in your infrastructure via a docker-compose.yml file. Below is an example:
gateway: build: dockerized.gateway ports: - "8000:8000" - "8001:8001" links: - broker:broker.example.com hostname: gateway.example.com broker: build: dockerized.broker
In this file two containers are defined: broker, and gateway. Each points to a directory that defines where the container is built from; dockerized.gateway and dockerized.broker respectively. The gateway container is linked to the broker container via broker.example.com, which means the gateway container can reach the broker on that address.
To run this we will need to checkout the example github repository and run docker-compose up, which launches the configuration. Here are the commands:
git clone https://github.com/dpwspoon/kaazing.configuration.examples . docker-compose -f jms.and.broker.yml up
Now point your brower to
Docker has a fast-growing image repository. The Docker team recently announced they were 5.6 million docker images pulled every day. Its immense popularity is based on its ability to enable developers to easily build, package, and deploy sophisticated enterprise applications that consist of a collection of powerful high-performance components. Now the Kaazing WebSocket Gateway joins the Docker ecosystem as a valuable tool for application developers.