.Net Core API running under docker

2019-08-19 06:06发布

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

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 is /app and in DirectoryInfo FullPaths value is "/app/C:\TempFolder"

enter image description here

when I running app without docker it works fine

It may sound bad, but I have to ask:

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

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

1条回答
该账号已被封号
2楼-- · 2019-08-19 06:29

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

Or map docker volume using docker-compose.yml:

    volumes: 
        - my-volume:/app

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.

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.

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

查看更多
登录 后发表回答