Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple devcontainers in vscode-remote

I have a project that creates multiple Docker images. I would like to setup a devcontainer in vscode-remote for each image so that I may spin up a container for each image.

I only need to spin up and connect to one container/image at a time.

Is it supported to have multiple devcontainer files? Maybe something like .devcontainer/devcontainer1.json and .devcontainer/devcontainer2.json (supposing I only had two images that I wanted to use)?

Each devcontainer would use an image with a different name and also requires different runArgs.

like image 286
Bidski Avatar asked Oct 30 '19 00:10

Bidski


People also ask

How do I connect to VS Code remote container?

To attach to a Docker container, either select Remote-Containers: Attach to Running Container... from the Command Palette (F1) or use the Remote Explorer in the Activity Bar and from the Containers view, select the Attach to Container inline action on the container you want to connect to.

How do I add a Dockerfile code in Visual Studio?

You can add Docker files to your workspace by opening the Command Palette (Ctrl+Shift+P) and using Docker: Add Docker Files to Workspace command. The command will generate Dockerfile and . dockerignore files and add them to your workspace.


1 Answers

Just found this here. I checked the documentation because I was interested in this as well. And the documentation states the following

In some cases, a single container environment isn't sufficient. Fortunately, Remote - Containers supports Docker Compose managed multi-container configurations.

You can either:

  1. Work with a service defined in an existing, unmodified docker-compose.yml.
  2. Create a new docker-compose.yml (or make a copy of an existing one) that you use to develop a service.
  3. Extend your existing Docker Compose configuration to develop the service.
  4. Use separate VS Code windows to work with multiple Docker Compose-defined services at once.

https://code.visualstudio.com/docs/remote/containers#_using-docker-compose

Maybe you want to check this.

Documentation for your use case can be found under the following page:

https://code.visualstudio.com/docs/remote/containers-advanced#_connecting-to-multiple-containers-at-once

You do this by using docker-compose.yml and need to have a folder structure like the following:

enter image description here

like image 177
Sebastian Schütze Avatar answered Dec 29 '22 12:12

Sebastian Schütze