0

I have an application consisting of a Flask web application and a RQ worker application. Both live in separate containers but use the same image. I would like to use Visual Studio Code's Remote Extension to run the containers and debug inside them. This all works well for either container using devcontainer.json and the automatically generated .devcontainer/docker-compose.yml which overwrite mine partially.

This Article explains that connecting to multiple containers is possible using multiple windows. They assume the two containers to have different source, stored in different folders which can be used to store separate devcontainer.json files.

I don't understand though how to configure the startup. When starting any of the two containers I would need the other one to start as well. That's easily achieved using the original docker-compose.yml. I could then manually run and debug the application in the started devcontainer.

Yet how would I connect to the other, then also running container and run and debug there?

rioV8
  • 24,506
  • 3
  • 32
  • 49
nehalem
  • 397
  • 2
  • 20

1 Answers1

0

First, install the Docker extension. In VS Code, you can right-click on the docker-compose.yaml File and click on compose up to start all the containers. You debug your script in exactly one terminal shell. This is the reason why you have just one VS Code window per container.

However, you can attach VS Code afterwards to as many already started containers as you like (e.g. after docker compose up) by right-click on the container and click on Attach Visual Studio code in the Docker tab.

danlooo
  • 10,067
  • 2
  • 8
  • 22
  • Thank you for your reply. Attaching after startup works indeed. I wonder though how to attach the debugger to the already running process, say the running Flask app. – nehalem Oct 19 '21 at 08:21
  • Does [this](https://stackoverflow.com/questions/60440765/how-can-i-attach-to-a-specific-process-in-visual-studio-code) help you? – danlooo Oct 19 '21 at 09:40