In this article, I will show how to run Oracle Database Express Edition using Docker.
Requirements
git
Docker
Oracle binaries (optional)
Why a post dedicated to Oracle?
On DockerHub you can find images for most of the common databases such as PostgreSQL or MariaDB. But when it comes to Oracle, all the good things come to an end.
Due to (I think) copyright reasons, Oracle doesn't provide images that can be pulled and run on a Docker instance.
But strangly, they provided an alternative solution.
Running Oracle Database in Docker
Oracle made available a suite of Docker build scripts that help set up many of its product offerings, including Oracle Database. You can find these scripts in a GitHub repository.
We'll deploy the version 18.4.0-xe because it is the only version that doesn't requires pre-downloaded binaries. For any other version, you'll need to download the required binaries as described below.
Note: All the step marked as (Optional) can be skipped for the version 18.4.0-xe, but are required for any other version.
(Optional) Download Oracle binaries
Go to Oracle Download page. and download the db version you require, for example oracle-database-xe-18c-1.0-1.x86_64.rpm
Clone Oracle Github project
$ git clone https://github.com/oracle/docker-images.git
(Optional) Copy the database binaries into the project folder
$ cp /path/to/file/oracle-database-xe-18c-1.0-1.x86_64.rpm /path/to/project/docker-images/OracleDatabase/SingleInstance/dockerfiles/18.4.0
Execute the installer. For the options description, see the command helper
$ cd docker-images/OracleDatabase/SingleInstance/dockerfiles
$ ./buildContainerImage.sh -v 18.4.0 -x
WARNING: the script can take up to 30 minutes before finishing
Check the image
List the docker images:
$ docker images
and check that there's an image tagged as oracle/database 18.4.0-xe
Pay attention to the size of the image: sometimes the installation does not complete completely but the script ends without reporting any problems. The image should be approximately 5.89GB in size
Run the container
$ docker run --name oracle \
-d \
-p 51521:1521 \
-p 55500:5500 \
-e ORACLE_PWD=mysecurepassword \
-e ORACLE_CHARACTERSET=AL32UTF8 \
oracle/database:18.4.0-xe
Where
-
--name
: specifies the container name -
-d
: launch the container in detached mode -
-p 51521:1521
and-p 55500:5500
map a host to a container port. -
-e ORACLE_PWD=mysecurepassword
and-e ORACLE_CHARACTERSET=AL32UTF8
set the environment variables. Here,ORACLE_PWD
sets the administrative password, andORACLE_CHARACTERSET
sets the database’s character set.
You can check the container status via the docker run
command, looking the STATUS
field:
$ d ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f7776a6dd664 oracle/database:18.4.0-xe "/bin/sh -c 'exec $O…" About a minute ago Up About a minute (health: starting) 0.0.0.0:51521->1521/tcp, :::51521->1521/tcp, 0.0.0.0:55500->5500/tcp, :::55500->5500/tcp oracle
In the example, the container is still starting (health: starting
). Once the container is started, the status will change in healty
.
Another way to check the container status is looking the container logs:
$ docker logs oracle
## Omitted for brevity
*******************
Prepare for db operation
7% complete
Copying database files
29% complete
Creating and starting Oracle instance
30% complete
31% complete
34% complete
38% complete
41% complete
43% complete
Completing Database Creation
47% complete
50% complete
Creating Pluggable Databases
54% complete
71% complete
Executing Post Configuration Actions
93% complete
Running Custom Scripts
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/XE.
Database Information:
Global Database Name:XE
System Identifier(SID):XE
Look at the log file "/opt/oracle/cfgtoollogs/dbca/XE/XE.log" for further details.
Connect to Oracle Database using one of the connect strings:
Pluggable database: 2540b6bf28f7/XEPDB1
Multitenant container database: 2540b6bf28f7
Use https://localhost:5500/em to access Oracle Enterprise Manager for Oracle Database XE
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
Since every time you launch the container the database instance needs to be installed, the container takes several minutes before it is ready.
Connecting to the database
You can connect the database using any client you want. In the example I've used dbeaver:
Alternatively, create a bash session within the container, using the OS user oracle
:
$ docker exec -it --user=oracle oracle bash
Set up the required Linux environment variables for Oracle Database:
bash-4.2# . oraenv
ORACLE_SID = [XE] ?
The Oracle base remains unchanged with value /opt/oracle
Then access SQL*Plus as you would on any Oracle Database system:
bash-4.2# sqlplus sys@XEPDB1 as sysdba
SQL*Plus: Release 18.0.0.0.0 - Production on Mon Aug 23 19:49:33 2021
Version 18.4.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0
SQL>
Coming next
Currently the database is working, but running the container requires a lot of time. In next posts I'll show how to improve starting time using different methods.
Sources
https://github.com/oracle/docker-images
https://blogs.oracle.com/oraclemagazine/deliver-oracle-database-18c-express-edition-in-containers
Top comments (0)