Search code examples
c#dockerfilecontainers

Docker: writing a file to physical or shared path, using docker and netcore3.1


what I'm trying to do is simply write files to a path

private string CreateIfMissing(string path)
    {
        path = Path.Combine(_options.baseBath, path);

        if (!Directory.Exists(path))
            Directory.CreateDirectory(path);

        return path;
    }

Suppose my storage base path is D:\STORAGE_ROOT

it works fine until I run it using a docker container, it results to create the full path again inside my app folder.

C:\App\MyRunningAppFolder\D*\STORAGE_ROOT\path_value.

Is there a way to enable or force the directory to point on the sent path, not the app path


Solution

  • The first solution that comes to my mind is to volume mount your external directory (storage base path) to an internal directory in your container.

    Then, you can create the directories in that internal directory, and these directories will also be created in your storage base path.

    The code will then need to use this internal directory as path.

    Docker Volumes