ps not fount when attaching .Net Core WebApi to Docker container

萝らか妹 提交于 2021-02-11 13:50:48

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/62905166/ps-not-fount-when-attaching-net-core-webapi-to-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!