How To Install Oracle Database on Docker

Many people had difficulties installing Oracle database on docker. One of the reasons is the image is not available on Docker hub. There are some tutorials in the comment section but they don’t work anymore. In this post, I’m going to show you how to install Oracle database on docker (12c, 19c, 21c…).

Create an account on Oracle docker registry

As I mentioned at the beginning of this post, Oracle database images are not available on Docker hub anymore, even after you log in. Luckily, you can obtain the images from Oracle docker’s registry at https://container-registry.oracle.com.

To be able to pull images from this registry, you need to:

  1. Register an account by going to https://profile.oracle.com/myprofile/account/create-account.jspx
  2. After that, make sure you accept Oracle’s terms and conditions. Without this step, you will not be able to pull the images.

Get the name of the image you want to pull

Now you already have an account, log in to https://container-registry.oracle.com/ with your credentials and search for “database”

You should see a result page similar to this:

Install Oracle Database on Docker

Let’s click on enterprise (the line I underscore with the red line there). On the new page that appears, scroll to the bottom, you will see the list of images available for download:

List of oracle database images

As you can see, there are various database versions you can download. But, how can you download a specific image? Using docker pull, of course.

Pull the right version of Oracle database image

From the available images, you can choose the version you want to pull. FOr me, I will pull version 12.2.0.1. To do that, I need first log in to Oracle container registry from the command line:

docker login  container-registry.oracle.com

You will see prompts to input your username and password. If you enter the details correctly, you should see the login succeeded message:

login to oracle container registry

Now, you can pull the image from oracle container registry:

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

You should be able to pull the image without issue.

If you see an error message mentioning the image does not exist or you don’t have the right, you probably haven’t accepted Oracle’s terms and conditions. Make sure you complete this before pulling the image.

Running the container

To create an Oracle database container, run the following command:

docker run -dit -p 1521:1521 --name oracle_db container-registry.oracle.com/database/enterprise:12.2.0.1

It may take a few minutes for the container to complete boot. You may want to monitor the log by using this command:

docker logs -f oracle_db

If you choose a different name for your container, change oracle_db to your container’s name.

When you see this in the log, that means the container is ready to use:

Now you can exec into the container to do management tasks:

docker exec -it oracle_db bash -c "source /home/oracle/.bashrc; sqlplus /nolog"
exec into oracle database container

Now you are ready to execute commands.

Create a user in Oracle database

While you are in the container SQL command line, you can create a user so you can use that to connect to the database later from clients (such as sqldeveloper).

connect sys as sysdba;

There will be a prompt that asks for a password, enter Oradoc_db1

Now execute the following commands (one per line) to create an user.

alter session set "_ORACLE_SCRIPT"=true;
create user db_user identified by db_user_pass;
GRANT ALL PRIVILEGES TO db_user;

In the script above, I created a user called db_user with password db_user_pass

You can change such details to your liking.

create an user in oracle database 12c docker container

Connect to Oracle database using sqldeveloper

Now we have created a user. We can use the credentials to connect to the database as follow:

connect to oracle database 12c with sql developer

Now, click on the Test button, and you should see the success text appears at the bottom left:

Connect to oracle database 12c successfully from sqldeveloper
Connect to oracle database 12c successfully from sqldeveloper

Conclusion

As you can see, it may take some extra steps to install Oracle databases with docker since the images are not publicly available on Docker hub. You need to create an account with Oracle, and accept the terms and conditions. After that, you can create containers as usual.

Note that I used Oracle database 12c image in this example. However, in case you need other images (19c, 21c…) they are also available on Oracle image repository.


Leave a Reply

Your email address will not be published. Required fields are marked *