Summary of steps for developing in Docker container with VS Code

Introduction

I can't deny the feeling now, but I often forget how to write devcontainer.json, so I'll leave it in the article as a memorandum for myself.

Installation procedure

Add extensions to VS Code

To connect to the development environment inside the Docker container with VS Code, the extension Remote Development You will need it, so let's install it.

remote_containers_vscode.png vscode.png)

Add devcontainer.json

After adding the extension, let's prepare the configuration file devcontainer.json and the storage folder.

/ProjectRoot
  └ .devcontainer
      └ devcontainer.json

Create a .devcontainer folder under the root folder of the project you want to use Remote Development, and create a devcontainer.json there.

In devcontainer.json, describe the definition of the Docker container to be expanded as shown below (docker-compose.yml in the example below), the VS Code extension you want to use, the port forwarding settings, etc. To go.

{
    "name": "sample_project",
    "dockerComposeFile": "../docker-compose.yml",
    "service": "web",
    "extensions": [
        "mhutchie.git-graph",
    ],
    "forwardPorts": [
        8080
    ],
    "workspaceFolder": "/app",
}

For details on how to set it, please read the official document devcontainer.json reference, but it has been translated into Japanese. Besides, there are many setting items, so I picked up the setting items that I often use and summarized them.

image

A single Docker container used for development Docker Hub, [Azure Container Registry](https://azure.microsoft.com/ja-jp/services/container- Set when referencing from registry /). (Both require login, so you need to have an account in advance.)

dockerFile

Set up a single Docker container for development when using a local Dockerfile.

dockerComposeFile

Set multiple Docker containers used for development when using local docker-compose.yml. (It is necessary to set service, which will be described later, to uniquely set the container to actually board.)

Please note that the path to the specified docker-compose.yml must be relative to devcontainer.json. (If you put it under the root of the project, it will be ../docker-compose.yml.)

service

This item is indispensable when using dockerComposeFile, and set the service name of the container to be actually loaded during development from the definition of docker-compose.yml. (In the case of web services, I think that it will be a container for application servers in most cases)

Recommended Posts

Summary of steps for developing in Docker container with VS Code
Docker management with VS Code
Getting Started with Docker with VS Code
Japanese setting of mysql in Docker container
Make a snippet for Thymeleaf in VS Code
Docker Container Operations with Docker-Client API for Java
[Rails5.2] Support for emoji of Mysql 5.7 in Docker (change character code to utf8mb4)
Summary of frequently used commands in Rails and Docker
Link Docker log to AWS CloudWatch and monitor in real time with VS Code
Lombok with VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Build ruby debug environment with VS Code of Windows 10
Build Java development environment with WSL2 Docker VS Code
Create a Java (Maven) project with VS Code and develop it on a Docker container
Workspace setting location when connecting remotely with VS Code and working on a Docker container
Wait for the container service to start with docker healthcheck
Getting Started with GitHub Container Registry instead of Docker Hub
Run VS Code on Docker
Format Ruby with VS Code
Preparation for developing with Rails
Hello World with VS Code!
[Java] Summary of for statements
[Introduction] Setting up GridDB Community Edition in the CentOS container of Docker Desktop for the first time
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
I created a Docker image of a container for learning OpenAI Gym
Until you run Hello World of JavaFX with VS Code + Gradle
Building a haskell environment with Docker + VS Code on Windows 10 Home
[Code Pipeline x Elastic Beanstalk] Summary of errors and countermeasures for CI / CD Java applications to Elastic Beanstalk with Code Pipeline
[For beginners] Summary of java constructor
Environment construction with Docker for beginners
Java Spring environment in vs Code
Spring Boot programming with VS Code
Summary of frequently used Docker commands
Java build with mac vs code
docker single container restart for myself
[Linux] Start Apache container with Docker
Build WebRTC Janus with Docker container
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
For the time being, run the war file delivered in Java with Docker
Enable automatic html tag generation in erb when working with VS Code
Starting with installing Docker on EC2 and running Yellowfin in a container
How to execute with commands of normal development language in Docker development environment
[Summary of technical books] Summary of reading "Introduction to Docker / Kubernetes Practical Container Development"
Run Redmine in the local environment of Windows10 Pro-Use Docker Desktop for Windows
Install Zabbix 5.0 with Docker → Set up Slack notification in case of failure
Summary of Docker understanding by beginners ⑤ ~ Until deploying docker container on EC2 instance ~
Try remote debugging of Java with Remote Containers in Visual Studio Code Insiders
How to start a Docker container with a volume mounted in a batch file
Create a container image for arm64 of Kibana and register it in GitHub Container Registry. Start Elastic Stack with Docker Compose on Raspberry Pi 4 (64bit)