DEV Community

Chandra Shettigar
Chandra Shettigar

Posted on • Originally published at devteds.com on

Multi-Container Local Development Setup using DevContainers in VSCode

As an application or web developer, it’s crucial to have an isolated yet seamless local development setup, especially when managing multiple applications or codebases across various microservice apps built on different programming languages, versions, or frameworks.

If you’ve used Docker for local development, you might be familiar with Docker Compose for handling multiple container setups. While this is helpful in many ways, it requires an extra step of entering a running container to execute ad hoc commands.

For instance, if you’re a Rails developer, you often need to run commands like rails generators, db migrations, rails runner, and especially the rails console. Similar challenges exist for most frameworks.

Imagine if you could open your editor in a container mode that loads the application environment and allow us to run application commands in the embedded terminal, without needing to run commands like docker run, docker exec, etc. This would make working within a containerized environment much easier.

One option that has worked well for my local development setup is the Dev Containers extension in VSCode. Not only does it allow you to load the application in VSCode within a container context, but you can also run dependency services (or other tiers of the application stack) as containers. The Dev Containers extension integrates smoothly with Docker Compose.

In this short tutorial, I’ll guide you through setting up a local development environment for an application that uses a database, both running as containers using Docker Compose and Dev Containers in VSCode. Here’s a quick breakdown of the steps you’ll learn in the tutorial:

  1. Start by creating a Dev Container setup for your application
  2. Create a web application using the Dev Container
  3. Configure a multi-container setup with Dev Container for the application and database containers
  4. Test and verify, mainly database container, using Docker Desktop
  5. Link the application running as a container with the database running as another container
  6. Conclude with a note on Multi-Stage Docker Build with DevContainer & Docker Compose

Setting up a reliable local environment can significantly enhance productivity for app developers. I hope this short video tutorial proves helpful!

Top comments (0)