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?
Installation
First, install the Dev Containers extension in VSCode:
- Open VSCode
- Go to Extensions (Ctrl+Shift+X)
- Search for "Dev Containers"
- Install the extension from Microsoft
Creating Your First Devcontainer
All the dependencies and tools needed to run the code are defined in a single file called devcontainer.json, located in the .devcontainer folder of your repository.
Here's a minimal example for a Rust project:
{ "name": "Rust Development", "image": "mcr.microsoft.com/devcontainers/rust:latest", "customizations": { "vscode": { "extensions": [ "rust-lang.rust-analyzer", "tamasfe.even-better-toml" ] } }, "postCreateCommand": "cargo --version" } Opening Your Project in a Container
- Open your project in VSCode
- Press
F1and select "Dev Containers: Reopen in Container" - VSCode will build the container and reopen your workspace inside it
- That's it! You're now developing inside the container
Advanced Configuration
For more complex projects, you might want to customize further:
{ "name": "Rust Full Stack", "image": "mcr.microsoft.com/devcontainers/rust:latest", "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/devcontainers/features/node:1": {} }, "customizations": { "vscode": { "extensions": [ "rust-lang.rust-analyzer", "tamasfe.even-better-toml", "vadimcn.vscode-lldb" ], "settings": { "rust-analyzer.checkOnSave.command": "clippy" } } }, "forwardPorts": [3000, 8080], "postCreateCommand": "cargo build", "remoteUser": "vscode" } This configuration:
- 🐳 Enables Docker-in-Docker for building containers inside your devcontainer
- 📦 Includes Node.js for frontend tooling
- 🔧 Pre-installs essential Rust extensions
- 🚪 Forwards ports 3000 and 8080 for web development
- ⚙️ Runs
cargo buildafter container creation
Using Docker Compose
For projects with multiple services (database, cache, etc.), you can use Docker Compose:
{ "name": "Rust with PostgreSQL", "dockerComposeFile": "docker-compose.yml", "service": "app", "workspaceFolder": "/workspace" } And your docker-compose.yml:
version: '3.8' services: app: build: . volumes: - .:/workspace:cached command: sleep infinity postgres: image: postgres:15 environment: POSTGRES_PASSWORD: postgres POSTGRES_DB: devdb ports: - "5432:5432" Conclusion
Devcontainers eliminate the "it works on my machine" problem and streamline team onboarding. By committing your .devcontainer configuration to version control, you ensure every developer works in an identical environment.
Ready to try it? Create a .devcontainer/devcontainer.json in your next project and experience the difference!