How to run Oracle Database Container in Docker

Learn how you can run an oracle database docker image in your Docker instance. This tutorial will use the image provided by Oracle in the Oracle Container Registry website.

Here’s an overview of the steps that we will follow in this article:

  1. Selecting the Oracle Database image to use.
  2. Logging in to Oracle Container Registry from Docker.
  3. Running the Oracle Database Docker image.
  4. Testing the connection.

Oracle Docker Container Registry

In order to use the Oracle Database image in Docker, you must have an account in Oracle. If you don’t have an account yet, please create first at Oracle to create an Oracle account.

After you have created or verified that you have an Oracle account, go to the Oracle Container Registry site. Under Browse Containers, click Database. Under the database page, select the repository that you want to use. For this tutorial, we will use the enterprise repository. Scroll to the bottom and you should see the available docker images that you can use.

list of available oracle database docker images.
oracle database docker image

Select the version that you want to use and take note of the docker pull command.

Logging in to Oracle Container Registry from Docker

Next, we need to login to Oracle Container Registry from Docker. In your Docker instance, type the following command:

docker login container-registry.oracle.com

Type in your username (email) and password. You can verify that the auth configuration was saved by checking the ~/.docker/config.json file.

cat ~/.docker/config.json

Running the Oracle Database Image in Docker

Now that we have set up our Docker, we can now pull and run the Oracle Image.

First, let’s check again the docker pull command that we select in the Oracle Container Registry. We need to get the registry URL and tag name. For example, in this tutorial, we selected the following:

docker pull container-registry.oracle.com/database/enterprise:21.3.0.0

The URL plus tag name is container-registry.oracle.com/database/enterprise:21.3.0.0. Now we can use this in our run command.

To run, issue the following command:

docker run -d --name oracle-21c -e ORACLE_PWD=sysPassword -p 1521:1521 -p 5500:5500 container-registry.oracle.com/database/enterprise:21.3.0.0
  • -d – this means that the container will run in detached mode.
  • –name – the name of the container which we set as oracle-21c.
  • -e ORACLE_PWD – the password that will be set for SYS/SYSTEM and PDB sysdba role user. We set it as sysPassword but you can change this to whatever password you want.
  • -p – we expose the ports 1521 and 5500 so that our docker container is reachable outside the server.

You can check the logs using the following command to check the status of your installation:

docker logs -f oracle-21c

Testing the Connection

Once installation is completed, you can now test the connection in your SQL Developer.

Create a new connection in your SQL Developer and add the following details:

CDB SYSDBA Connection Details:

username: sys
password: password set in the docker run
role: SYSDBA
host: localhost or IP if in other machine
port: 1521
SID: ORCLCDB

By default, Oracle will create 1 PDB (ORCLPDB1) that you can use. Below are the default details that you can try to connect as SYSDBA of your PDB:

sys user:
username: sys
password: password set in the docker run
role: SYSDBA
host: localhost or IP if in other machine
port: 1521
service name: ORCLPDB1

And here’s a default user that you can use on your PDB which is actually just changing the role from SYSDBA to DEFAULT:

username: sys
password: password set in the docker run
role: default
host: localhost or IP if in other machine
port: 1521
service name: ORCLPDB1

Changing Oracle Password

You can change your password in case you forgot it. To change the password, you need to enter inside the container:

docker exec -it oracle-21c bash

You will be transferred to the home folder of the container where you can find the setPassword.sh. Run this script and follow on-screen instructions:

./setPassword newPassword

That’s it, you now have a working Oracle Database running in a Docker instance. Also, read how you can create a new Pluggable Database (PDB) in your Oracle Instance.

Share this tutorial!