I am writing in C# core, using linux container (running in windows).
I need a way to use external configuration file, and a way in programming (C# core code) to get the values of the configuration file.
That's without copy the docker configuration file into the image, used by:
docker cp ...
Need that for an existing container, without need to rebuild or run a new container instance for that (only by using the existing container).
Also, I need to map a volume to an existing container, without the need to rebuild or run a new container.
The following command is not suitable, since it creates a new container instance:
docker run -v ...
Need also a way to read some specific enviornment variables in C# core language, after use it as:
docker run -e ...
Is there any best practice for above?
Thanks.
It is extremely normal to need to delete and recreate containers. For instance, if you have a new build of your application, you’ll need to delete and recreate any containers that are running it to run against the new image. You can’t add a volume mapping to an existing container; but recreating containers should be so routine that it shouldn’t be a big deal to recreate it with the new volume mapping.
Using docker run -v
as a path to inject config files into a container is pretty normal. You can store it at a fixed path in the container, and use whatever config-file-parsing library you have readily available to read it. It can be anywhere on the host, but it’s fine to have a fixed value for the right-hand side of the docker run -v
option.
(The two other good things to use bind-mounted volumes for are getting log files out of a container, and storage of persistent data that lives in the filesystem but must outlive a single container instance.)