[英]Debugging .NET console app with command line arguments within a docker container
I am debugging a .NET console application sitting within a docker container which works fine.我正在调试位于 docker 容器中的 .NET 控制台应用程序,该容器运行良好。
However, this is not so simple when I try to pass command line arguments via the launch.json / task.json files to the application.但是,当我尝试通过 launch.json / task.json 文件将命令行 arguments 传递给应用程序时,这并不是那么简单。 I would have thought this would be fairly common / simple but I have struggled to find anything at all, and my trial and error has got me nowhere.
我原以为这会很常见/很简单,但我一直在努力寻找任何东西,而且我的反复试验让我无处可去。 The remaining setup is pretty standard.
其余设置非常标准。
How would I pass command line arguments using launch.json and tasks.json?如何使用 launch.json 和 tasks.json 传递命令行 arguments? I have included my setup below.
我在下面包含了我的设置。
launch.json:发射.json:
"configurations": [
{
"name": "Docker .NET Core Launch",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"netCore": {
"appProject": "${workspaceFolder}/MyProject/MyProject.csproj",
},
},
tasks.json任务.json
{
"type": "docker-build",
"label": "docker-build: debug",
"dependsOn": [
"build"
],
"dockerBuild": {
"tag": "myproject:dev",
"target": "base",
"dockerfile": "${workspaceFolder}/MyProject/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
},
"netCore": {
"appProject": "${workspaceFolder}/MyProject/MyProject.csproj"
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build: debug"
],
"dockerRun": {
},
"netCore": {
"appProject": "${workspaceFolder}/MyProject/MyProject.csproj",
"enableDebugging": true
}
},
You can skip these configs and utilize command arguments in the docker entry point, it'll be more easier.您可以跳过这些配置并在 docker 入口点中使用命令 arguments ,它会更容易。
Set up a new scripts file, entry.sh设置一个新的脚本文件 entry.sh
#!/bin/bash
echo Arguments - "$@"
Prepare your dockerfile like this像这样准备您的 dockerfile
FROM ubuntu:22.04
COPY ./entry.sh /
chmod +x entry.sh
ENTRYPOINT ["/entry.sh"]
Build and run your docker image构建并运行您的 docker 映像
docker run mycontainer HelloWorld
And you'll see your arguments there !你会在那里看到你的 arguments !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.