Monday, August 21, 2017

Running Oracle in a Docker Container - Part 3

OK, my apologies - I have 2 blog posts on this and nowhere does it get to the actual point of running Oracle in a Docker Container. I got caught up with real work and although I have done it and documented it, I haven't got around to posting here until now.

So, this is what you've been waiting for!

Using a container with an Oracle database

A search for 'oracle' shows quite a few entries, including a few that have databases already installed:

I downloaded the 11g one to test:



I started it up (ignore the different sessions)




but there were some issues – vi wasn’t installed so I couldn’t edit files, plus the listener.ora pointed to a hostname that changes every time the container is restarted. 

Install vi:





I tried to force the hostname by editing /etc/hostname and /etc/hosts but it didn’t work, but I noticed that every time the container restarted it added an entry – 172.17.0.2, so I put that in the listener.ora and it worked:





I then tried starting the database:




It started fine, but was pretty slow. The Mac Docker app can change how much memory can be allocated, so I stopped the container, changed it, and restarted it.


But before that, I committed the container so that the changes would be saved:


I also uploaded it to my repository:



The upload took a while and timed out a few times, I had to retry – but it knows where it got to so continued.

So there, at last, you have Oracle XE running in a Docker container!

Connecting to the database with SQLDeveloper

A connection with SQL Developer is easy – but you need to restart the container and map a port:


Start the listener and database:


Then start SQLDeveloper and use these connection details (I created an ‘andy’ user in the database):



Even though the IP address in the container is 172.17.0.2, you need to use 127.0.0.1 here.

You can then connect.


REMEMBER: Any database updates will be lost unless you commit the changes in the container.




















No comments:

Post a Comment