How to Deploy an Oracle Database 19c Docker Container

The Oracle database is officially supported to run as a Docker Container and a prebuilt image can be pulled from the Docker Hub registry. However, the latest version available from the Docker Hub is over 3 years old and the latest database version is only Oracle Database 12cR2.

But do not despair, there is good news. If you are looking for an Oracle Database version 19c image, then that’s available for free at the Oracle Container Registry.

In this article I will guide you through the steps to get started with an Oracle 19c Database running as a Docker container. I will also include the steps to connect to the Database container from your host using SQLDeveloper

For this blog article my host is running Oracle Linux 7 and the Unbreakable Enterprise Kernel. The database container image requires a minimum of 8GB of disk space and 2GB of RAM.

Step 1: Install Docker

If you already have Docker installed on your system, you can skip this step. Otherwise, while connected as root run the following steps:

 Edit entries for ol7_latest, ol7_uekr4 and ol7_addons:
 > enabled=1

Documentation on installing the preinstall package including on Redhat Linux- https://docs.oracle.com/en/database/oracle/oracle-database/19/ladbi/running-rpm-packages-to-install-oracle-database.html

The following step is not necessary and can be skipped when running the Oracle Database as a container. However, I guess I am a creature of habit and am used to running the Oracle Database PreInstall package prior to installing an Oracle database on my Linux servers. One benefit from running the Preinstall package is that it can provide you with a sanity check to make sure your host system is capable of running an Oracle Database and that the Linux user you set up in your host matches the Oracle user inside your container.

Step 2: Sign in to Oracle Container Registry

The next step is to visit the Oracle Container Registry at container-registry.oracle.com. You will need an Oracle Account (it’s completely free to register) to download the image. The website is easy enough to navigate, and once you’ve decided on the image you will be using, you will need to accept the license agreement to use the container.

Once you have accepted the license agreement, take a note of the pull command that you will be using to get the Oracle database 19c image.

Step 3: Pull Database Container image

We’re now ready to go to the machine where we will be running the container. But before we can use the Docker pull command we will need to login to the Oracle container registry using our Oracle account. This will save an authentication token on our host.

Once logged-in we can pull the docker image.

The time to perform this step is dependent on your internet download speeds. You will be downloading several files, one of which is approximately 2.7GB in size. Once the pull operation has completed, you should see the following:

We can see the image we have just downloaded by using the Docker images command as follows:

Step 4: Run the Database Container

It’s now time to start the container using the image we just pulled from the container registry. I chose to add two parameters for my set up:

-d for Detached. This parameter will run the container in “detached” or background mode. This permits us to run the database container without having a console screen devoted to the session.

–name is the name we will assign to the container for future use.

-p for port-mapping. If we want to access the database in the container with an external client such as SQLDeveloper we will have provide port mapping for the default Oracle listener (port 1521). This parameter maps port 1521 inside the container to our host port 1521.

Note that we could also have provided a parameter for volume-mapping which would permit me to map an external mount point to my container, which isn’t a bad idea if I wanted to persist data between images or control the location on my host. However in my case persisting the data in the container works just fine. …and yes my data is persisted between system restarts.

There are additional customizations that are available such as choosing standard edition vs enterprise edition, changing the database character-set, or setting the default password for sys/system, etc.

To keep things simple, in my setup, I opted to go with the out-of-the-box settings and they seem to be fine for me.

The first time you start the database it will go through a deployment process which means it will take some extra time to start. But these steps are one-time initialization processes and will be skipped in future.

At this stage you can do two things to monitor the progress, you can run a docker ps command to see the state of the run:

or even better, you can view the log file of the creation process to get additional insight into what is actually being run inside the container.

Take note a randomly generated password for sys, system and pdbadmin is at the top of the log file so you should get a copy of this.

The log file will indicate that the database is ready once the initialization process has completed:

We can also run our docker ps command again, and this time we will see that the container is “Up” and “healthy”. You will also notice that we can see that port 1521 is running as well.

Step 5: Connecting to the Container

We are now ready to access the Oracle Database 19c Container. But before we start using it in earnest we should change the sys/system/pdbadmin password.

Because I am running the database container in detached-mode I need to use a docker exec command to run the commands inside the container. I am also using the -it parameters so the operation is an interactive operation.

This can be done as follows:

In my case I changed the password to “My19cPassword”

Now that the password has been set we are ready to access the container. In this case we will use the same docker exec command but to run an interactive sqlplus session.

You will notice that the container includes a Pluggable Database: ORCLPDB1. We could connect to the pluggable database using an alter session set container operation but it would be nicer to access the pluggable database directly using the service handle.

So before we start, we can play it safe and confirm that the service to connect to the PDB is running, so you can check this by running a lsnrctl status command as follows:

Now that we have confirmed the listener service is created and running for our pluggable database you can go ahead and connect to it directly as follows:

Step 6: Connecting to the Container with SQLDeveloper

So this is good news. We can access the pluggable database inside the container quite easily. However, it would be really nice if we could skip the docker exec command and just access the pluggable database inside the container directly with a tool like SQLDeveloper.

Well don’t despair, that is very simple to do. But in order to access the container you will need the ip address for the container. This can be gotten by viewing the container configuration using the inspect command. The inspect command returns it’s values in a json-formatted, but a simple grep command can simplify this task as follows.

Once you have determined the service-name for the pluggable database and the ip-address for the container you are ready to create a new connection in SQLDeveloper:

sqldeveloper connection

After setting up the database connection, let’s connect to the database to see that it works…

oracle sqldeveloper

So now it’s time to really start playing!


10-NOV-2020

Okay an update… this is following up on a question asked by Michael Paege (https://mpaege.wordpress.com/) about the Oracle licensing requirements for running in a Container, here’s a link to an Oracle document- https://www.oracle.com/a/tech/docs/running-and-licensing-programs-in-containers-and-kubernetes.pdf