dockerasp.net-core.net-coredocker-composeasp.net-docker-extensions

Unable to debug my Docker container with Visual Studio 2017


I am unable to debug my Docker container with Visual Studio 2017.

I am using Docker 18.06.1-ce and VS 15.8.8.

When starting a debug session in VS (control + F5), the container starts up fine but VS is not attached. The container also remains running and is not started in dev mode. I have to use docker stop a76244870ffe if I want to kill it.

Running docker container ls:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
a76244870ffe        myapplication       "dotnet MyApplicat.."    25 minutes ago      Up 4 minutes        0.0.0.0:80->80/tcp   dockercompose10819768170563966978_myapplicatio_1

docker-compose.yml:

version: '3.4'

services:
  myapplication:
    image: ${DOCKER_REGISTRY}myapplication
    build:
      context: .
      dockerfile: dockerfile
    ports:
     - "80:80"
    environment:
     - ASPNETCORE_ENVIRONMENT=local

Build output in VS:

1>------ Build started: Project: docker-compose, Configuration: Debug Any CPU ------
1>docker-compose  -f "C:\mylocation\docker-compose.yml" -p dockercompose10819768170563966978 --no-ansi config
1>The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
1>services:
1>  myapplication:
1>    build:
1>      context: C:\mylocation
1>      dockerfile: dockerfile
1>    environment:
1>      ASPNETCORE_ENVIRONMENT: local
1>    image: myapplication
1>    ports:
1>    - published: 80
1>      target: 80
1>version: '3.4'
1>docker-compose  -f "C:\mylocation\docker-compose.yml" -p dockercompose10819768170563966978 --no-ansi config
1>The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
1>services:
1>  myapplication:
1>    build:
1>      context: C:\mylocation
1>      dockerfile: dockerfile
1>    environment:
1>      ASPNETCORE_ENVIRONMENT: local
1>    image: myapplication
1>    ports:
1>    - published: 80
1>      target: 80
1>version: '3.4'
1>docker-compose  -f "C:\mylocation\docker-compose.yml" -p dockercompose10819768170563966978 --no-ansi config
1>The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
1>services:
1>  myapplication:
1>    build:
1>      context: C:\mylocation
1>      dockerfile: dockerfile
1>    environment:
1>      ASPNETCORE_ENVIRONMENT: local
1>    image: myapplication
1>    ports:
1>    - published: 80
1>      target: 80
1>version: '3.4'
1>docker-compose  -f "C:\mylocation\docker-compose.yml" -p dockercompose10819768170563966978 --no-ansi config
1>The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
1>services:
1>  myapplication:
1>    build:
1>      context: C:\mylocation
1>      dockerfile: dockerfile
1>    environment:
1>      ASPNETCORE_ENVIRONMENT: local
1>    image: myapplication
1>    ports:
1>    - published: 80
1>      target: 80
1>version: '3.4'
1>docker-compose  -f "C:\mylocation\docker-compose.yml" -p dockercompose10819768170563966978 --no-ansi up -d
1>The DOCKER_REGISTRY variable is not set. Defaulting to a blank string.
1>Starting dockercompose10819768170563966978_myapplication_1 ...
1>Starting dockercompose10819768170563966978_myapplication_1 ... done
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

dockerfile:

FROM microsoft/dotnet:2.1-sdk AS builder
WORKDIR /app
COPY ./src/myapplication/myapplication.csproj ./src/myapplication/myapplication.csproj
COPY nuget.config ./
WORKDIR ./src/myapplication/
RUN dotnet restore
WORKDIR /app
COPY ./src ./src
WORKDIR ./src/myapplication/
RUN dotnet publish myapplication.csproj -c Release -o publish
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runner
WORKDIR /app
COPY --from=builder /app/src/myapplication/publish/ .
ENV ASPNETCORE_ENVIRONMENT local
EXPOSE 80
ENTRYPOINT ["dotnet", "MyApplication.dll"]

Solution

  • Ctrl + F5 is the shortcut for starting without a debugger. Try F5 without Ctrl.