使用命名管道从容器内部访问 docker 引擎时出现 Docker.Dotnet UnauthorizedAccessException

发布于 2025-01-14 06:53:19 字数 1264 浏览 5 评论 0原文

我创建了一个 ASP.NET Blazor 服务器应用程序,它使用 Docker.DotNet 查询 Docker 引擎图书馆。我将应用程序构建为 Docker Windows 容器映像,并在运行容器时映射命名管道“\.\pipe\docker_engine”。在我的带有 docker 桌面的 Win10 开发机器上一切正常。我可以访问容器化 Blazor 应用程序并从主机获取容器列表。

现在,当我尝试在 Windows Server 2019 VM 上运行此映像时,出现异常(来自容器内的 Blazor 应用程序):

System.UnauthorizedAccessException: Access to the path is denied.
 at System.IO.Pipes.NamedPipeClientStream.TryConnect(Int32 timeout, CancellationToken cancellationToken)
 ...

如果我直接在服务器上部署并运行 Blazor 应用程序,则它可以正常工作。 我还在服务器上运行 Portainer 并且工作正常。

我是否需要在 Docker.DotNet 代码中配置一些特殊的内容才能使其在容器内部工作?

这是 Docker.DotNet 代码:

DockerClient client = new DockerClientConfiguration().CreateClient();
IList<ContainerListResponse> containers = await client.Containers.ListContainersAsync(
    new ContainersListParameters()
    {
        Limit = 100,
    });

这就是我启动容器的方式:

docker run -dt --restart=always -p 80:80 -e "ASPNETCORE_ENVIRONMENT=Production" --name DockerBlazor -v \\.\pipe\docker_engine:\\.\pipe\docker_engine dockerblazor:latest

欢迎任何想法:)

I have created an ASP.NET Blazor server app that queries the Docker engine using the Docker.DotNet library. I build the app as a Docker Windows container image and map the named pipe '\.\pipe\docker_engine' when running the container. Everything works fine on my Win10 dev machine with docker desktop. I can access the containerized Blazor app and get a list of containers from the host.

Now, when I try to run this image on a Windows Server 2019 VM I get an exception (from the Blazor app inside the container):

System.UnauthorizedAccessException: Access to the path is denied.
 at System.IO.Pipes.NamedPipeClientStream.TryConnect(Int32 timeout, CancellationToken cancellationToken)
 ...

If I deploy and run the Blazor app directly on the server, it works fine.
I also run Portainer on the server and it works fine.

Do I need to configure something special in the Docker.DotNet code to get it to work from inside the container?

This is the Docker.DotNet code:

DockerClient client = new DockerClientConfiguration().CreateClient();
IList<ContainerListResponse> containers = await client.Containers.ListContainersAsync(
    new ContainersListParameters()
    {
        Limit = 100,
    });

and this is how I start the container:

docker run -dt --restart=always -p 80:80 -e "ASPNETCORE_ENVIRONMENT=Production" --name DockerBlazor -v \\.\pipe\docker_engine:\\.\pipe\docker_engine dockerblazor:latest

Any ideas are welcome :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多彩岁月 2025-01-21 06:53:19

我想通了。
在 Dockerfile 中我需要添加

USER ContainerAdministrator

,现在它可以工作了。

I figured it out.
In the Dockerfile I needed to add

USER ContainerAdministrator

and now it is working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文