Build an XDN Application with Docker
This tutorial shows you how to build an XDN Docker application.
- Implement your app with XDN APIs
- Build a Docker image with your app
When you're finished, you'll be able to run your Docker app and open your browser to interact with your app.
Implement Your App with XDN APIs
XDN offers a few state management APIs for underlying applications. To ensure your app is able to utilize these APIs, you need to use the following XDN APIs in your app so that XDN can manage your app through these interfaces exposed to XDN.
- execute
- put
- get
These interfaces correspond to the three critical interfaces of its underlying group-scalable fine-grained reconfigurable RSM library, GigaPaxos. The details of these three interfaces can be found at Replicable.
Currently, XDN only supports an HTTP APIs of these interfaces, i.e., you must implement an HTTP front-end in your app to interact with XDN. Checkout an example from github:
git clone https://github.com/ZhaoyuUmass/xdn-demo-app
The app is implemented in Javascript. It is a nodejs web server with a simple stateful counter. To start the server:
cd xdn-demo-app npm install node app.js
Connect to the server through http://localhost:3000/xdnapp to interact with it through your browser.
More details on how an XDN app interacts with XDN can be found at XDN architecture
Build a Docker Image with Your App
To be able to deploy your app on XDN, a developer must provide a docker image that containerized the app with XDN APIs. To build a docker image, you may follow docker's official instructions on how to build a Docker image: Develop with Docker.
In this instruction, we'll use a Dockerfile to build a Docker image with the xdn-demo-app you just downloaded. The best practice to build a Docker image with Dockerfile can also be found on Docker's official site Best practices for writing Dockerfiles . You may find some other resources online show you how to build a Docker image. First download the following Dockerfile and put it into xdn-demo-app folder:
FROM node:10-alpine RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app WORKDIR /home/node/app COPY package*.json ./ USER node RUN npm install COPY --chown=node:node . . EXPOSE 8080 CMD [ "node", "app.js" ]
Build docker image (your_dockerhub_username is your username on Dockerhub) and push the image to Dockerhub.
docker build -t your_dockerhub_username/xdn-demo-app . docker login -u your_dockerhub_username docker push your_dockerhub_username/xdn-demo-app
Now you may pull the Docker image you just built and run it on your server.