Tuesday, December 27, 2016

Oracle 12c setup using Docker on Ubuntu

Recently had to install Oracle 12c on an ubuntu 16.04 server  , the quickest way I found to do that was through docker .

Pre-requisites

First things first we need to setup docker and this is done by following the docker docs :
 https://docs.docker.com/engine/installation/linux/ubuntulinux/


Installing Oracle Image 

Now that you have a working docker install you need to :

  1. Download the image for Oracle 12c 
  2. Open port 8080 and 1541 such as you get access to the web Application express interface and are able to connect to the Oracle instance via SQLPlus respectively
  3. Map a source directory on your docker host with a directory within the Docker Oracle container should you want to import dumps for example
All the above can be achieved within the command below :
docker run -d -P --name atlas_oracle12 -p 8080:8080 -p 1521:1521  -v /home/ubuntu/atlaslocaldump:/u01/app/oracle/admin/xe/dpdump/ sath89/oracle-12c  

Things to note are that :
  1. atlas_oracle12 - this is the name I have given to my container , it can be any valid name e.g foo 
  2. /home/ubuntu/atlaslocaldump - this directory on my docker host which i want to make visible within the oracle docker container ( so basically the source )
  3. /u01/app/oracle/admin/xe/dpdump/ - this is the directory on the docker container from which i will be able to access the files within /home/ubuntu/atlaslocaldump 
  4. sath89/oracle-12c - this is the name of the image for the Oracle-12c install , you can get more information around this here on docker hub  .
  5. Also it takes around 10-15 mins depending on your machine to initialise the Oracle instance so you might not just be able connect straight to SQLPlus .. give it some time to initialise
SQLPlus

So once the DB is up and running you might want to access the Oracle instance via SQLPlus , to do that you can either install SQLPlus on your docker host and connect or you go within your Oracle container and access the bash , I have done the later as installation of SQLPlus client on Ubuntu was a completely nightmare .

So connect to the oracle container using the following command :
docker exec -it atlas_oracle12 bash 

 Note that atlas_oracle12  is the name of the container that you defined in the docker run command above if this is not the name of the container then change it to reflect your own container name.

Now that we are within the container SQLPlus can be called using :
$ORACLE_HOME/bin/sqlplus system/oracle@//localhost:1521/xe.oracle.docker

Importing a Dump

You can also import a dump using the following command :

$ORACLE_HOME/bin/impdp USERNAME/PASSWORD@//localhost:1521/xe.oracle.docker dumpfile=myDumpFile.dmp  logfile=myLogFile.log table_exists_action=replace schemas=mySchema 
Do change the values above to correspond to your specific settings

Removing the  Oracle Container

For some reasons you might want to remove the oracle container in our case it is named atlas_oracle12 ( change this below to the name you gave your container instance )

To do that you need to stop the contained using command :

docker stop atlas_oracle12

Then remove the container directly using :

docker rm atlas_oracle12

You can check that the container is removed by doing a :

docker ps



No comments: