I wish I could update the settings of the application by changing the local profile.
I use "volume" to bind a local directory, for example:
docker run -v D:test:/app
But when the container is running, all files in /app are emptied, because D:test does not have any files.
Is there any way I can achieve my goal
3
Answers
That the way it works. Volume type you use is bind mount, i.e. you mount file system, using mount point mapped to a host directory.
According to documentation:
You have two options here (both imply host data should exist in advance):
Bind to a folder, containing configuration data. As you showed.
It is possible to bind only file:
docker run -v D:testconfig.json:/app/config.json
While binding to a file, if it does not exist beforehand, docker-daemon would think it is a directory and will create directory, both in container and on the host.
Hence, if host directory is empty mounted file system would also be empty.
Your question is a bit unclear. I guess you’re problem is the following: You want to bind mount your app directory, but it is initially empty and will stay empty since the bind mount overwrites everything put into
/app
during buildI usually use two different ways:
D:test
(if applicable). This is also a viable strategy for e.g. the source code of nodejs apps/app_temp
. Then create an entry point which moves/app_temp
into/app
. If you want to persist the profile through multiple build/run phases, it has to be inside the build context (which is likely notD:test
) on your host.You need to change a bit the way your application is organized. put all the settings in their own directory and have the application read them from there. Then you can map only the settings folder you the host one.
Another option is to map the host folder to a temporary folder inside the container and have the ENTRYPOINT script update your files (by copying them over) and then run your application.
Docker was not meant to be used for the workflow you are trying to setup and for this reason you need to do some extra work.