I am considering an architecture where I am deploying a JavaEE web application on JBOSS running inside a docker container.
Since it is a very simple application, I am considering using a embedded database like derby or h2.
However, If a need to deploy a new version of this application, the data inside the database must be kept.
So, it is rather a silly question, but I need to confirm that my assumptions are correct.
Assumptions (correct or not):
If I stop the docker machine and start it again, the data will be lost.
If I keep the docker container running and deploy a new version of the *.WAR file, NO data will be lost
I can create a sql script to run on startup and populate the database, but all user generated data will be lost.
The data should not be kept in the container, you want to place it inside of a volume. Typically this would either be a host based volume, or you can place it in a named volume or another docker container. So when running the database container:
docker run -v
pwd/dbdata:/data mydb:latest
This will mount ./dbdata inside of your container as /data and survive restarts and upgrades. With host based volumes, you need to manually initialize the contents, it will not include any volume data that was created inside of the image via the Dockerfile.