Making Oracle Database persistent with Docker

Mike Raab
Oracle Developers
Published in
3 min readAug 22, 2017

So you have built the latest Oracle Database EE v12.2.0.1 from GitHub. Now you want to deploy it in Oracle Container Cloud Service (OCCS).

Besides creating the Service YAML, there are some additional steps that you need to take, if you want your Oracle DB container to have persistent data on the Worker node volume: /opt/oracle/oradata

Note — There maybe other methods of accomplishing the same goal, the below is just one example.

Let’s review the steps for this example, including setting up a user in the Worker node, so that the Oracle DB in the Docker container can write to the local volume. If you do not take these steps, your container can not run successfully if it has a volume parameter. This is because the default user “oracle” in the database container does not have sufficient rights to write to the local host volume, and you need to enable it for security reasons.

This setup is not unique to OCCS. This is the case also, if you were just running the image natively via the command line on any Docker host.

Here is how to do it.

Create the Service YAML. Utilize the settings here in GitHub to setup your service. On this first iteration, do NOT include the Volume parameter yet.

Deploy the new service.

Once the container is running, you will need to use the Docker exec command to find the user id for the user “oracle”.

To do this, first, SSH into the Worker node that is running the database container. You can find the public IP of the Worker node on the Hosts page.

SSH into the Worker node and run these commands to exec into the container to get the user id:

$ ssh opc@<host ip address> -i path_to/privateKey

Run as root on the Worker node:

$ sudo -s

Find the container ID and exec into it:

# docker ps
# docker exec -i -t <imageID> /bin/bash
$ id

In this example, the user id is 54321, which is fairly typical.

Now, exit out of the container, create a new user on the Worker node, called “oracledb” with the same user id, and give that user, rights to /opt/oracle.

Note — the user “oracle” already exists on the Worker node, but does not use the same user id as the user “oracle” in the container. Therefore, you just need to create a new user of any unique name, utilizing the same user id as the container user.

$ exit
# useradd -u <userID> oracledb
# chown -R oracledb /opt/oracle

Next, stop and remove the deployment. Edit the database service to add back the volume parameter:

volumes:
- ‘/opt/oracle/oradata:/opt/oracle/oradata:rw’

Save the service and deploy again. In a few minutes (depending on how much OCPU your Worker node has) the DB container is fully setup and will persist its data. To see the progress of the database setup, just use the View Logs button on the container page until you see the message that the database is ready to use.

--

--