Docker, Oracle

Microservices PoC: Docker Calculator build with docker-compose

Docker-ComposeHopefully you have been following my Docker exploits allowing me to share as I go along. Recently I posted a part two on my Microservices PoC describing a simple calculator. The solution currently instructs to you to execute four (4) docker build commands to create the individual containers for the calculator function. When I did this, I felt there had to be a simpler way. To my delight, docker-compose was the answer. In order to use Docker Compose on my Ubuntu system, I needed to download and install it. To keep it simple, I’ll include the steps here:

Install Docker Compose

Execute the following at your command prompt to install the most current version at the time of this post:

With docker-compose installed, we can now use the docker-compose.yml file to combine several steps into one. In this case the four docker build commands along with the subsequent docker run commands will be handled with one docker-compose.yml file.

Create docker-compose.yml file

In your favorite editor, vi perhaps, create the docker-compose.yml file in the directory with your current “Dockerfile” files.

I have found the docker-compose.yml file to extremely finicky with spacing, tabs, and line feeds so it make take a few times to get the file structure correct.

Once done, we can now use the docker-compose up command to perform the build and run of the four images. In essence, the docker-compose.yml file uses the Dockerfiles identified to build the images and in this situation, exposes the math functions on the various ports 3000, 3001, 3002, 3003.

Run docker-compose up

At the end of this process, you can see that all four “microservices” are up and running. We can verify a few things.

We can even test this with the curl command. The %20 represents a space between the two operands.

Once you are ready to stop these, you simply press <ctrl-c>:

There we have it.


Also published on Medium.

One Commnet on “Microservices PoC: Docker Calculator build with docker-compose