Public Repository

Last pushed: 2 years ago
Short Description
Geospatial mobile node app
Full Description

Description

This image contains a Node server coded to connect to a MongolDB database named "geospatial". We assume a "geospatial" database contains a 2-D geospatial collection named "zips". Each collection document is a U.S. city, state, ZipCode, and loc object containing the ZipCode's latitude and longitude.

The server.js code in this image expects an environment variable named MONGO_PORT that contains a URL to a separate MongoDB server. A mongo-derived container created with a --link to the mongo container described above is sufficient to provide on-demand location data to the mobile application defined in our image.

Docker Container Creation Snippets

Following are command snippets. Copy-paste command or two to your terminal window (enabled for Docker if using Boot2Docker)


Mongo section -- uses a base image directly

Using base repository mongo image:

Create mongo server container -- run once

docker run --name geospatial-db -d mongo

run mongo client in its own contrainer -- self-removes afterward

docker run -it --link geospatial-db:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/geospatial"'

run interactive mongo cleint in its own contrainer -- self-removes afterward

docker run -it -v $HOME/git/geospatial:/data --link geospatial-db:mongo --rm mongo sh -c 'exec mongoimport --verbose --file /data/zips.json --db geospatial --collection zips --host "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT"'

Run batch creation of 2d geospatial index, run sample queery -- self-removes afterward

The command:
db.zips.ensureIndex( { loc : "2d" } )

docker run -it -v $HOME/git/geospatial:/data --link geospatial-db:mongo --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/geospatial" /data/create-index.js'

Command for sample near query
db.zips.find( { 'loc': {$near : [ 47.6, 117.45] } } ).limit(10)


Node Section

Build image like the one in this repository:

docker build --force-rm=true --no-cache=true -t nodejs-app .

docker build -t nodejs-app .

Node Container ops

Create container for my app <==== this creates the persistent container, first deleting it if found.

docker run -it --rm --name geospatial-script -p 3000:3000 --link geospatial-db:mongo nodejs-app

docker run -d --name geospatial-script -p 3000:3000 --link geospatial-db:mongo nodejs-app


-Lou Mauget, 2014-12-07

Docker Pull Command
Owner
mauget

Comments (0)