Photo by Rubaitul Azad on Unsplash
Managing Dev Projects with Docker Dev Environments
Utilizing Docker Container as a full-featured development environment for a more efficient and streamlined workflow.
If you are a Windows user who enjoys developing applications in a GNU/Linux environment, you probably have the Windows Subsystem for Linux (WSL) installed on your system. With WSL, you can run a Linux OS directly on Windows without the overhead of a traditional virtual machine or a dual-boot setup.
The development experience using WSL is significantly better than developing on Windows OS. You can effortlessly install all the necessary development dependencies on WSL, just as you would on a Linux machine, without impacting the host system (Windows). It is fast and seamlessly integrated with the Windows OS.
Docker Container
However, WSL does come with some limitations. Imagine you are working on multiple projects that require different Python or Node.js versions. One solution is to use venv
for Python or nvm
for Node.js. This might work to some extent, but eventually, you may need to manage various dependencies on databases, APIs, or other services. At some point, your WSL environment could become cluttered with all kinds of dependencies, making it difficult to keep track of them.
This is where Docker Containers come into play to address these limitations. With Docker, each project, along with all its dependencies, is containerized within a single container, resulting in a completely isolated development environment. In this regard, Docker is more than just a virtual environment.
I am going to briefly describe Docker since there are already lots of articles available online covering this topic.
Docker is a containerization platform that allows you to package an application and its dependencies into a single image. This image can then be run on any machine that has Docker installed, regardless of the underlying operating system.
The main ingredient of Docker is Dockerfile
. It is a blueprint for building a docker image. Docker Image is a template for running a container and Dokcer Container is the running process of the image.
Benefits of Using Docker for Development
Here are some of the main benefits of using Docker as a development environment:
Consistency: Docker containers provide a consistent development environment for all developers, regardless of their operating system or machine configuration. This can help to prevent bugs and errors, and it can also make it easier to collaborate on projects.
Portability: Docker containers are portable, meaning that they can be easily moved from one machine to another. This makes it easy to deploy applications to production, and it can also help to reduce the risk of errors during deployment.
Efficiency: Docker containers are lightweight and efficient, which can help to save resources on development machines. This can be especially important for developers who are working on large or complex projects.
Overall, Docker is a powerful tool that can help developers to improve the efficiency and consistency of their development environment.
Docker Environments
Docker Environments (still in Beta at the time this article was written) is a new feature of Docker Desktop. It allows you to effortlessly create a configurable development environment. Under the hood, it takes advantage of the capabilities of Docker Compose
whilst simplifying it with an intuitive GUI.
You need to create a compose-dev.yaml
file to create a development environment. This file has the same constructs used for Docker Compose. It contains the configurations for all your application's services, such as mount volumes, ports, etc.
Here is an example of compose-dev.yaml
file.
services:
web:
build: .
ports:
- "8000:5000"
volumes:
- .:/code
- logvolume01:/var/log
depends_on:
- redis
redis:
image: redis
volumes:
logvolume01: {}
Summary
In this article, we discuss the benefits of using Docker Container for development in a Windows environment with WSL. We explain how Docker addresses the limitations of WSL, such as managing different dependencies for various projects, by providing isolated development environments. We also introduce Docker Environments, a new feature that simplifies the creation of configurable development environments, and discuss how using a Docker-based Linux development environment can save time, ensure consistency, and reduce errors.
What's Next?
In the next article, I will discuss how to utilize Docker Dev Environment to construct a development environment for cross-compiling a C++-based Raspberry Pi application.