Developing inside a container
As a developer, I am constantly discovering new repositories. I am always glad if they offer a devcontainer to spin up the dev environment.
What is a devcontainer, you may ask?
The Dev Containers extension for Visual Studio Code lets you use a docker container as a full-featured development environment.
This is a great way to get started with a project without having to worry about the setup. It is also a great way to ensure that the code runs in a consistent environment, regardless of the developer's local setup.
The well-known phrase "it works on my machine" best describes why you should use a devcontainer. But there are several other benefits of using it.
The benefits
- 🚀 Easy setup: Ensures a developer can quickly set up a development environment without having to install all the dependencies and tools on your local machine.
- 🔄 Consistency: Ensures that all developers are using the same environment.
- 🧩 Reproducibility: It allows you to easily reproduce the same environment on different machines.
- 📦 Portability: Also allows to share the container with other developers, making it easy to onboard new team members.
- 📝 Version control: You can version control the devcontainer configuration, which makes it easy to track changes and roll back to a previous version if needed.
- 🔒 Isolation: A devcontainer allows you to isolate your development environment from your local machine, which can help prevent conflicts with other projects or dependencies.
- ⚙️ Customization: You can customize the devcontainer to suit your needs, including installing additional tools and dependencies.
- 🛠️ Integration with CI/CD: You can use the same container in your continuous integration and continuous deployment (CI/CD) pipeline, which can help ensure that the code is tested and deployed in a consistent environment.
How to use it?
All the dependencies and tools needed to run the code are defined in a single file. This file is called devcontainer.json
and is located in the .devcontainer
folder of the repository.