Movatterモバイル変換


[0]ホーム

URL:


TryMCP servers to extend agent mode in VS Code!

Dismiss this update

Debug containerized apps

The Container Tools extension provides more support for debugging applications within containers, such as scaffoldinglaunch.json configurations for attaching a debugger to applications running within a container.

The Container Tools extension provides adocker debug configuration provider that manages how VS Code will launch an application and/or attach a debugger to the application in a running container. This provider is configured via entries withinlaunch.json, with configuration being specific to each application platform supported by the provider.

The Container Tools extension currently supports debuggingNode.js,Python, and.NET applications within containers.

Requirements

Scaffolding or pasting a launch configuration intolaunch.json isnot sufficient to build and debug a container. To successfully run a container launch configuration, you must have:

  • A Dockerfile.
  • docker-build anddocker-run tasks intasks.json.
  • A launch configuration that invokes these tasks.

We recommend using theContainers: Add Docker Files to Workspace... command to create these items, if none of these assets already exist. If you already have a functional Dockerfile, we recommend using theContainers: Initialize for container debugging command to scaffold a launch configuration and container-related tasks.

Node.js

More information about debugging Node.js applications within containers can be found atDebug Node.js within a container.

Examplelaunch.json configuration for debugging a Node.js application:

{  "configurations": [    {      "name":"Containers: Node.js Launch",      "type":"docker",      "request":"launch",      "preLaunchTask":"docker-run: debug",      "platform":"node"    }  ]}

Python

More information about debugging Python applications within containers can be found atDebug Python within a container.

Examplelaunch.json configuration for debugging a Python application:

{  "configurations": [    {      "name":"Containers: Python - Django",      "type":"docker",      "request":"launch",      "preLaunchTask":"docker-run: debug",      "python": {        "pathMappings": [          {            "localRoot":"${workspaceFolder}",            "remoteRoot":"/app"          }        ],        "projectType":"django"      }    }  ]}

.NET

You can choose between two ways of building and debugging your project within containers:

  • With .NET SDK: If you are familiar withMSBuild or want to containerize your project without a Dockerfile, this is the recommended choice.

    Note: This option is only available for .NET SDK 7 and above and uses thedotnet publish command to build the image.

  • With a Dockerfile: If you prefer customizing your project with aDockerfile, choose this option.

For more details about these two options, refer toDebug .NET within containers.

Examplelaunch.json configuration for debugging a .NET application usingDockerfile:

{  "version":"0.2.0",  "configurations": [    {      "name":"Containers: .NET Launch",      "type":"docker",      "request":"launch",      "preLaunchTask":"Run Container",      "netCore": {        "appProject":"${workspaceFolder}/project.csproj"      }    }  ]}

Configuration reference

PropertyDescription
containerNameName of the container used for debugging.
dockerServerReadyActionOptions for launching a browser to the container. Similar to serverReadyAction, but replaces container ports with host ports.
removeContainerAfterDebugWhether to remove the debug container after debugging.
platformThe target platform for the application. Can benetCore ornode.
netCoreOptions for debugging .NET projects in containers.
nodeOptions for debugging Node.js projects in containers.
pythonOptions for debugging Python projects in containers.

dockerServerReadyAction object properties

PropertyDescription
actionThe action to take when the pattern is found. Can bedebugWithChrome oropenExternally.
containerNameThe container name to match the host port.
patternThe regex pattern to look for in Debug console output.
uriFormatThe URI format to launch.
webRootThe root folder from which web pages are served. Used only whenaction is set todebugWithChrome.

node object properties

These properties are the same as those described in theVS Code documentation for attaching a debugger to Node.js applications. All properties passed in thenode object will be passed on to the Node.js debug adaptor, even if not specifically listed below.

PropertyDescriptionDefault
portOptional. The debug port to use.9229
addressOptional. TCP/IP address of the debug port.
sourceMapsOptional. Enable source maps by setting this totrue.
outFilesOptional. Array of glob patterns for locating generated JavaScript files.
autoAttachChildProcessesOptional. Track all subprocesses of debuggee and automatically attach to those that are launched in debug mode.
timeoutOptional. When restarting a session, give up after this number of milliseconds.
stopOnEntryOptional. Break immediately when the program launches.
localRootOptional. VS Code's root directory.The root workspace folder.
remoteRootOptional. Node's root directory within the container./usr/src/app
smartStepOptional. Try to automatically step over code that doesn't map to source files.
skipFilesOptional. Automatically skip files covered by these glob patterns.
traceOptional. Enable diagnostic output.

python object properties

PropertyDescriptionDefault
hostThe host for remote debugging.
portThe port for remote debugging.5678
pathMappingsMaps the project path between local machine and remote host.
projectTypeThe type of your Python project,flask for Flask projects,django for Django,fastapi for FastAPI, and general for others. The project type will be used to set the port and commands used for debugging.
justMyCodeDebug only user-written code.
djangoDjango debugging.false
jinjaJinja template debugging (such as Flask).false

netCore object properties

Properties passed in thenetCore object are generally passed on to the .NET debug adaptor, even if not specifically listed below. The complete list of debugger properties is in theOmniSharp VS Code extension documentation.

PropertyDescription
appProjectThe .NET project (.csproj, .fsproj, etc.) to debug.

Next steps

Read on to learn more about:

12/14/2023

[8]ページ先頭

©2009-2025 Movatter.jp