sleemer / docker.dotnet.debug

This is a sample that demonstrates how to debug dotnet core 2.0 console running in docker from vscode
73 stars 14 forks source link

Consider using volumes #3

Open eiximenis opened 6 years ago

eiximenis commented 6 years ago

Hi, An option for allowing debugging without needing to recreate the container everytime is to use a volume to share vsdbg and the source code with the container.

Given a multistage Dockerfile, that builds your netcore image and a valid compose file that allows you to start it, you can write another compose file to debug your container:

version: '3.4'

services:
  api:
    image: myapi:dev
    build:
      target: base
    labels:
      - "com.microsoft.visualstudio.targetoperatingsystem=linux"
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - DOTNET_USE_POLLING_FILE_WATCHER=1
    volumes:
      - .:/app
      - ~/.nuget/packages:/root/.nuget/packages:ro
      - ~/vsdbg-core:/vsdbg:ro
    entrypoint: tail -f /dev/null

Key points:

Basically this compose makes my container to be "like the basic image" (base stage), and do nothing. Source code and vsdbg is provided through bind mounts. You can start the container once and "forget about it". Then just need a "docker exec" to run vsdbg on it.

Base stage is the typical initial stage in the Dockerfile:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
EXPOSE 80
# end of this stage
sleemer commented 6 years ago

Hi @eiximenis, thanks for sharing your solution. It's looks great, but the only problem that I can see is that you force everyone having nuget packages and vsdbg at the same path as you have. But that's not always possible. My original approach doesn't make any assumptions about your fs structure.

eiximenis commented 6 years ago

Hi! ;-)

About nuget packages, what is shared with container is the "nuget package cache folder" which is located in ~/.nuget (%USERPROFILE%\.nuget in win) in almost all nuget installations.

About vsdbg, you're true: need to download and store somewhere in your disk. Location is up to you, just update compose file to reflect your location. I. e. if you are in Windows and have VS installed with Docker Tools you already should have vsdbg in ~/vsdbg/vs2017u5 folder

Thanks!!