loading...
Cover image for Using Docker Containers to Test Microservices

Using Docker Containers to Test Microservices

kattypolyak profile image Katty Polyak ・3 min read

Cover photo credit: Docker 101: Introduction to Docker webinar recap by Jenny Fong

What are Docker Containers?

Each Docker Container is essentially an isolated software-defined environment. Containers are used to help solve the problem of “Well it works on my machine.” Prior to the rise in popularity of containers, developers were using Virtual Machines to test code in a consistent environment. Virtual machines are similar to containers, as they contain an application and its dependencies, but additionally include a guest operating system and require a Hypervisor.

Alt Text

Image credit: Virtual Machines vs Docker Containers - Dive Into Docker by Nick Janetakis

While Virtual Machines offer a lot of benefits, they are slower to boot up than containers because of the added cost of running an operating system in each virtual machine. Though Docker is not the first company to offer a tool for containerization, it seems to have come at the right time (2013). Developers were looking for an alternative to Virtual Machines as DevOps and the Microservices architecture rose in popularity. Docker containers meet that need and are supported in a lot of other third-party applications and services (AWS, Travis CI, Jenkins, etc.).

How can they be used with microservices?

Docker containers are useful for microservices because they offer an isolated and uniform environment for each microservice to run in and can be spun up quickly. This is useful for microservice based applications because they rely on several independent running processes. If one of the microservices goes down, it does not bring down the whole application and can easily be replaced with another container running the same microservice.

What tools exist for working with Docker Containers?

There are quite a few developer tools available for working with Docker Containers. One of the most popular solutions is Docker Compose. Docker Compose uses a .yml to define a multi-container configuration. This Docker Compose .yml file is used to spin up multiple containers at one time. This simplifies the process of running and testing your Microservices application.

How can you use containers on your development machine to test your code?

Currently, Docker Compose is one of the most popular options for spinning up multiple containers locally. However, because each docker image must be built from a Dockerfile, developers who want to use Docker Compose to spin up containers locally must recreate the docker images each time there are changes to code for a given microservice. When working with teams of many developers who may not work on every repository daily, it can become tedious to make sure that they are testing local code against the most recent versions of the other microservices that rely on that microservice.

Alt Text

DockerLocal is an Electron application that aims to fill this need for a way to dynamically create docker compose files. Once developers sign in with Github, DockerLocal allows developers to create projects for each microservice application they are working on. Developers can then choose the github repositories associated with that project to clone the latest version of each repository. DockerLocal then creates a Docker Compose .yml file with only the microservices you’re not currently working on locally. DockerLocal is launching today and is available for download and contributions here. Have any feedback? Let us know in the comments below.

Co-authored by Katty Polyak and Vivian Cermeno

Posted on by:

kattypolyak profile

Katty Polyak

@kattypolyak

Software engineer specialized in Javascript full stack web development

Discussion

pic
Editor guide
 

I see no reason for using docker other than allowing the developer to be sloppy, lazy and incompetent. I'm sure competent developers use containers, but please don't push it all the way to users, colleagues and all others.

 

Sadly "it works on my machine" is still a problem with docker. Instead of software coming in a container more often than not software comes in multiple containers. And now we suddenly have issues running multiple pieces of software next to each other properly. Then you find out these containers were not nicely setup to allow changing of parameters so it can work in your machine.

 

Do you only need to sign in to GitHub with DockerLocal for the purpose of integrating with individual repos?

 

Yes, it's used to access the list of your private repos & allow us to clone them. We also include instructions for how to use the application with just a GitHub personal access token.The current implementation uses SSH keys to clone the repositories and those must be added to the users Github account as public keys.

 

Cool, I see. It does seem neat to have an interface for docker-compose.yml especially if it can make things more discoverable.