'How to persist my appsettings.json to host machine from Docker container and mount that single file

I have an aspnetcore application that has been containerized and it is running properly, the value of the node ConnectionStrings in appsettings.jon file is being saved based on the value entered from the web interface when application is being setup and this file shouldn't be overwritten after the initial setup when application is updated as you know containers are ephemeral. I have a SetUpController for doing this and everything works well, the reason for doing this is the application runs on premise for most of our clients and they have different setups.

My question is how to ensure the appsettings.jon isn't overwritten when the container is updated. I want to be able to copy the file to a host volume after the application is successfully setup and mount the appsettings.json from the host volume the next time the application runs. I am using a linux container on windows and Docker Toolbox because the system where the application is run can't install Docker for windows.

How do I mount an appsettings.json stored on the host machine anytime the application run?

I have checked online for ideas but none of them seems to work.



Solution 1:[1]

I would use persistent storage for this the docker documentation on https://docs.docker.com/storage/ will explain much better than i how to use for your purpose.

Hope it helps

Solution 2:[2]

Thanks @pressharp This worked for me for Linux:

docker run -d --name=name
-p 80:80
-v /opt/dockertest2/appsettings.json:/app/appsettings.json
imagename

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 markorial
Solution 2 William Daugherty