Friday, December 29, 2017

Getting started with Oracle Database in a Docker container!

One of the benefits of using Docker is quick and easy provisioning. I wanted to find out first-hand if this could help me get an Oracle Enterprise Edition database quickly up and running for use in a development environment. Oracle provides Docker images for its Standard and Enterprise Edition database in the Oracle Container Registry. Lucas Jellema has already provided two blogs on this (here and here) which have been a useful starting point. In this blog I'll describe some of the choices to make and challenges I encountered. To summarize, I'm quite happy with the Docker images in the registry as they provide a very easy way to automate the install of an EE database. You can find a Vagrant provisioning shell script with the installation of Docker and Docker commands to execute here and a description on how to use it here.

Docker

Installing Docker on Oracle Linux 7

Why Docker

Preparing for this blog was my first real Docker experience outside of workshops. The benefits of Docker I mainly appreciated during this exercise is that
  • Docker uses paravirtualization which is more lightweight than full virtualization on for example VirtualBox or VMWare.
  • The installation of a product inside the container is already fully scripted if you have a Docker image or Dockerfile. There are a lot of images and Dockerfiles available. Also provided and supported by software vendors such as Oracle.
  • The Docker CLI is very user friendly. For example, you can just throw away your container and create a new one or stop it and start it again at a later time. Starting a shell within a container is also easy. Compare this to for example VBoxManage.
In order to install Docker on Oracle Linux 7, you need to do some things which are described below.

Preparing a filesystem

Docker images/containers are created in /var/lib/docker by default. You do not need to specifically create a filesystem for that, however, Docker runs well on a filesystem of type BTRFS. This is however not supported on Oracle Linux. Docker has two editions. Docker CE and Docker EE. Docker CE is not 'certified' for Oracle Linux while EE is. For Docker CE, BTRFS is only recommended on Ubuntu or Debian and for Docker EE, BTRFS is only supported on SLES.

When you do want to use a BTRFS partition (at your own risk), and you want to automate the installation of your OS using Kickstart, you can do this like:

part btrfs.01 --size=1000 --grow
btrfs /var/lib/docker --label=docker btrfs.01

See a complete Kickstart example here for Oracle Linux 7 and the blog on how to use the Kickstart file with Packer here.


Enable repositories

Docker is not present in a repository which is enabled by default in Oracle Linux 7. You can automate enabling them by:

yum-config-manager --enable ol7_addons
yum-config-manager --enable ol7_optional_latest
yum-config-manager --enable ul7_uekr4

Install Docker

Installing Docker can be done with a single command:

yum install docker-engine btrfs-progs btrfs-progs-devel -y

If you're not using BTRFS, you can leave those packages out.

Start the Docker daemon

The Docker CLI talks to a daemon which needs to be running. Starting the daemon and making it start on boot can be done with:

systemctl start docker
systemctl enable docker

Allow a user to use Docker

You can add a user to the docker group in order to allow it to use docker. This is however a bad practice since the user can obtain root access to the system. The way to allow a non-root user to execute docker is described here. You allow the user to execute the docker command using sudo and create an alias for the docker command to instead perform sudo docker. You can also tune the docker commands to only allow access to specific containers.

Add to /etc/sudoers
oracle        ALL=(ALL)       NOPASSWD: /usr/bin/docker

Create the following alias
alias docker="sudo /usr/bin/docker"

Oracle database


Choosing an edition

Why not XE?

My purpose is to automate the complete install of SOA Suite from scratch. In a previous blog I described how to get started with Kickstart, Vagrant, Packer to get the OS ready. I ended in that blog post with the installation of the XE database. After the installation of the XE database, the Repository Creation Utility (RCU) needs to be run to create tablespaces, schemas, tables, etc for SOA Suite. Here I could not continue with my automated install since the RCU wants to create materialized views. The Advanced Replication option however is not part of the current version of the XE database. There was no automated way to let the installer skip over the error and continue as you would normally do with a manual install. I needed a non-XE edition of the database! The other editions of the database however were more complex to install and thus automate. For example, you need to install the database software, configure the listener, create a database, create scripts to start the database when the OS starts. Not being a DBA (or having any ambitions to become one), this was not something I wanted to invest much time in.

Enter Oracle Container Registry!

The Oracle Container Registry contains preconfigured images for Enterprise Edition and Standard Edition database. The Container Registry also contains useful information on how to use these images. The Standard Edition database uses a minimum of 4Gb of RAM. The Enterprise Edition database has a slim variant with less features but which only uses 2Gb of RAM. The slim image also is a lot smaller. Only about 2Gb to download instead of nearly 5Gb. The Standard Edition can be configured with a password from a configuration file while the Enterprise Edition has the default password 'Oradoc_db1'. The Docker images can use a mounted share for their datafiles.


Create an account and accept the license

In order to use the Container Registry, you have to create an account first. Next you have to login and accept the license for a specific image. This has been described here and is pretty easy.


After you have done that and you have installed Docker as described above, you can start using the image and create containers!

Start using the image and create a container

First you have to login to the container registry from your OS. This can be done using a command like:

docker login -u maarten.smeets@amis.nl -p XXX container-registry.oracle.com

XXX is not my real password and I also did not accidentally commit it to GitHub. You should use the account here which you have created for the Container Registry.

I created a small configuration file (db_env.dat) with some settings. These are all the configuration options which are currently possible from a separate configuration file. The file contains the below 4 lines:

DB_SID=ORCLCDB
DB_PDB=ORCLPDB1
DB_DOMAIN=localdomain
DB_MEMORY=2GB

Next you can pull the image and run a container with it:

docker run -d --env-file db_env.dat -p 1521:1521 -p 5500:5500 -it --name dockerDB container-registry.oracle.com/database/enterprise:12.2.0.1-slim

The -p options specify port mappings. I want port 1521 and port 5500 mapped to my host (VirtualBox, Oracle Linux 7) OS.

You can see if the container is up and running with:

docker ps

You can start a shell inside the container: 

docker exec -it dockerDB /bin/bash

I can easily stop the database with:

docker stop dockerDB

And start it again with

docker start dockerDB

If you want to connect to the database inside the container, you can do so by using a service of ORCLPDB1.localdomain user SYS password Oradoc_db1 hostname localhost (when running on the VirtualBox machine) port 1521. For the RCU, I created an Oracle Wallet file from the RCU configuration wizard and used that to automate the RCU and install the SOA Suite required artifacts  in the container database. See here.

Finally

I was surprised at how easy it was to use the Docker image from the registry. Getting Docker itself installed and ready was more work. After a container is created based on the image, managing it with the Docker CLI is also very easy. As a developer this makes me very happy and I recommend other developers to try it out! There are some challenges though if you want to use the images on larger scale.

Limited configuration possible

Many customers use different standards. The Docker image comes with a certain configuration and can be configured only in a (very) limited way by means of a configuration file (as shown above). You can mount an external directory to store data files.

Limitations in features

Also, the Docker container database can only run one instance, cannot be patched and does not support Dataguard. I can imagine that in production, not being able to patch the database might be an issue. You can however replace the entire image with a new version and hope the new version can still use the old datafiles. You have to check this though.

Running multiple containers on the same machine is inefficient

If you have multiple Oracle Database containers running at the same time on the same machine, you will not benefit from the multitenancy features since every container runs its own container and pluggable database. Also every container runs its own listener.

No comments:

Post a Comment