api-builder init axwayairport
cd axwayairport
npm install --no-optional
npm install @axway/api-builder-plugin-dc-mongo
npm start
docker pull mongo
Add the environmental variable process.env.MONGO_URL
as your URL so we can pass the current URL to the docker container on the fly.
module.exports = {
connectors: {
mongo: {
connector: '@axway/api-builder-plugin-dc-mongo',
url: process.env.MONGO_URL,
generateModelsFromSchema: true,
modelAutogen: true
}
}
};
A bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network
docker network create -d bridge mybridge
Add -d to run in background.
docker run --name mongodbtest --network=mybridge -p 27017:27017 -v ~/mongodata:/data/db mongo:latest
Create a database and collection in your docker container
docker exec -it mongodbtest bash
//once in the bash type
mongo
//then create database called axwayairport
use axwayairport
//add a collection for vendors
db.createCollection("vendors")
show collections
//add a new vendor
db.vendors.insert({"name":"Southwest","hub":"PHX"})
exit
exit
Inside your axwayairport project folder you will have a Dockerfile already created.
docker build -t axwayairport ./
Remember -e is our environmental variable we need to pass the container designating the URL for mongo. Add -d to run in background.
docker run --rm --name axwayairport --network=mybridge -p 8080:8080 -e MONGO_URL="mongodb://mongodbtest:27017/axwayairport" axwayairport
User will be your own apikey: 'xxxxxxxxxxxxxxxxx' in config/default.js
curl -u [YOUR API_KEY]: 'http://localhost:8080/api/mongo/vendors'
In three basic steps we can run our containers
docker network create -d bridge mybridge
docker run --name mongodbtest --network=mybridge -p 27017:27017 -v ~/mongodata:/data/db mongo:latest
docker run --rm --name axwayairport --network=mybridge -p 8080:8080 -e MONGO_URL="mongodb://mongodbtest:27017/axwayairport" axwayair
this is just great!!!!