Skip to content

Consider using volumes #3

@eiximenis

Description

@eiximenis

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:

  • Using a bind mount to share the source code with container
  • Using a bind mount to share nuget cache
  • Using a bind mount to share vsdbg with the container (for this to work you need to download vsdbg on your host of course)
  • Stay on "base" stage
  • Redefining entrypoint to "do nothing"

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions