Set up Oracle XE with Docker container and connect with DBeaver

Tags: oraclesql

Today we will learn how to set up Oracle database server with Docker Linux container. This example can be applied to both Windows, Mac and Linux machine.

We will start with buiding Oracle database server image and then luanch a new container that has a running Oracle server inside. Finally we will connect the database server with GUI tool DBeaver.

Let's get started.

Build Oracle Docker image

For Windows users, you can use Linux subsystem or Git Bash command line tool. In this example, I will use Git Bash and you can install it by following command.

$ choco install git

You need to have choco installed to use the choco install command

Next lanch Git Bash shell and clone Oracle Docker project.

$ git clone [email protected]:oracle/docker-images.git 

Form the current working directory, CD to docker-images/OracleDatabase/SingleInstance

$ cd docker-images/OracleDatabase/SingleInstance/dockerfiles

Use ls command and you fill find list of folder and buildDockerImage.sh script.

$ ls 
11.2.0.2/  12.1.0.2/  12.2.0.1/  18.3.0/  18.4.0/  19.3.0/  buildDockerImage.sh*

Then copy Oracle XE setup file to the folder matched with the version you downloaded. In this example, copy the setup file to 11.2.0.2 folder.

Download oracle-xe-11.2.0-1.0.x86_64.rpm.zip

Build the image with buildDockerImage.sh script. For Unix users, you may need prefix sudu command or allow exection permission to buildDockerImage.sh script.

$ ./buildDockerImage.sh -v 11.2.0.2 -x

parameters:

  • -v is Oracle database version to build
  • -x to create an image based on 'Express Edition'

Wait for several minutes unit it's done and you will get the following messages:

 Oracle Database Docker Image for 'xe' version 11.2.0.2 is ready to be extended:

    --> oracle/database:11.2.0.2-xe

  Build completed in 84 seconds.

If you run docker image ls, you will find a new image oracle/database with tag 11.2.0.2-xe

Lanch Docker Oracle database server container

Use docker run command to lanch a new container with oracle/database:11.2.0.2-xe image.

$ docker run --name OracleXE \
--shm-size=1g \
-p 1521:1521 \
-p 8081:8080 \
-e ORACLE_PWD=12345 \
-v oracle-data:/u01/app/oracle/oradata \
oracle/database:11.2.0.2-xe

Learn more about parameters

Note: The ORACLE_SID for Express Edition is always XE and cannot be changed, hence there is no ORACLE_SID parameter provided for the XE build. Wait for serveral minutes unitil it's done and you will get the following message.

#########################
DATABASE IS READY TO USE!
#########################

Righnt now, Oracle database server is ready to use.

Connect with DBeaver

When we launch the container with docker run, we specifed host's port to1521 and password to 12345. We will use these information to connect to a server with DBeaver.

Download DBeaver

!!! To use DBeaver, you need to have Java (JDK) 8+ or AdoptOpenJDK 11 installed on your computer.

Launch DBeaver

Create a new Oracle connection and fill the following information.

  • Host: localhost
  • Port: 1521
  • Database: XE
  • Use SID
  • User name: SYS
  • Role: SYSDBA
  • Password: 12345

You may need to edit a driver. For editing the driver you can follow the steps in the following image and download the driver from Oracle Database 11g Release 2 (11.2.0.4) JDBC Drivers

Enter image description here

Save the connection and connect to the dataase server. You can now query data from Oracle database server as the following

Enter image description here