Running Oracle XE on Docker

Oracle XE is a free Oracle database that you can run locally and is very handy for development purposes.

This post shows how to create a docker image with an instance of Oracle XE for you to manage and use in Linux (Ubuntu, RedHat, etc.), Mac, Windows, and other Operating Systems.

Download Oracle XE

Go to Oracle XE Download Page.

Download the version for Linux with .rpm extension.

Docker Image from Oracle Official Dockerfiles

Clone the official Oracle repo from GitHub containing the Dockerfiles.

git clone https://github.com/oracle/docker-images.git

Copy the Oracle XE to the right folder, here I’m assuming version 18.4.0 and that you cloned the repo to the home folder.

cp ~/Downloads/oracle-database-xe-18c-1.0-1.x86_64.rpm ~/docker-images/OracleDatabase/SingleInstance/dockerfiles/18.4.0

Enter the folder with the script to build the image:

cd ~/docker-images/OracleDatabase/SingleInstance/dockerfiles

Finally, build the image using parameters -x because we are installing Oracle XE and -v 18.4.0 because that’s the version being used.

./buildDockerImage.sh -x -v 18.4.0

Persistent volumes

As it is, everytime the container is destroyed the data is lost.

So let’s create a volume to persist our data on the host machine.

mkdir ~/docker-volumes/oracle-xe

Give permissions on host for the user oracle in group dba to write in your folder from inside the container.

chmod 775 ~/docker-volumes/oracle-xe
sudo chown 54321:54322 ~/docker-volumes/oracle-xe

In the container, the user oracle has id 54321 and group dba has id 54322, confirm that’s the same for you just in case.

Running the container

To run the container, use the following docker run:

docker run -d \
-p 91521:1521 \
-p 95500:5500 \
-e ORACLE_PWD=password123 \
--name=oracle-xe \
--volume ~/docker-volumes/oracle-xe:/opt/oracle/oradata \
oracle/database:18.4.0-xe

Now we have a container named oracle-xe based on our image oracle/database:18.4.0-xe.

A volume mapping /opt/oracle/oradata to ~/docker-volumes/oracle-xe.

SYS and SYSDBA default password is password123.

Port from the container 1521 is mapped to 91521, and 5500 is mapped to 95500.

Troubleshooting

After running for the first time, check the logs in the container to see if there is something like a Permission Denied error with:

docker logs oracle-xe

If so, try starting a session in the container:

docker exec -it oracle-xe bash -c "source /home/oracle/.bashrc; bash"

Check the permissions for /opt/oracle/data:

ls -ld /opt/oracle/oradata

If the output shows root:root as owner, change it to oracle:dba:

chown oracle:dba /opt/oracle/oradata

Restart your container.

Quick commands

For logs:

docker logs oracle-xe

Start a session in the container:

docker exec -it oracle-xe bash -c "source /home/oracle/.bashrc; bash"

Stop the container:

docker stop -t 200 oracle-xe

Start the cotainer:

docker start oracle-xe

Connecting to Oracle SQL Developer

To connect Oracle SQL Developer or any other client running on our host to the Oracle XE instance running in the container use the following.

Host: localhost
Port: 91521
User: SYS
Password: password123
SID: xe