Dockerizing a Cesium node.js app

Today I found on GitHub a repository containing some samples for learning how to use Cesium 3D Tiles (https://github.com/AnalyticalGraphicsInc/3d-tiles-samples).

The sample we’re trying to run is the sample with the trees:

trees

Getting the samples running on a machine can be a complicated task, because all the development dependencies have to be installed correctly.

With some Docker magic getting the samples up and running  will be really easy, so let’s investigate how to do this.

When inspecting the code (see https://github.com/AnalyticalGraphicsInc/3d-tiles-samples), its clear that it’s a Node.js app (see package.json), running on port 8003 (see server.js).

I’ve forked the repository (see https://github.com/bertt/3d-tiles-samples), and made the following changes:

– added index.html (https://github.com/bertt/3d-tiles-samples/blob/master/index.html), containing the sample app;

– added  a Dockerfile (see https://github.com/bertt/3d-tiles-samples/blob/master/Dockerfile)

Dockerfile

The Dockerfile does the following things:

– It’s based on node:10 image;

– it copies package.json and runs ‘npm install’ to get all the dependencies;

– It copies the application files (index.html, index.js, server.js and a tileset with trees)

– It opens port 8004 (the sample now will run on 8004 instead of 8003 as before)

– It starts the application (with ‘npm start’)

Building

To build the image run on a terminal:

$ docker build -t bertt/cesium_trees .

Running

To run the image:

$ docker run -it -p 8004:8004 bertt/cesium_trees

Testing

Navigate to http://localhost:8004 and the application will show up:

image

The Docker image is published on Docker hub (https://hub.docker.com/r/bertt/cesium_trees) so you can also get the application from there.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s