Develop, build, debug or run a .NET Core app in a container using docker and docker-compose tools.
NOTE: Unless indicated otherwise, assume all shell commands will work in both bash and PowerShell.
- docker-compose enables building interop solutions with complex infrastructure in isolation.
- No hard-coded container names or process ID extraction necessary -- talk to each service by its predefined name.
- Keep your normal workflow, i.e. build, debug, run unit tests -- there's a minimum overhead to facilitate the container(s).
- Files with the
.debugsuffix are used in development. - Production configuration can be used for creating, publishing or running an image.
- Production image runs unit tests on build.
- Uses the
Directory.Build.propsfile to keep track oflocalvscontainerartifacts for rich coding sessions.
For simple coding sessions, all you need is git, docker and a source-code editor of your choice. Consider using vscode.
- Production image cannot be debugged (because there's no debugger embedded in the image).
- OmniSharp plugin with its integrated unit test runner in vscode run locally.
It is recommended to install .NET Core SDK. This would not be required, if OmniSharp tooling could target the container instead of the local build.
TODO: Figure out how to make OmniSharp target containers.
For local development, your must enable sharing with Docker either your local drive or root folder containing this solution. However, mounting volumes is not required for building a production image.
Building the environment is required the first time you clone this repository or if there's a change in the environment configuration. Either use the env-build task or run the following command manually.
docker-compose --file docker-compose.debug.yml buildYou should be able to follow your normal development process. Use the build, test or other predefined tasks in vscode. If you need to debug, set your breakpoint(s) and hit F5 (must use the .NET Core Docker Launch (console) launch configuration).
TODO: Add a launch configuration for debugging unit tests inside a container.
Execute the following command:
docker-compose buildNOTE, this is a simple configuration with one app service. You could opt to build an image from the Dockerfile directly. For complex setup with many services, it is recommended to use docker-compose at all times.
Depending on how you build your production image, the process may leave intermediary images behind. To reclaim the disk space, consider using the below command.
docker rmi $(docker images --filter dangling=true -q --no-trunc)This project was inspired by the following sources: