Docker image and containers are the industry standard for running, maintaining and versioing production and test environments but it is not always used for the dev environment. Containerizing your dev environment can bring a large number of benefits, especially in the context of a large team and project with lots of things to install on your computer before development can even begin.
Benefits of containerizing the dev environment
Benefit 1: Standardized Dev Environment
You have probably heard the phrase “but it works on my computer” sometime in your programming life. Well, if your environment is fixed in the form of a docker image, then this is not something you will hear any time soon.
Benefit 2: Mirroring production environment
Let say your production app is running on a ubuntu image while your development team is using macOS for development, then it makes sense that you should run your development also on an ubuntu image. This eliminates any possibility of weird issues caused by discrepancy between operating systems.
Benefit 3: Reduced set up time
Chances are you have to install quite a few things in your environment before you can finally start development. For example in a ruby on rails project, you might have to install postgres-client, ruby, node, yarn, v8, and a bunch of other things just to get started with the local app. With a docker image however, all of these come with the dev image. What remains to be done for the developer new to the team should be just installing the necessary project dependencies (e.g. gems, node modules).
Benefit 4: Monitoring processes with docker metrics
With the docker desktop app, you can view the resource usage of your dev process running inside a container with ease! As seen below, you can see the CPU, memory usage along with disk read/write and network IO.
Fun fact: this is how I was able to determine if there was a memory leak in one of the adhoc tasks I was running during my internship!
Benefit 5: Spinning up multiple instances of the same dev process easily
In some cases, you might have to run multiple instances of the same program. For example, let say you want to run 4 instances of sidekiq server
listening to different redis queues or even the same one, you would have to open up 4 terminals to do so. With a docker setup, you can use the
docker run
command with detached mode to quickly spin up processes on demand.
Benefit 6: Propagating changes to the project environment
Suppose your team is going through a node version upgrade from version x to version y. What would be the process like if we are not using a containerized dev environment? Every developer on the team would need to download and use the correct version before starting development again. On the other if we version and release our dev image as environment dependencies change, all that needs to be done is to pull the correct image.