How to deal with ProgramData folder when containerizing ASP.NET Core WebApi app?

I’m in the process of containerizing an ASP.NET Core 6.0 WebApi project.

I’m using a container, which seems to be based on Debian Bullseye.

I’m at the point where the image is running, but am not sure how to deal with ProgramData folders. Basically when I used to host the app on Windows, I would use the C:\ProgramData folder to store all changing data including logs, custom user image/audio uploads etc.

As an example let’s take logs. On Windows Server I was using NLog, to log to C:\ProgramData\MyCompany\MyApp\Logs. Now that the container is running on linux, that path no longer exists. I’m assuming those logs are just not going anywhere at that point.

What’s the right approach to correcting that?

  1. I’m assuming I need to modify my application logging destination to for example /data directory inside the container? The only reason I’m saying /data is because the actual app resides in /app, as per sample Dockerfile provided by Microsoft.

  2. Or is there a way I can use a volume command inside docker compose to direct the image to automatically map calls to C:\ProgramData\MyCompany\MyApp\ to /data?

Indeed, a folder like /data inside the container will do. Next, to map that folder to some other folder on your local disk (outside the container), see Use bind mounts | Docker Documentation. (I also recommend the other sections of that guide.)

So, you’ll need something like -v "C:\ProgramData\MyCompany\MyApp\:/data". (May need some escaping of the backslashes, I don’t know.)

Or just have Docker take care of persisting that data in a “volume” that Docker handles for you, but for which it’s harder to access that folder’s contents from your computer.

See Manage data in Docker | Docker Documentation.

1 Like