How to put Oracle XE inside Minishift (VirtualBox)

Allan Santos
8 min readJan 16, 2020

In this tutorial I’ll show how to put Oracle 18.4.0 XE inside minishift 1.34

Motivation

I was working with OpenShift using MiniShift as the image bellow shows.

Structure that I had

But I wanted the structure showed by the image bellow.

Structure that I wanted to have

Of course those images are not perfectly, but I think this is enough to picture the situation that I wanted to change.

That took me a lot of time and gave me a few white hairs but now I have all my applications and a oracle database working on my OpenShift inside my MiniShift machine. There are a several small things to put this running as desirable, so lets begin.

Task to be accomplished.

  1. Make oracle image
  2. Put the oracle image inside openshift docker registry.
  3. Configure shared storage in openshift for the oracle containers
  4. Connect in oracle from local machine, with SQL Manager Tool.

Make oracle image

In https://github.com/oracle/docker-images is possible to find instruction to create oracle images for a lot of oracle products, including a few version of oracle database, if you wanna, you can flow the information of that github, I did. But I created a repository in my own github that has all the necessary content to create a image of oracle 18.4.0-xe. Here https://github.com/acsdev/docker-images is possible clone or download the repository, after that, execute the commands bellow inside the folder oracle-18.4.0.

cat ./splited-rpm/splited.tar.gz* > ./oracle-database-xe-18.4.x86_64.tar.gztar -xvf ./oracle-database-xe-18.4.x86_64.tar.gzrm oracle-database-xe-18.4.x86_64.tar.gzdocker build -t oracle-18-4-0-xe:latest -f Dockerfile.xe .

That operation will take a while but after it finish, you will have in your local docker registry one oracle image called oracle-18-4-0-xe:latest. Execute the command “docker image ls” to see something like this.

REPOSITORY          TAG                 IMAGE ID            SIZE
oracle-18-4-0-xe latest 663f367a5d41 8.44GB
oraclelinux 7-slim 0d49b70bc432 118MB

If you want to test the image, just execute the instructions bellow, but keep in mind that will take some time, because the first container execution will create the database, set passwords, copy files and so on.

# To Run
docker run --name oracle-18-4-0-xe \
-p 8080:8080 \
-p 1521:1521 \
-p 5500:5500 \
-e ORACLE_BASE=/opt/oracle \
-e ORACLE_SID=XE \
-e ORACLE_PDB=oracle \
-e ORACLE_PWD=oracle \
--detach \
--privileged \
oracle-18-4-0-xe
#To See the log
docker logs --follow oracle-18-4-0-xe

NOW, is very problematic to pass a docker image from your local machine to Open Shift docker registry inside MiniShift machine. So, to accomplish that is easier to push your oracle image to docker hub and then pull it into Open Shift docker registry.

If you do not have a docker account, just create one! Or you can pull the docker from my docker account, I do not mind ;).

#To PUSH a image from your docker accountdocker tag oracle-18-4-0-xe:latest [YOUR_USER]/oracle-18-4-0-xe:latestdocker login -u [YOUR_USER] -p [YOUR_PASSWORD]docker push [YOUR_USER]/oracle-18-4-0-xe:latest

PUT the oracle image one your Open Shift docker

At this point, I will consider that the Minishift will be started for the first time.

Before to start Minishift execute the configurations bellow.

# To avoid problems with hard drive space
minishift config set disk-size 40GB
# To use virtual box as hypervisor
minishift config set vm-drive virtualbox
# To work always with the same IP address
minishift config set static-ip true
# Enable a route for docker registry
minishift addon enable registry-route

Now, start the Minishift with:

minishift start

Keep in mind, if you didn’t make static-ip and didn’t enable registry-route, it still possible make the things happen, but it will be a little more difficult, so I will assume that you did.

After Minishift has started, give a permission of admin cluster to developer user.

# To see how to be able to use Open Shift command line
minishift oc-env
# To use Open Shift command line
eval $(minishift oc-env)
# To login as admin
oc login -u system:admin
# To give the cluster admin role to developer user
oc adm policy --as system:admin add-cluster-role-to-user cluster-admin developer

Now, pull, tag and push the oracle image in Open Shift docker registry inside your Minishift machine.

# To see how to be able to use docker inside Minishift
minishift docker-env
# To execute docker instructions in your Open Shift docker registry
eval $(minishift docker-env)
# To login in Open Shift as a developer user
oc login -u developer -p 1
###
### Login successful.
# To login in Open Shift docker registry with developer credentials
docker login -u developer -p $(oc whoami -t) $(minishift openshift registry)
###
### WARNING! Using --password via the CLI is insecure. Use --password-stdin.
### WARNING! Your password will be stored unencrypted in ## <USER_FOLDER>/.docker/config.json.
### Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
### Login Succeeded
# To pull image from docker hub
docker pull <DOCKER_USER>/oracle-18-4-0-xe:latest
# To tag oracle image for the namespace "myproject" in Open Shift docker registry
docker tag <DOCKER_USER>/oracle-18-4-0-xe:latest $(minishift openshift registry)/myproject/oracle-18-4-0-xe:latest
# To push the image into Open Shift docker registry
docker push $(minishift openshift registry)/myproject/oracle-18-4-0-xe:latest

myproject is the default project (namespace) of developer user

After all that, an imageStream named as oracle-18.4.0-xe will be created in myproject namespace.

To check it, execute “oc get imageStream” or “oc get is”. A list of image streams that contains oracle-18.4.0-xe will be showed to you.

Finally, is possible to start docker container inside open shift.

# Relax the security at OpenShift level by granting all the authenticated users access to the anyuid SCC
oc adm policy add-scc-to-group anyuid system:authenticated
# Start an deployment with ORACLE_PWD environment variable
# This will be password for oracle system user
oc new-app --image-stream=oracle-18-4-0-xe -e ORACLE_PWD=oracle

After this point, a pod will be initiated as well the oracle installation process inside it. So, I hardly recommend to stop the pod initialization with the command bellow.

oc scale dc/oracle-18-4-0-xe --replicas=0

Why stop the pod initialization?

Imagine, the installation process takes a lot of time, download a lot of files but all this files will be property of the POD, if will need kill the pod and start a new one, the installation process will start from scratch.

To avoid that, you have to create storage shared between the oracle pods. Follow the next commands to accomplish that.

# This command will show a already existing volume for oracle inside the deployment configuration 
oc describe dc/oracle-18-4-0-xe | grep oradata
###
### /opt/oracle/oradata from oracle-18-4-0-xe-volume-1 (rw)

To avoid to losing data between oracle pods is necessary to share the volume folder with them using a Persistent Volume Claim.

# Create a Persistence Volume with 5G point for the directory already createdcat << PV | oc create -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: oracle-18-4-0-xe-pvc
namespace: myproject
spec:
accessModes:
- ReadWriteMany

resources:
requests:
storage: 5G
PV
# Get the VOLUME_NAME created for the Persistence Volume Claim
oc get pvc/oracle-18-4-0-xe-pvc | awk '{print $3}'
# Remove default volume from oracle deployment
oc set volume dc/oracle-18-4-0-xe --remove --name=oracle-18-4-0-xe-volume-1
# Bind the PersistentVolume to oracle
oc set volume dc/oracle-18-4-0-xe --add --name=VOLUME_NAME --type=persistentVolumeClaim --claim-name=oracle-18-4-0-xe-pvc --mount-path=/opt/oracle/oradata
# Get volume real path
oc describe pv/VOLUME_NAME | grep Path | awk '{print $2}';
# Give all permissions for the volume real path
minishift ssh "sudo chmod 777 VOLUME_REAL_PATH"

NOW, start one POD

# To init a POD
oc scale dc/oracle-18-4-0-xe --replicas=1
# To get PODs running
oc get pods
# To monitor process to create database
oc logs -f ORACLE_POD_NAME (sample: oracle-18-4-0-xe-7-c2gdw)

DB is ready to use?

Yes, at this point, database should be ready to use inside the open shift. BUT, there is no way to access it from local machine yet. For that, you will need expose oracle ports and create a tunnel for communication with a specific POD running oracle.

First, expose oracle ports. Only 1521 is really necessary.

oc expose svc/oracle-18–4–0-xe \
-name=oracle-18–4–0-xe-5500 -port=5500
oc expose svc/oracle-18–4–0-xe \
-name=oracle-18–4–0-xe-8080 -port=8080
oc expose svc/oracle-18–4–0-xe \
-name=oracle-18–4–0-xe-1521 -port=1521

Now, you need a tunnel (using port 1521) with the POD is running oracle.

# Get PODs
oc get pods
# Start tunnel
oc port-forward 11521:1521 POD_NAME
ORoc port-forward $(oc get pods | grep oracle-18-4-0-xe | awk '{print $1}') 11521:1521* I did choose the port 11521 in local machine to bind with 1521 for the POD running oracle

Keep in mind, to connect in oracle database from local machine it is necessary to do two things.

  1. Keep the tunnel open! The simplest way to do that is keeping a terminal window open with “oc port-forward” running.
  2. To connect from local machine, you will have to use locahost:<PORT> chosen in “oc port-forward”. So, in that case the address will be localhost:11521 as the picture bellow.

Now, it is finally over. You are able to connect at oracle that resides in Open Shift.

BONUS TIPS

1. Push oracle image to ODR WITHOUT registry-route ENABLED

# To login in openshift as a developer user
oc login -u developer -p 1
### Login successful.
# To get a token for developer user
oc whoami -t
### sample of tokem
### 4bjt17GDdaVjPf-rGTN8WB69FSozcCEe1tiGGQKUI-c
(SAVE THIS TOKEN)
# To open a ssh session with minishift
minishift ssh
# To login in Open Shift docker registry with developer credentials
docker login -u developer -p TOKEN 172.30.1.1:5000
# To pull image from docker hub
docker pull <DOCKER_USER>/oracle-18.4.0-xe:latest
# To tag oracle image for the namespace "myproject" in Open Shift docker registry
docker tag <DOCKER_USER>/oracle-18.4.0-xe:latest 172.30.1.1:5000/myproject/oracle-18.4.0-xe:latest
# To push the image into Open Shift docker registry
docker push 172.30.1.1:5000/myproject/oracle-18.4.0-xe:latest

--

--