Add DevContainer
Docker gives us a consistent, isolated runtime environment for our application. Now we need a consistent, isolated environment for development. That's the purpose of a development container. A development container is a Docker container that has all of the development dependencies installed into a container so that developers develop using the exact same set of tools, configured the same way. This helps ensure that the results of one developer are "easily" reproducible by other developers.
VS Code provides a framework for creating development containers, called devcontainers. Essentially, we create a subdirectory named .devcontainer
in the root of the project which contains configuration files for building a Docker container that has all of the development tools installed and configured.
All devcontainers have only three dependencies:
- Docker
- VS Code
- The
Remote Container
VS Code extension
With these installed, a developer can open any project's devcontainer, regardless of the technology used in that project. When a developer opens a project in VS Code, if that project has a .devcontainer folder, VS Code will ask if the developer if they want to reopen the project inside the devcontainer. Selecting "yes", VS Code will build the devcontainer if it does not exist and run it. If the container already exists, it runs that container. After that, the developer is free to work on the project inside the container with all of the development dependencies installed!
As a project evolves it will be important to ensure that the project can still be developed inside a fresh devcontainer. This should be relatively "easy" as one can delete the existing devcontainer and build a new one to see if it still works. This ensures that new developers will "easily" be able to reproduce the results of other developers.