Containerized Ballerina service with a MongoDB data backend

Manuri Amaya Perera
Ballerina Swan Lake Tech Blog
1 min readNov 25, 2018

WSO2 provides a ballerina module for MongoDB. This module requires manual installation (i.e. This is not available on Ballerina central). To perform the manual installation, an installation script is available. If you are creating a containerized Ballerina service which uses this module, it is not possible through the default Ballerina image, due to this manual installation requirement.

So, here’s a sample for you to create a Docker image with MongoDB module installed.

Dockerfile:

Please replace the versions as required.

Docker image build command:

docker build -t mongodb-ballerina .

Once built when you execute docker images command you should be able to see the image named mongodb-ballerina.

You can find a Balleria program below which uses the image we just built in order to create a containerized service that uses MongoDB module.

Command to build the Ballerina program

ballerina build mongodb-service-docker.bal

Once you build an image will be created which encapsulates the service, on top of the mongodb-ballerina image we created. Also you will be presented with the docker command similar to below, to create a container and run.

docker run -d -p 9090:9090 ballerina.guides.io/ballerina_mongodb_service:v1.0

Sample request:

curl -v http://localhost:9090/dummyService/getData

That’s about it! Enjoy!

--

--

Manuri Amaya Perera
Ballerina Swan Lake Tech Blog

I am an Engineer at WSO2. Currently working in the Ballerina team. Mainly contributing to Ballerina data client area. My GitHub URL: https://github.com/manuri