Bootstrap FreeKB - Oracle Database - Install Oracle Express Database on Docker
Oracle Database - Install Oracle Express Database on Docker

Updated:   |  Oracle Database articles

A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).

 

The docker pull command can be used to pull down the latest oracle express image. Be aware that the image is around 11.4 GB so you'll have to ensure you have enough space for the image.

sudo docker pull container-registry.oracle.com/database/express:latest

 

Or, create a file named Dockerfile so that the Dockerfile contains the following.

FROM container-registry.oracle.com/database/express:latest

 

Then use the docker build command to create the image, running this command in the same directory as the Dockerfile.

docker build --tag oracle-express-database .

 

The docker images command can be used to display the image.

~]$ sudo docker images
REPOSITORY                                       TAG       IMAGE ID       CREATED        SIZE
container-registry.oracle.com/database/express   latest    8da8cedb7fbf   2 months ago   11.4GB

 

The following command can then be used to create and start the ngninx container. Let's break down this command.

  • The docker run command is used to create and start the container.
  • The --detach flag is used to run the container in the background.
  • The --publish option is used both the Docker server and nginx container to listen on port 1521, which adds a rule to iptables to allow connections between the Docker system and container on port 1521.
  • The --env option is used to set your Oracle DB password
  • The --name option is used to give the container a specific name.
  • The container-registry.oracle.com/database/express image is used.
sudo docker run --detach --publish 1521:1521 --env ORACLE_PWD=itsasecret --name oracle-express-db container-registry.oracle.com/database/express

 

The docker container ls command can be used to ensure the container is running.

~]$ sudo docker container ls -a
CONTAINER ID   IMAGE                                            COMMAND                  CREATED         STATUS                   PORTS                                       NAMES
c668b7dfc2e0   container-registry.oracle.com/database/express   "/bin/bash -c $ORACL…"   2 minutes ago   Up 2 minutes (healthy)   0.0.0.0:1521->1521/tcp, :::1521->1521/tcp   oracle-express-db

 

The docker logs command should return something like this.

~]$ sudo docker logs oracle-express-db
Starting Oracle Net Listener.
Oracle Net Listener started.
Starting Oracle Database instance XE.
Oracle Database instance XE started.
The Oracle base remains unchanged with value /opt/oracle
SQL*Plus: Release 21.0.0.0.0 - Production on Thu Oct 19 09:12:32 2023
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle.  All rights reserved.
Connected to:
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
SQL>
User altered.
SQL>
User altered.
SQL>
Session altered.
SQL>
User altered.
SQL> Disconnected from Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
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:
No patches have been applied
===========================================================
2023-10-19T09:12:31.038060+00:00
Starting background process CJQ0
Completed: ALTER DATABASE OPEN
2023-10-19T09:12:31.162592+00:00
CJQ0 started with pid=64, OS id=412
2023-10-19T09:12:35.388476+00:00
TABLE AUDSYS.AUD$UNIFIED: ADDED INTERVAL PARTITION SYS_P328 (3398) VALUES LESS THAN (TIMESTAMP' 2023-10-20 00:00:00')
XEPDB1(3):TABLE AUDSYS.AUD$UNIFIED: ADDED INTERVAL PARTITION SYS_P360 (3398) VALUES LESS THAN (TIMESTAMP' 2023-10-20 00:00:00')

 

And the docker exec and sqlplus commands can be used to test a connection to the Oracle database.

~]$ sudo docker exec oracle-express-db sqlplus / as sysdba

SQL*Plus: Release 21.0.0.0.0 - Production on Thu Oct 19 09:17:24 2023
Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle.  All rights reserved.


Connected to:
Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0

SQL> Disconnected from Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0

 

Or you can run the docker exec command with the -it option to create an interactive shell in the container and then use sqlplus to get an interactive SQL prompt.

~]$ sudo docker exec oracle-express-db sh
sh-4.2$ sqlplus
Enter user-name: SYSTEM
Enter password: itsasecret
SQL>

 

For testing/debugging purposes, you should be able to connect and issue SQL queries using:

  • user = SYSTEM
  • password = the ORACLE_PWD password you set in the prior docker run command (e.g. itsasecret)
  • connection string = <ip address of your docker system>:1521/XE

 

Or, go with sqlplus SYSTEM/<password> to avoid being prompted for username and password.

~]$ sudo docker exec oracle-express-db sh
sh-4.2$ sqlplus SYSTEM/itsasecret
SQL>

 

For example, here is how I would connect using Python.

#!/usr/bin/python3
import oracledb

try:
  connection = oracledb.connect(user="SYSTEM", password="itsasecret", dsn="10.11.12.13:1521/XE")
except Exception as exception:
  print(f"got the following exception: {exception}")
else:
  print("Successfully connected to Oracle Database")

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 565aad in the box below so that we can be sure you are a human.