Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persisting data in docker's volume for Oracle database

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.

like image 318
tyomka Avatar asked Dec 07 '17 14:12

tyomka


People also ask

Which option allows containers to run with persistent volumes?

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.

Is Docker volume persistent?

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.

How do I persist data in a docker container?

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.

Why does Docker create a volume when I run a container?

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:

How do I create a todo-DB volume in Docker?

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.

How do I Run SQL Server in a docker container?

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.


2 Answers

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)

like image 156
nickolay.laptev Avatar answered Sep 21 '22 03:09

nickolay.laptev


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.
like image 38
Kilian Avatar answered Sep 23 '22 03:09

Kilian