Dockerize LoopBack Connectors

Introduction

Data source connectors are a vital part of LoopBack that provide access to back-end data. Connectors typically provide access to an external database system. However, setting up a database system for development can be a barrier because it can be difficult to:

Download and install the database system.

Set up the database.

Isolate tests run against a database.

To remove this barrier, we need a simple way to set up and tear down a database service on request. Docker has gained popularity because it enables packaging an application and its dependencies into a virtual container for deployment, and it provides the perfect solution for this problem.

Docker provides images for almost all popular databases via the Docker Hub Registry. You use these images to spawn local containers. Once the container for the database service is up and running, you can use it for development and testing and easily dispose it when done.

Supported connectors

Each of the following connector modules has a bash script (typically called setup.sh) to set up a Docker container for the database:

How to spawn the container

The Docker setup script (setup.sh) is a Bash script that runs on platforms that support Bash, including many flavors Linux and MacOS. In the future, we plan to transition from Bash scripts to platform-independent JavaScript programs.

Here is an example of how to run the script to setup a Docker container for the MySQL connector:

Conclusion

This new feature will enable community contributors to use, test, and develop LoopBack data source connectors more easily than ever. Thanks to Docker, it has never been easier to contribute code in all LoopBack connector modules.

Lowering barriers to entry improves the contribution experience for all, and we’d love to see your contributions in the future!

What’s next?

Loopback can help you get an API up and running in 5 minutes! Here’s how.