'How ro access docker volume files from the code on docker container

i have creted a docker volume with such command

docker run -ti --rm -v TestVolume1:/testvolume1 ubuntu

then i created a file there, called TestFile.txt and added text to it

Also i have a simple "Hello world" .net core app with Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0
COPY bin/Release/net6.0/publish/ ShareFileTestInstance1/
WORKDIR /ShareFileTestInstance1
ENTRYPOINT ["dotnet", "ShareFileTestInstance1.dll"]

I published it using

dotnet publish -c Release

then ran

docker build -t counter-image -f Dockerfile .

And finally executed

docker run -it --rm --name=counter-container counter-image -v TestVolume1:/testvolume1 ubuntu

to run my app with a docker volume

So what i want to achive to access a file which is in a volume("TestFile.txt" in my case) from a code in the container.

for example

Console.WriteLine(File.Exists("WHAT FILE PATH HAS TO BE HERE") ? "File exists." : "File does not exist.");

Is it also possible to combine all this stuff in a Dockerfile? I want to add one more container next and connect to the volume to save data there.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source