Wednesday, June 29, 2016

Installing Oracle Express 11g using Docker on Ubuntu

Installation of Oracle database on a Linux system for learning purposes is a huge hassel since there are so many steps to follow to get Oracle database is up and running. Furthermore, since I'm running on Ubuntu Linux which is a Debian based system, things are much more complicated than working on a RPM based system. Due to these reasons, I was strugging to get Oracle databse up and running on my system for a while. Finally I found a nice way to use it. Without going through the overhead of installing it, I found a docker image which I can to directly run on my Ubuntu Linux platform. Following are the steps I followed to get it done on my Ubuntu 16.04 LTS system.

Preparing the system for Docker

These steps are needed if you didn't have docker configured in your system like me initially. I found these steps from here [1].

(1) Run following commands on the terminal.

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D


(2) Open the following file and remove any existing contents from it. In my case, I didn't have such a file anyway.

sudo vim /etc/apt/sources.list.d/docker.list

Add the following line to that file.

deb https://apt.dockerproject.org/repo ubuntu-xenial main

(3) Then run following commands.

sudo apt-get update
sudo apt-get purge lxc-docker
apt-cache policy docker-engine
sudo apt-get update
sudo apt-get install linux-image-extra-$(uname -r)


(4) Now let's install docker and start it. The last command is just to check whether docker works fine.

sudo apt-get update
sudo apt-get install docker-engine
sudo service docker start
sudo docker run hello-world


Setting up Oracle XE 11g in Docker

Now we are ready to get our oracle database running on docker. I found these instructions mainly from this [2] article.

(1) Let's pull the docker image from repository to our machine.

sudo docker pull alexeiled/docker-oracle-xe-11g

(2) We can start it with the following command.

sudo docker run -d -p 49160:22 -p 49161:1521 -p 49162:8080 alexeiled/docker-oracle-xe-11g

(3) We can see the status of the running docker container using the following commands.

# to see the running docker processes
sudo docker ps

# to see the things running inside a particular docker image, we can use the following command. The value we passed to the '-f' parameter is the contained ID which we can findout using the above command.

sudo docker logs -f 6ab14881419c

(4) We can get a bash terminal for our docker running Oracle XE using the following command. There also we have used the container ID as a parameter.

sudo docker exec -it 6ab14881419c /bin/bash

Preparing sqlplus tool for using Oracle XE 11g

Now that we have started running oracle xe as a docker image and got a root shell for this docker container, we can start interacting with the database server using the 'sqlplus' client program. Let's do some preliminary things to enable the sample database schema called HR and a user account to use it called HR account.

(1) Login to the database using 'sqlplus' tool with username 'system' and password 'oracle'.

# take the root shell of docker image
sudo docker exec -it 6ab14881419c /bin/bash

# start sqlplus tool
sqlplus

(2) Run the following query on the SQL prompt.

ALTER USER HR ACCOUNT UNLOCK IDENTIFIED BY password;

(3) We should see the output as 'User altered.' Now, 'exit' from the 'sqlplus' and then login again but this time with the unlocked user account where the username is 'system' and password is 'password'.

(4) Now in the SQL prompt, type the following query and see whether we get a proper output. If so, we have unlocked our HR account and the HR schema is now available to us.

select count(*) from employees;

Now we are good to go with learning Oracle database.

References:

[1] https://docs.docker.com/engine/installation/linux/ubuntulinux/

[2] http://tuhrig.de/3-ways-of-installing-oracle-xe-11g-on-ubuntu/

No comments:

Post a Comment