I am trying to create a Dockerfile for a webapp that uses a file database. I would like to be able to mount the file from the host * The file is at the root of the complete software installation, so it is not ideal for mounting this full directory.
Another problem is that before the first use, the database file has not yet been created. The first time user will not have a database, but another user can do this. I cannot "mount" anything during assembly. I suppose.
Perhaps it could work as follows:
- Start of the first / new database:
- Run the container (without mounting).
- Webapp creates a database.
- Stop container
- subsequent launches:
- Run the container with
-v to mount the file
It would be better if an extra start / stop is not needed for the user. Even so, I’m still looking for a way to make it user-friendly, perhaps using the “methods” to launch it (maybe I can determine the thing with the first load as part of docker-compose, as well as the “regular” method? )
How can I do this in simpel mode so that it is cleared for all users for the first time?
* The reason is that you can copy the Dockerfile and the database file as a backup and only be run with these two items.
** How to mount host volumes in docker containers in Dockerfile during build
source share