I created volume for storing my application database data - docker volume create dbvolume
.
Then I launched my docker container with Oracle XE 11g database image and data volume.
docker run --name=OracleXE --shm-size=1g -p 1521:1521 -p 8080:8080 -e ORACLE_PWD=weblogic1 -v dbvolume:/opt/oracle/oradata oracle/database:11.2.0.2-xe
Stored some entries in database. Stopped and removed container then launched it again, but no data persisted in database.
How can I get persisted data on subsequent requests to application.
Docker has an option to allow specific folders in a container to be mapped to the normal filesystem on the host. This allows us to have data in the container without making the data part of the Docker image, and without being bound to AUFS.
Volumes are the best way to persist data in Docker. Bind mounts may be stored anywhere on the host system. They may even be important system files or directories. Non-Docker processes on the Docker host or a Docker container can modify them at any time.
By creating a volume and attaching (often called “mounting”) it to the directory the data is stored in, we can persist the data. As our container writes to the todo.db file, it will be persisted to the host in the volume.
Because if we define a volume when we run a container, and that volume does not exist, Docker creates it for us. Thank you, Docker! Ok, now let's use the docker exec command to get into the existing postgres container and use psql. psql is an interactive terminal usedto create tables and inserts via SQL from the command prompt:
Create a volume by using the docker volume create command. docker volume create todo-db Stop and remove the todo app container once again in the Dashboard (or with docker rm -f <id>), as it is still running without using the persistent volume. Start the todo app container, but add the -v flag to specify a volume mount.
Let’s talk about how we can use Docker Volumes and SQL Server to persist data. If we want to run SQL Server in a container we will want to decouple our data from the container itself. Doing so will enable us to delete the container, replace it and start up a new one pointing at our existing data.
Accepted answer is not correct for Oracle 11g XE, that is asked in this question.
"/u01/app/oracle" should be mapped with a volume (e.g. -v dbvolume:/u01/app/oracle)
from https://github.com/oracle/docker-images/tree/master/OracleDatabase
-v /opt/oracle/oradata
The data volume to use for the database.
Has to be writable by the Unix "oracle" (uid: 54321) user inside the container!
If omitted the database will not be persisted over container recreation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With