VSCode X Docker: Make a Comfortable Development Environment
Tags: vscode, docker, devops, programming
Published: 2024-05-02 14:00:00

## Introduction

Hello, my name is Ryo, and I am an engineer from WESEEK, Inc. in Japan. In this article, I would like to introduce how to build a dev container environment in a project using Docker and Visual Studio Code (VSCode) extensions.

Have you ever felt that installing specific programming languages or libraries when building a development environment is a hassle? Especially when installing directly on the host PC, it is very time-consuming because you have to proceed while checking whether there are any conflicts with the existing ones.

Once the dev container environment introduced in this article is built, it is no longer necessary to install individual programming languages and libraries when building a similar development environment. Thus, you can expect to save a great deal of time. This is very effective when developing with multiple developers.

We are sure that there are many people who are developing with VSCode, so please take time to read this article and learn how to make a comfortable development environment.

---

## The Environment Used In This Project

- macOS Catalina: v10.15.7
- VSCode: v1.65.0
- Remote — Containers: v0.224.2
- Docker Desktop: v20.10.12

See below for detailed system requirements:
https://code.visualstudio.com/docs/remote/containers#_system-requirements

---

## What Is a Dev Container Environment?
The dev container environment can be built using the VSCode extension “Remote — Containers”, and can be built on any OS as long as Docker and VSCode are available.

![remote-containers_1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/252knh2rgoo1tajl9u1i.png)

As shown in the figure above, when the dev container environment is launched, VSCode can access the Docker container and edit files on the VSCode container.

In addition, VSCode configuration, extensions, and installation of necessary languages and libraries can be stored in devcontainer.json and Dockerfile.

Thus, developers only need to install Docker and VSCode and open the project repository directory on VSCode to use the development environment.

---

## Quickly Build an Environment In 3 Easy Steps

Now, let’s build the dev container environment.

**1. Install Docker**
Please click on the following link to install the software:
https://www.docker.com/products/docker-desktop

**2. Install the extension “Remote — Containers” in VSCode**
We will add an extension to VSCode. In this case, we will install “Remote — Containers” since it is for accessing containers.

![remote-containers_2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ep0q4zpfd2spxqf0vvmn.png)

**3. Select “Reopen in Container” and setup**
Once the extensions are in place, you are almost ready to go.

- Firstly, click on the icon with the green background in the lower left corner of the VSCode screen

![Find the icon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezchay5u3tttcgv6x0fy.png)

- Then a menu will appear in the upper center of the screen, click on “Reopen in Container” and wait a moment.

![Reopen in Container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fvon5wv4rsc5sm2meco3.png)

- Select the environment you want to create

![Select environment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jphw6rmsodys3eqxp0oj.png)

The construction of the dev container environment is completed

---

## About `.devcontainer` Directory
When the environment is created by the above procedure, a directory named `.devcontainer` is created as shown below, and two files are automatically created under the directory.


![.devcontainer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nufr641pwzupd5x9r9up.png)

I will give a brief description of these two files

### devcontainer.json
This file is mainly used to describe VSCode settings. It can be used to describe VSCode extensions and settings that you want to standardize in your project.

Check here for more reference:
https://code.visualstudio.com/docs/remote/devcontainerjson-reference#_vs-code-specific-properties

### Dockerfile
This file describes the configuration of the container itself. We have posted blogs on Dockerfile in the past. For more details, please refer here.

You can also put docker-compose.yml instead of Dockerfile and make it readable.

### Docker-compose
In that case, the following definitions are required in the devcontainer.json file:
- dockerComposeFile
- service

Also, we have posted blogs on Docker-compose in the past. For more details, please refer [here](https://dev.to/weseek-inc/building-a-docker-development-environment-part-1-1lhe?preview=66c3d0de4257b518b013e65729031f9e4b7b0a27d03b0d5a7dc19ccff06758a9915755525f4349806eefa5af2003e6db9ac2441ee4d578bbc6dc50d6).

Check here for more reference: https://code.visualstudio.com/docs/remote/devcontainerjson-reference#_docker-compose-specific-properties

---

## Tips
Since the goal of this article is to build a dev container environment, it is necessary to proceed with the expansion of dockerfile/docker-compose in addition to building the dev container environment, depending on the project.

You can use common extensions in the dev container environment by entering the IDs of the VSCode extensions used in the dev container environment in the extensions of the devcontainer.json file.

You can enter the ID of the extension directly in the file, but as shown in the image below, search for the extension you want to add and select “Add to devcontainer.json” to automatically enter it in the extensions of devcontainer.json.

![add to devcontainer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zo12mxr15x9u7wmje5ej.png)

Thank you for reading and learning with me to create a dev container environment in 3 simple steps.

Why don’t you start now and try to build a dev container environment in the project you are participating in?

---

## About Us💡

In addition, we want to introduce a little more about GROWI, an open software developed by **WESEEK, Inc**.

**GROWI** is a wiki service with features-rich support for efficient information storage within the company. It also boasts high security and various authentication methods are available to simplify authentication management, including **LDAP/OAuth/SAML**.

**GROWI** originated in Japan and GROWI OSS is **FREE** for anyone to [download](https://docs.growi.org/en/admin-guide/?utm_source=dev+community&utm_medium=referral&utm_campaign=VSCode_Docker_Make_a_Comfortable_Development_Environment) and use **in English**.

For more information, go to [GROWI.org](https://growi.org/en/?utm_source=dev+community&utm_medium=referral&utm_campaign=VSCode_Docker_Make_a_Comfortable_Development_Environment) to learn more about us. You can also follow our [Facebook](https://www.facebook.com/people/GROWIcloud/100089272547238/) to see updates about our service.

![GROWI.org](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rhpa0qcdukeall2vfsj.png)