So, you want to be a serious developer? Welcome to the world of DevContainers. If you haven’t used them before, prepare to have your mind blown (in a good way). Let's dive in.
DevContainers are basically the magical "works on my machine" solution, but in a way that actually works. They let you define your development environment inside a Docker container, so no more "it works on my laptop, but not on yours" nonsense.
Think of them as your entire workspace in a box — from operating system to dependencies, tools, and configurations — it's all there. And yes, that means you can switch between projects or share your setup with others without the usual headache of installing different tools.
- Consistency: You get the same environment no matter where you run it.
- Portability: You can ship it, share it, or use it on any machine that can run Docker.
- Isolation: Every project gets its own sandbox. No cross-contamination of libraries or versions.
- Productivity: With everything pre-configured, you can get coding right away without setup time.
Now that you know the basics, let’s get to the real fun part: running these bad boys in VS Code.
Let’s keep this simple and efficient, like you, right? Follow these steps:
Make sure you have Docker installed on your machine. If not, download and install it. Trust me, it’s painless (mostly).
If you’re using VS Code (and you should be), go ahead and install the Dev Containers extension from the marketplace. Just search for "Dev Containers" and hit install.
Here comes the magic part:
- Open your project folder in VS Code.
- Hit Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the Command Palette.
- Type "Dev Containers: Reopen in Container" and hit Enter.
VS Code will now spin up a container based on the configuration in your project’s .devcontainer folder. Grab a coffee while Docker does its thing.
Once the container is ready, you’re all set to start coding! Everything will run in this isolated environment, and you won’t have to worry about messing with your local setup. Your terminal, extensions, and code are all running in this beautiful little box.
Want to tweak things? Of course you do. Look for a .devcontainer
folder in your project directory. Inside, you'll find configuration files like devcontainer.json
and docker-compose.yaml
where you can define the base Docker image, extensions, settings, and more. This is your playground. Go wild.
Our DevContainer setup includes multiple services to make your development environment as close to production as possible:
- Backend Service: Running NestJS, because we're fancy like that.
- MySQL Database: For all your relational data needs.
- Redis Cache: To cache or not to cache? Always cache.
- MongoDB Database: When NoSQL is the right answer (it often is).
All these services are defined in the .devcontainer
directory and are automatically set up when you open the project in the DevContainer. Talk about convenience!
A common question: What happens to my data when the container shuts down?
Good news — VS Code keeps your project files safe and sound on your local machine, but anything installed or saved inside the container (like logs, installed packages, etc.) will vanish unless you persist it with Docker volumes. This ensures you always start with a clean environment, but if you need persistence, just configure it in your Docker setup. Don't worry, our docker-compose.yaml
takes care of that by defining volumes for MySQL, Redis, and MongoDB data.
- Container won’t start? Check your Docker is running and the
.devcontainer
config is correct. - Performance issues? Give Docker more resources (CPU, memory) in its settings.
- Missing dependencies? Make sure your
.devcontainer
files include everything you need — this is where you define what’s installed in the container.
With DevContainers, you're stepping into a world where development environments are consistent, reproducible, and portable. No more "it works on my machine" excuses. You now have a reliable, professional-grade tool that keeps your workflow smooth and your sanity intact.
Enjoy the ride, and welcome to the future of development.