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
.
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.
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.
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:
- Work with a service defined in an existing, unmodified docker-compose.yml.
- Create a new docker-compose.yml (or make a copy of an existing one) that you use to develop a service.
- Extend your existing Docker Compose configuration to develop the service.
- 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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With