.Net Core API在docker下运行 [英] .Net Core API running under docker

查看:247
本文介绍了.Net Core API在docker下运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目(.Net Core API),该项目在Windows的Docker下运行,并提供客户可以上传文件的服务。

I have a project (.Net Core API) which runs under Docker for windows and have service where customers can upload files.

我想将这些文件保存在服务器(例如 C:\TempFolder),但是当我在调试模式下(使用docker)运行项目并通过代码动态创建目录时,出现错误:'System.IO.IOException:无效参数...

I want to save these files on the server (for example "C:\TempFolder") but when I running project in debug mode (with docker) and creating directory dynamically from code there is an error: 'System.IO.IOException: Invalid argument..."

CurrentDirectory为/ app,在DirectoryInfo FullPaths中,值为 / app / C:\TempFolder

CurrentDirectory is /app and in DirectoryInfo FullPaths value is "/app/C:\TempFolder"

< a href = https://i.stack.imgur.com/llAxT.png rel = nofollow noreferrer>

当我在没有docker的情况下运行应用程序时,效果很好

when I running app without docker it works fine

听起来可能很糟糕,但我不得不问:

It may sound bad, but I have to ask:

是否可以创建目录(在我有权限的地方,例如在本地PC或服务器上)在docker下运行时?

is it possible to create directory (somewhere, where I have permission, for example on my local PC or the server) when running under docker?

这是我的第一个项目ng docker so ...

this is first project for me where I'm using docker so...

推荐答案

您可以使用 docker卷作为启动docker容器时的参数,或者具有在docker-compose中定义(如果使用的话)。

you can use docker volumes as arguments when starting docker container, or have volumes defined in docker-compose if you're using it.

docker volume create my-vol

docker run -d --name devtest --mount source=my-vol,target=/app

或使用docker-compose.yml映射docker卷:

Or map docker volume using docker-compose.yml:

    volumes: 
        - my-volume:/app

或映射到相对于docker的目录-compose.yml:

Or map to directory relative to docker-compose.yml:

    volumes: 
        - ./temp-dir:/app

请记住,容器内的代码不会知道某些文件夹已映射到容器外部的存储。

Have in mind that code inside container will have no idea some folder is mapped to storage external to container.

来自主机映射到docker卷和映射到相对路径之间的主要区别在于Docker将决定该卷在主机中的存储位置以及谁可以访问它,而相对路径是您控制的目录。

From host perspective main difference between mapping to docker volume and mapping to relative path is that Docker will be deciding where in the host that volume is stored and who can access it, while relative path is a dir that you control.

使用相对路径时要注意的另一点是确保您在目录上设置了权限,以便docker进程可以使用它。

Another point to note when using relative path is be sure you set permissions on your directory so docker processes can use it.

这篇关于.Net Core API在docker下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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