无法使用Visual Studio 2017调试我的Docker容器

时间:2018-11-01 13:50:58

标签: docker asp.net-core .net-core docker-compose asp.net-docker-extensions

我无法使用Visual Studio 2017调试Docker容器。

我正在使用Docker 18.06.1-ce和VS 15.8.8。

在VS(控件+ F5)中启动调试会话时,容器可以正常启动,但未连接VS。容器还保持运行状态,并且dev模式启动。如果要杀死它,必须使用docker stop a76244870ffe

运行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

在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"]

2 个答案:

答案 0 :(得分:1)

Ctrl + F5 是无需调试器即可启动的快捷方式。尝试 F5 而不使用 Ctrl

答案 1 :(得分:1)

Solution Configuration设置为Debug,然后按 <CTRL + F5> 构建docker image并在本地运行。

点击<F5>开始调试。