将.Net Core WebApi附加到Docker容器时ps不起作用 [英] ps not fount when attaching .Net Core WebApi to Docker container

查看:70
本文介绍了将.Net Core WebApi附加到Docker容器时ps不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Docker调试.Net Core webApi项目.但是,我正在努力使其正常工作.

我正在关注

因此,docker容器正在运行.现在,我想使用 Visual Studio代码对其进行附加.当我单击调试选项上的绿色箭头时:

我收到此错误:

在搜索错误时,我发现我们需要使用apt install(解决方案

您已在基本映像中安装了软件包,而应将其安装在将要使用 ps 的最终映像中./p>

  FROM mcr.microsoft.com/dotnet/core/aspnet:3.1运行apt更新&&\apt install -y procpsWORKDIR/app复制--from = build-env/app/out.ENTRYPOINT ["dotnet","BooksApi.dll"] 

构建和测试

  docker build -t myapp.docker运行-it --rm --entrypoint bash myappps 

I am trying to debug my .Net Core webApi project using Docker. However, I am struggling to make it work.

I was following this link, to attached my .Net Core app on Docker using VS Code.

This is my Dockerfile

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env

#install debugger for NET Core
RUN apt update && \
    apt install -y procps && \
    curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l /vsdbg

WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "BooksApi.dll"]

Then, I added the launch.json in order to attached the Docker container process:

"configurations": [
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickRemoteProcess}",
            "pipeTransport": {
                "pipeProgram": "docker",
                "pipeArgs": ["exec", "-i", "forecastapp"],
                "debuggerPath": "/vsdbg/vsdbg",
                "pipeCwd": "${workspaceRoot}",
                "quoteArgs": false
            },
            "sourceFileMap": {
                "/app": "${workspaceRoot}"
            }
        }
]

Those two files seems to be fine at first glance. So when building and running it on Docker everything is OK.

Docker build command:

docker build -t myweatherforecastapp .

Docker run command

docker run -it -p 8080:80 --name forecastapp myweatherforecastapp

Until this point everything is working fine. I can hit the end point.

So, the docker container is running. Now I want to attached it using Visual Studio Code. When I click on the green arrow on the debug option:

I am getting this error:

When googling the error, I saw that we need to install procps using apt install (link). That's already covered on my Dockerfile:

 apt install -y procps 

I am kind of running out of ideas what might be wrong or if I am missing something. Could you help?

Thanks in advance.

解决方案

You installed package in the base image, while it should be installed in the final image where you are going to use ps.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
RUN apt update && \
    apt install -y procps
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "BooksApi.dll"]

Build and test

docker build -t myapp .
docker run -it --rm --entrypoint bash myapp
ps

这篇关于将.Net Core WebApi附加到Docker容器时ps不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆