DEV Community

Nikola Balic for Daytona

Posted on • Originally published at daytona.io on

Creating a development container

Creating a development container involves setting up a standardized and reproducible development environment that can run consistently across different workstations or CI/CD environments. This tutorial will guide you through the process of creating a basic development container using commonly used tools like Docker and Visual Studio Code (VS Code).

Prerequisites

  • Docker installed and running on your machine

  • Visual Studio Code with the Remote - Containers extension installed

  • Basic familiarity with Docker and VS Code

Step 1: Create a Dockerfile

A Dockerfile specifies the instructions to create the image for your development environment.

  1. Create a new directory for your project and navigate into it:

  2. Inside the directory, create a file named Dockerfile with the following content:

Step 2: Create a devcontainer.json File

The devcontainer.json file describes how VS Code should interact with the development container.

  1. In the same directory, create a file named devcontainer.json with the following content:

Step 3: Open the Project in VS Code

Open the directory you created in VS Code. Press F1 to open the command palette and select Remote-Containers: Reopen in Container. This will build the Docker image if it's not already built and start a container with your development environment, attaching VS Code to it.

Step 4: Develop Inside the Container

Now you are inside a containerized development environment. You can open a terminal in VS Code, and you'll be interacting with the shell inside the container. Install your project's dependencies, develop your code, and run your applications all within the container.

You can add more tools and dependencies you need for your project by modifying the Dockerfile and rebuilding the container.

Step 5: Maintaining the Dev Container

As you iterate over your dev container, you may find you need to add additional tools or modify settings. You can update the Dockerfile and devcontainer.json as needed, and rebuild your container to apply changes using the Remote-Containers: Rebuild Container command in VS Code.

Remember when you commit your project, include the .devcontainer folder with the devcontainer.json and the Dockerfile. This ensures that anyone who clones the repository can get started with the same environment.

Top comments (0)