Orchestrating Visual Studio Code : Part 4 : Running Docker Containers
Previously, in part 3, we learned how to debug a container running in docker. In this section, we will learn how to run our containerized application without the debugger.
Unfortunately at this time, the
vsdbg
debugger for Visual Studio Code does not support attaching to a running process remotely. Instead, it listens for commands to start the application and, as a result, your docker application will not run without it.
Container AppSettings
Make a copy of your appsettings.json
file and call it appsettings.container.json
. This file will be used exclusively when the application runs inside of docker.
└───src
│ appsettings.container.json
│ appsettings.development.json
│ appsettings.json
│ Program.cs
│ Startup.cs
│ WebApp.csproj
For now we will leave it alone, but in a future post I will show you how to leverage this file to perform cross-container communications between multiple microservices.
Compose Method
We will be leveraging the compose
method we created earlier to add a new switch that does not set the REMOTE_DEBUGGING
environment variable. This will cause the Dockerfile
entrypoint to fire up the application instead of waiting for debug commands.
ENTRYPOINT ["/bin/bash", "-c", "if [ \"$REMOTE_DEBUGGING\" = \"enabled\" ]; then sleep infinity; else dotnet WebApp.dll; fi"]
case "$1" in
"clean")
clean
;;
"compose")
compose
;;
"composeForDebug")
export REMOTE_DEBUGGING="enabled"
compose
;;
*)
showUsage
;;
esac
Compose Task
We will add a new task to .vscode/tasks.json
that will call our compose()
method in the project-tasks.sh
script.
{
"label": "compose",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"osx": {
"command": "bash ./scripts/project-tasks.sh compose"
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated"
},
"problemMatcher": [],
"windows": {
"command": ".\\scripts\\project-tasks.ps1 -Compose"
}
}
Running our Task
At this point, press F1, select Tasks: Run Task
, and select compose
. Your docker container will build and run without a debugger attached. You will need to manually open your web browser to view the application at: http://localhost:5000/api/values
Conclusion
We have learned how to compose and run our docker container without attaching a debugger.
Source Code
https://github.com/christophla/blog-orchestrating-vscode/tree/part-4-running-containers
Next Post : Unit Tests
In the next post we will learn how to create a unit test project and a VS Code task to run them. We will also explore the GitLense
extension to support running and debugging individual tests from within the IDE.
Previous Post : Debugging Docker Containers
https://christophertown.com/orchestrating-vscode-debugging-docker