Want to run an Oracle database for developing or experimenting for free with minimal setup effort? This article shows how you can get up & running an Oracle DB using Docker in a few minutes.
Searching around for running an Oracle DB on Docker you’ll likely be navigated to the Oracle Database on Docker site on GitHub. This provides comprehensive guides and Dockerfiles to built your own images… interesting, but unfortunately not a quick and simple solution to pull & run a database. So let’s explore a more easy way…
Table of Contents
Pulling the official Oracle DB container image
Oracle also provides pre-built Docker images in their own registry located at container-registry.oracle.com.
Navigating to the Database section, you can find images for various versions of the Oracle database like Enterprise, Express or Free. In this article we’ll use the Free version.
By choosing a repository you’ll get additional information on how to pull the image and what parameters are offered for customizing.
To use those Docker images, you’ll need an Oracle account to log on to the container registry. If you don’t have one, go ahead and create one for free.
Then log on to the Oracle container registry and pull the database image, e.g. the latest free edition.
$ docker login container-registry.oracle.com
$ docker pull container-registry.oracle.com/database/free:latest
$ docker image ls | grep oracle
container-registry.oracle.com/database/free latest 39cabc8e6db0 2 months ago 9.16GB
Having this, you are ready to start the database.
Starting the Oracle database with Docker
Before we start a new container running the database, its recommendable to create a local directory where all the data files can persist outside the container. By doing so, the data persistence is decoupled from the containers lifeycycle. In our example the local directory /opt/oracle/oradata
was created with write permissions for any user.
Now you can start up the Oracle DB like so:
$ docker run --name oracle \
-p 1521:1521 \
-e ORACLE_PWD=Test123 \
-v /opt/oracle/oradata:/opt/oracle/oradata \
container-registry.oracle.com/database/free:latest
This will start a container named oracle
binding it to port 1521 and setting the SYS password of the database to Test123
. The local directory /opt/oracle/oradata
will be mounted directly in the container ensuring that database files are persistent.
Note 1: If you encounter any permission problems with the data directory under Linux, any SELinux settings are likely the cause. To overcome this, a quick solution is to pass the :Z
option to the volume parameter: -v /opt/oracle/oradata:/opt/oracle/oradata:Z
For more details on that, just have a look on the article about moving MongoDB to Docker.
Note 2: On first startup when the mounted oradata
directory is empty, Oracle will create a completely new database in there which might take some minutes.
After the startup is completed, you should see DATABASE IS READY TO USE
in the output. Also this gives you the SID of the started DB which is FREE
in that case.
Awesome, now let’s connect and use the database…
Connecting to the database
After startup is completed you can connect to the database at localhost:1521
as SYS using the supplied password Test123
.
Using SQLDeveloper…
…or using sqlplus
…
$ sqlplus sys/Test123@localhost as sysdba
SQL*Plus: Release 21.0.0.0.0 - Production on Fri Nov 10 21:08:06 2023
Version 21.12.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
Connected to:
Oracle Database 23c Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.3.0.23.09
SQL>
…or any other DB tool you want.
That’s already it. Have fun playing around with Oracle DB 🙂