DEV Community

Cover image for 9 reasons why you should use Docker as a development environment
Dániel Gál
Dániel Gál

Posted on • Updated on

9 reasons why you should use Docker as a development environment

I have been developing React apps in Docker for a few years now, and so far nothing was able to stop me from containerizing every project I get started with.

This article is perfect for you if you read about containers or already started playing around with them, but you are not yet sold on the idea of using them as a development environment. If you have no idea what a container is, check out the links at the bottom.

This is more of a "meta" writing about container based development, not a guide on getting started with it. If you are looking for some tutorials, hit up the search bar above.

https://images.unsplash.com/photo-1593824854968-7833add41c16?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80Photo by Noel Broda on Unsplash

No clutter on your PC

Know the feeling of working on multiple projects and having 4 versions of Node, 2 versions of Python and 3 separate database management software installed on your machine? Do you have the habit of starting a new project every few months to try out a new trending technology, but during the struggle of setting it up and getting a "Hello World" app to work you lose your motivation?

With Docker, all the software required to run your app is inside the container. This gets us to the next reason:

No other software needed

At least not on the host computer (your machine). Given a fresh install of Windows, macOS or Linux, once you install Docker, you can just clone the project repository and fire up your app. If you set the environment up right, it should work out of the box.

Isolated environment

What happens in the container, stays in the container. You can install all the dependencies you want, it will not affect your host machine. The opposite applies too, the other software installed on your computer will not interfere with your app in the container.

Works anywhere

If a computer has Docker installed, you can develop your app on it without effort. If you want your friend or colleague involved in creating your app, they don't have to spend hours installing software and dependencies. The just need to give one universal command and they are ready to go. If you don't like taking your computer to and from the office you work at, you can have the same environment on both machines with Docker. You can even set it up on a server and attach to it remotely.

https://images.unsplash.com/photo-1528660493888-ab6f4761e036?ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80Photo by Steve Halama on Unsplash

Easy cleanup

Once you are done with a project, just delete the image and any containers you created, and you're good. It doesn't take up space on your machine anymore. If you change your mind, you can build it again with one single command. Without Docker, you would have to remember all the software you installed just to get a project running, and get rid of them individually to free your computer from the stuff you don't use anymore.

Easy on disk space

Not everybody has terabytes of SSD storage these days. Maybe you only own a 256 GB drive, like me. Working on multiple projects, having 5 different IDEs and many libraries installed takes its toll on your storage space. With Docker, if you put a project on hold, you can just delete its images and containers from your computer. You can easily build it again if you want to continue and you will get the same environment.

It is also possible to persist files across builds with the help of volumes, so you don't have to delete and recreate some parts of your app every time, for example a database.

Gateway to production

The skills learned trying to configure a Docker environment for the development process might come in handy when you're shipping your app. Chances are you will deploy it on some kind of cloud infrastructure that supports containers like Kubernetes.

CI/CD

Some CI/CD providers (like CircleCI) offer the possibility of using containers in your builds. Since your environment is already a container, little to no configuration is needed to make your app test and deploy itself automatically.

https://images.unsplash.com/photo-1556075798-4825dfaaf498?ixlib=rb-1.2.1&auto=format&fit=crop&w=1055&q=80Photo by Yancy Min on Unsplash

VSCode Remote - Containers

This VSCode extension is so great, it deserves its own section. To be honest, it is the main reason why I wanted to share this knowledge with you.

Before this extension existed, if we wanted to edit the code in the container without restarting it every time we made a change, we had to mount the project folder as a volume. If you changed the file on the host computer, it changed in the container as well. This had (still has) some problems.

Technology reliant on filesystem events like live reloading were a pain to work with. They were not as reliable because the filesystem events did not happen in the container (a shortcoming of mounted volumes), and on many occasions polling was required, draining your computer's processing power just to watch file changes.

With VSCode Remote - Containers, these problems don't exist. You can attach VSCode to the container itself, open the project folder inside it and get to work. The file changes now happen inside the container, no need for polling or mounting the code as a volume.

Mounting the code is still a good idea though, if you want to use version control software on the host computer (a Git client like GitKraken for example).

Check out the VSCode docs on developing inside a container.

Conclusion

The community behind Docker based development environments is strong. The most popular languages, runtimes and frameworks like Node, Python and Ruby have a plethora of guides to help you Dockerize your development experience. If the reasons listed in this article made you curious about this way of creating software, make sure to try it out!

If you decide to go with Docker for your next project, check out these tips to improve your productivity:

Other useful resources

Check out these writings on Docker and containers in general:

This article is also available on Medium.

Top comments (2)

Collapse
 
nikaizuddin profile image
Nik Mohamad Aizuddin

4 months ago I tried Docker 19.03.8 with WSL 2 backend on Windows. Unfortunately Docker on Windows consumes a lot of memory, about 4 times more than Linux does. I need to run Docker within virtual machine to prevent this memory issue.

So now most of the time, I'm using Docker/Podman within Vagrant box and provision with Salt.

Collapse
 
lyrod profile image
Lyrod

Problem with Docker on macOS is that docker is very slow and the mac turns at 100% cpu speed for a simple app (symfony, nestjs, react (cra) for example).

I only use docker to have a database for every project for now