Table of Contents
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:
- Register an account by going to https://profile.oracle.com/myprofile/account/create-account.jspx
- 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:
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:
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 184.108.40.206. 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:
Now, you can pull the image from oracle container registry:
docker pull container-registry.oracle.com/database/enterprise:220.127.116.11
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:18.104.22.168
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"
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
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
You can change such details to your liking.
Connect to Oracle database using sqldeveloper
Now we have created a user. We can use the credentials to connect to the database as follow:
Now, click on the Test button, and you should see the success text appears at the bottom left:
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.
I build softwares that solve problems. I also love writing/documenting things I learn/want to learn.