Skip to content

Instantly share code, notes, and snippets.

@kevnord
Last active April 25, 2020 08:38
Show Gist options
  • Save kevnord/e96e5a22f46d6ca1e0e7debb13b4684b to your computer and use it in GitHub Desktop.
Save kevnord/e96e5a22f46d6ca1e0e7debb13b4684b to your computer and use it in GitHub Desktop.
Debugging .NET Core in Docker Container with Visual Studio Code. Based on https://github.com/Microsoft/generator-docker/issues/130#issuecomment-287222915
version: '3.5'
services:
MY_PROJECT:
container_name: MY_PROJECT
image: MY_PROJECT:dev
build:
context: ./src
dockerfile: Dockerfile
target: debug
args:
buildconfig: debug
ports:
- "5001:80"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- DOTNET_USE_POLLING_FILE_WATCHER=1
entrypoint: tail -f /dev/null
volumes:
- ./src/MY_PROJECT/bin/Docker/:/app
- ~/.nuget/packages:/root/.nuget/packages:ro
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80
# DEBUG
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS debug
WORKDIR /app
EXPOSE 80
ARG buildconfig
# limit messages
ENV DEBIAN_FRONTEND noninteractive
RUN if [ "${buildconfig}" = "debug" ]; then \
apt-get update && \
apt-get install -y --no-install-recommends unzip && \
rm -rf /var/lib/apt/lists/* && \
curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l /vsdbg; \
else \
echo "*Skipping Debugger Installion *"; \
fi
ENV DEBIAN_FRONTEND teletype
# PUBLISH
FROM debug AS build
WORKDIR /src
COPY ./MY_PROJECT/MY_PROJECT.csproj ./MY_PROJECT/
COPY ./MY_PROJECT.Core/MY_PROJECT.Core.csproj ./MY_PROJECT.Core/
RUN dotnet restore "MY_PROJECT/MY_PROJECT.csproj"
COPY . .
WORKDIR /src/MY_PROJECT
RUN dotnet publish "./MY_PROJECT.csproj" -o /publish -c Release;
# FINAL
FROM base AS final
WORKDIR /app
COPY --from=build /publish .
ENTRYPOINT ["dotnet", "MY_PROJECT.dll"]
{
"version": "0.2.0",
"configurations": [
{
"name": "Docker: MY_PROJECT launch",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "publish",
"cwd": "/app",
"program": "/app/MY_PROJECT.dll",
"sourceFileMap": {
"/app": "${workspaceRoot}/src/MY_PROJECT"
},
"pipeTransport": {
"debuggerPath": "/vsdbg/vsdbg",
"pipeProgram": "/bin/bash",
"pipeCwd": "${workspaceRoot}",
"pipeArgs": [
"-c",
"docker exec -i MY_PROJECT /vsdbg/vsdbg --interpreter=vscode"
]
}
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/MY_PROJECT/MY_PROJECT.csproj", "-c", "Debug", "-o", "bin/Docker"
],
"problemMatcher": "$msCompile"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment