Docker provides an efficient way to create and manage database environments. By leveraging containerization, DBAs can easily spin up isolated database instances with consistent configurations, simplifying tasks such as development, testing, and even production deployments. This eliminates the complexities of manual setups and ensures consistent environments across different teams and platforms, significantly improving productivity and reducing operational overhead.
In this post, We will see how to use Docker to build up and run a Oracle Database 23ai Free in less than five minutes.
Container creation.
docker run
is the core command in Docker used to create and start a new container. If the specified image doesn’t exist locally on your machine, docker run
first attempts to pull the image from the designated repository (like Docker Hub or a private registry). The image contains all the necessary files, libraries, and configurations for the software you want to run (in this case, an Oracle database). Once the image is pulled, docker run
creates a new container based on that image. This container is essentially an instance of the software defined within the image. Finally, docker run
starts the container and executes the command specified within the image or provided as an argument to the docker run
command.
# docker run -d \ --name ora23ai \ -p 1521:1521 \ -p 5500:5500 \ -e ORACLE_PWD=DB-Master \ -e ORACLE_CHARACTERSET=AL32UTF8 \ -v ${PWD}/oracle/oradata:/u01/app/oracle/product/23.0.0/dbhome_1/data \ container-registry.oracle.com/database/free:latest
Here’s a breakdown of the options used:
-d
: This tells Docker to run the container in detached mode, meaning the container will start in the background and won’t block the terminal.--name ora23ai
: This assigns a name to the container, making it easier to identify and manage.-p 1521:1521
: This maps the port 1521 inside the container to port 1521 on the host machine. This is important because 1521 is the default port used by Oracle databases to listen for connections.-p 5500:5500
: This maps the port 5500 inside the container to port 5500 on the host machine. This port is used by Oracle EM. However, it’s important to note that Enterprise Manager Express was deprecated from version 23ai.-v ${PWD}/oracle/oradata:/u01/app/oracle/product/23.0.0/dbhome_1/data
: This mounts a volume from the host machine to the container at /u01/app/oracle/product/23.0.0/dbhome_1/data
. This is important for persisting the database data, meaning the data will not be lost when the container is stopped or restarted.
Additionally, -e ORACLE_SID=PDB1
can be used to set up an identifier for an Oracle database instance.
# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 26d8178437ec container-registry.oracle.com/database/free:latest "/bin/bash -c $ORACL…" 18 minutes ago Up 18 minutes (healthy) 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp, 0.0.0.0:5500->5500/tcp, :::5500->5500/tcp ora23ai
This is the result of running the docker ps
command which shows information about running Docker containers.
- CONTAINER ID: This is a unique identifier for the container.
- IMAGE: This shows the image name used to create the container. Here, it’s
container-registry.oracle.com/database/free:latest
which is the Oracle 23c Free database image. - COMMAND: This indicates the command used to run the container.
- CREATED: This shows how long ago the container was created.
- STATUS: This indicates the current state of the container.
- PORTS: This section shows the ports mapped between the container and the host machine. Here, two ports are mapped:
0.0.0.0:1521->1521/tcp
: This maps port 1521 on the host machine (any IP address can access it) to port 1521 inside the container.
: This maps port 5500 on all interfaces inside the container (including loopback) to port 5500.0.0.0.0:5500->5500/tcp
- NAMES: This shows the name assigned to the container. Here, it’s
ora23ai
.
Let’s check the content of the log:
# docker logs ora23ai Starting Oracle Net Listener. Oracle Net Listener started. Starting Oracle Database instance FREE. Oracle Database instance FREE started. The Oracle base remains unchanged with value /opt/oracle SQL*Plus: Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems on Tue Jan 7 10:46:40 2025 Version 23.5.0.24.07 Copyright (c) 1982, 2024, Oracle. All rights reserved. Connected to: Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free Version 23.5.0.24.07 SQL> User altered. SQL> User altered. SQL> Session altered. SQL> User altered. SQL> Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free Version 23.5.0.24.07 The Oracle base remains unchanged with value /opt/oracle ######################### DATABASE IS READY TO USE! ######################### The following output is now a tail of the alert.log: Dumping current patch information =========================================================== No patches have been applied =========================================================== 2025-01-07T10:46:39.709614+00:00 FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN Completed: Pluggable database FREEPDB1 opened read write Completed: ALTER DATABASE OPEN
Finally, let’s open a SSH terminal and test the database connection with sqlplus.
# docker exec -it ora23ai /bin/bash bash-4.4$ sqlplus / as sysdba SQL*Plus: Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems on Tue Jan 7 10:53:35 2025 Version 23.5.0.24.07 Copyright (c) 1982, 2024, Oracle. All rights reserved. Connected to: Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free Version 23.5.0.24.07 SQL> select DBID, NAME, CREATED, LOG_MODE from v$database; DBID NAME CREATED LOG_MODE ---------- --------- --------- ------------ 1448739566 FREE 11-AUG-24 ARCHIVELOG
Connecting from SQL Developer.
To access the database running within the Docker container, you essentially connect to the host machine itself. The Docker container has mapped its internal port (1521 by default) to a port on the host machine. This allows you to connect to the database as if it were running directly on the host.
Stopping, restarting and removing the container.
Stopping, starting and removing a Docker container is straightforward. You can use the docker start
, docker stop
and docker rm
commands to gracefully shut down the container and then remove it from your system.
# docker stop ora23ai # docker start ora23ai # docker stop ora23ai # docker rm ora23ai
To wrap up.
Docker is a piece of cake for DBAs. Create and manage your Oracle databases quickly and easily! With Docker, you can spin up multiple databases in a snap, each in its own isolated sandbox. Say goodbye to the hassle of installing databases just for testing!.