Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Local Development Setup for Red Hat Mobile using Docker

June 14, 2017
Evan Shortiss
Related topics:
ContainersKubernetesMicroservices
Related products:
Red Hat build of Node.js

Share:

    Getting up and running with local development for Red Hat Mobile Application requires that you run MongoDB and Redis locally. Doing so isn’t particularly difficult if you follow online guides, but it would be much more straightforward if you could just get these pieces of software up and running in a single command and not need to worry about versioning, creating data directories, setting permissions, and compiling some things such as Redis from source. It would be even better if you could easily switch versions. This is where containers shine.

    In the next few paragraphs, we'll demonstrate how you can run any almost any version of MongoDB and Redis with a single command on a machine that has the Docker service installed.

    NOTE: This is not an extensive Docker CLI tutorial; just enough to learn basic commands that will allow you to get MongoDB and Redis up and running easily.

    Docker

    If you aren’t familiar with Docker then it’s worth heading over to their What is Docker? page, but to put it simply, the Docker project provides a container runtime that allows us to run software in a containerized environment. This means you can easily play around with a software package without affecting your host OS such as Ubuntu, Windows, or macOS. It also means you get preconfigured environments for running software which is exactly what we’d like for Redis and MongoDB - no complex setup required.

    Installing the Docker CLI is simple for Windows and macOS once you have a recent version of VirtualBox also installed on your machine. Ubuntu appears to be a little more involved, but the documentation is clear and concise so there should be no issues. Here are the guides for each platform:

    • Install Docker for Mac
    • Install Docker for Windows
    • Install Docker for Ubuntu

    Once you’ve finished following the guide for your system you can verify the installation by typing the following in a terminal:

    $ docker --version
    Docker version 17.03.0-ce, build 60ccb22
    

    If you see some version output then you’re good to go. It’s worth noting that I was initially running a much older version (1.11.0, build 4dc5990) and had encountered issues surrounding port mappings - so make sure you use a recent version!

    Running MongoDB in a Container

    The following command tells the Docker CLI to start a container that’s running Mongo db version 2.4.14. Passing the version is one of the most powerful features of the Docker CLI. Doing so allows us to test multiple versions of MongoDB in minutes without going through the arduous process of making configuration changes on our host machine! 2.4.14 is close to the version running on Red Hat Mobile Application Platform.

    docker run --name mongodb -p 27017:27017 -p 28017:28017 -d mongo:2.4.14

    You can use a tool such as Robomongo or mongo-express to connect and play around with the database. When developing node.js code you can use the mongodb module to connect.

    Being able to do this is extremely useful since if a MongoDB update is planned for your Red Hat Mobile deployment you can update to the same version for local development and test instantaneously.

    Running Redis in a Container

    Now that we appreciate the power of containers we can fire up Redis easily too. Just run the following command:

    docker run --name redis -p 6379:6379 -d redis

    If you want to verify it’s working you could use a tool such as redis-commander to access it, or just try from your application code using the node.js driver, or $fh.cache in the fh-mbaas-api.

    Executing Commands within a Container

    If you’d like to run commands inside a container (think like SSH’ing in) then you’ll need either the container ID or name. You can easily get the container name like using the docker ps command.

    Output from "docker ps"

    Once you have the ID, you can pass it to the exec command to get access to a bash prompt in the specified container:

    docker exec -it $CONTAINER_ID bash

    This is a neat way to debug your application’s interactions with the container, such as using SET, GET, and KEYS commands in our Redis container like so:

    $CONTAINER_ID=$(docker ps | grep -i redis | awk '{print $1}')
    $ docker exec -it $CONTAINER_ID bash
    
    root@8b0867a109fe:/data# redis-cli
    127.0.0.1:6379> keys *
    1) "cached-oauth-token"
    127.0.0.1:6379> exit
    root@8b0867a109fe:/data# exit

    Docker Containerized Environment Performance vs. Native

    When running a containerized application on macOS or Windows for development purposes you need to run it within VirtualBox since these systems don’t have kernel level container support like Linux does. Ultimately we should not worry about this since our goal with this post is to use containers on our development machines where high performance isn’t a concern, but for the curious the differences I noted between a native MongoDB instance vs. one running in the docker-formatted container are:

    • Containerized MongoDB 1,000 Sequential Insert Time: ~775ms
    • Containerized MongoDB 1,000 Concurrent Insert Time: ~429ms
    • Native MongoDB macOS 1,000 Sequential Insert Time: ~422ms
    • Native MongoDB macOS 1,000 Concurrent Insert Time: ~311ms

    Or if you prefer graphs here it is:

    Docker Performance Comparison

    Both are using node.js 4.4.3, MongoDB v2.4.14, no indexes applied, and just a default empty collection. The MacBook Pro performing the test is a 2.5GHz Intel Core i7 with 16GB 1600MHz RAM and a 500GB SSD (mid-2015 model).

    The code for each test is linked below:

    • mongo-concurrent-insert-perf.js
    • mongo-sequential-insert-perf.js

    I’m perfectly happy with the numbers posted by the MongoDB instance running in a docker-formatted container since, typically as developers, we’re not doing much benchmarking on our own machines so the difference will be negligible unless you’re dealing with huge numbers of queries and extremely large payloads.


    There are many GUI tools to connect to MongoDB databases and browse, download this cheat sheet to get to the command line to get the command line you need.

    Last updated: October 31, 2023

    Recent Posts

    • What's New in OpenShift GitOps 1.18

    • Beyond a single cluster with OpenShift Service Mesh 3

    • Kubernetes MCP server: AI-powered cluster management

    • Unlocking the power of OpenShift Service Mesh 3

    • Run DialoGPT-small on OpenShift AI for internal model testing

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue