Vai al contenuto

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-21c-1.0-1.018.x86_64.rpm ~/docker-images/OracleDatabase/SingleInstance/dockerfiles/21.3.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 21.3.0 because that’s the version being used.

sudo ./buildContainerImage.sh -x -v 21.3.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 1521:1521 \
-p 15080:8080 \
-e ORACLE_PWD=password123 \
--name=oracle-xe \
--volume ~/docker_volumes/oracle-xe:/opt/oracle/oradata \
oracle/database:21.3.0-xe

or if you prefer to use docker-compose create the docker-compose.yml file inside the docker-image folder with the command:

nano docker-compose.yml

and put this information inside:

oracle-xe:
  image: oracle/database:21.3.0-xe
  ports:
    - "15080:8080"
    - "1521:1521"
  environment:
    - ORACLE_PWD=password123
  volumes:
    - /home/erbc/docker_volumes/oracle-xe:/opt/oracle/oradata

change the ORACLE_PWD with your own.
Close and save the file with CTRL+X and after press Y .
Now you can start the container with the following command:

docker-compose up -d

Now we have a container named oracle-xe based on our image oracle/database:21.3.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 1521 and 8080 is mapped to 15080.

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: 1521
User: SYS
Password: password123
SID: xe

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *