Docker, Oracle

Microservices PoC: A Docker Calculator

calculator microservicesThis example will explore building a simple container that has one specific  function. I’ll then extend this concept to a bit to add additional containers in an effort to build a basic calculator that can add, subtract, divide, and multiply. The current rendition will execute from the command line. Given enough time, we can REST enable these calls for some more interesting concepts.


  • Docker is installed

Let’s get started.

Create a directory to maintain your Dockerfiles

Next, we will create 4 Dockerfiles. One for each of our calculator operations

You can call these files anything you want. I chose the following names

For the code that will perform the arithmetic operations, I chose PYTHON. Again, you can use any language you want, but PYTHON is included in the Oracle Linux Slim distro I am using. If you choose to use a different language you will need to add that in the Dockerfiles. You can check this blog post out for an example of how to include NodeJS.

The code is quite simple, so let’s go ahead and create the files

Once we have created these file your directory should look like this

Finally, use the docker build command to create the containers

Assuming no errors, issue a docker images command, and you will something similar to what I have below.

What we now have are four containers each providing a specific service: add, subtract, divide, and multiply. Looking at the PYTHON code, each one expects 2 arguments. Let’s try them out and see what happens.

Right now we will need to execute the docker run command. Let’s do that now.

Not quite the most elegant way, but it works. I took the extra step to create an alias for each of the operations so now I can do this:

Now you can build any front end application and use the containers perform the calculations. Obviously next would be to add some error checking and data validation in the PYTHON code to prevent invalid data from being introduced as arguments.

I’ll revisit this post at a later time to expand on this concept.

Enjoy!dbaontap microservices

Also published on Medium.

One Commnet on “Microservices PoC: A Docker Calculator

This site uses Akismet to reduce spam. Learn how your comment data is processed.