问题
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"
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:
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.
来源:https://stackoverflow.com/questions/48420989/net-core-api-running-under-docker