Run Oracle Database in Docker using prebaked image from Oracle Container Registry–a two minute guide image 17

Run Oracle Database in Docker using prebaked image from Oracle Container Registry–a two minute guide

imageThis article will show how to run an Oracle Database on a Docker host using the prebaked images on Oracle Continer Registry. It is my expectation that it takes me very little manual effort to run the full 12.2.0.1 Oracle Enterprise Database – just pull and run the Docker image. Once it is running, I get the usual Docker benefits such as clean environment management, linking from other containers, quick stop and start, running scripts inside the container etc.

The minimum requirements for the container is 8GB of disk space and 2GB of memory. There is a slim alternative that requires less resources: The slim (12.2.0.1-slim) version of EE does not have support for Analytics, Oracle R, Oracle Label Security, Oracle Text, Oracle Application Express and Oracle DataVault. I am not sure yet how much that shaves of the resource requirements.

My recent article Quick introduction to Oracle Container Registry–running one of Oracle’s prebaked images explained the first steps for getting started with Oracle Container Registry, including how to sign up and accept terms and conditions for individual images.

Once that is out of the way, we can get going with running the database.

The steps are:

  1. start docker
  2. login to Oracle Container Registry
  3. pull image for Oracle Database – I will use the enterprise edition database image in this article
  4. run a docker container based on that image
  5. start interacting with the database, for example from SQLcl or SQL Developer.

In terms of work, it will take less than two minutes of your time. The time before the database is running is mainly determined by the time it takes to download the image. After that, running the container takes just a few dozens of seconds.

The Oracle Database images are published on the website for the Container Registry:

image

image

image

Copy the docker pull command in the upper right hand corner to the clipboard. It is also worth remembering the docker run command for running the database image.

Note that this webpage contains more useful information:

  • how to run SQL scripts from within the container
  • how to expose the database [port] outside the container
  • how to specify SID (default ORCLCDB), PDB (default is ORCLPDB1), DOMAIN (default is localdomain) and allocated MEMORY (default is 2 GB)
  • how to change SYS password (default is Oradoc_db1)
  • how to make use of a volume external to the database container for storing data files, redo logs, audit logs, alert logs and trace files
  • how to run a database server image against an existing set of database files

Let’s run a database

After starting Docker (on my laptop I am using the Docker Quick Start Terminal in the Docker Toolbox), login to the container registry using your Oracle account.

image

SNAGHTMLea0ec12

Then pull the database image, using the command

docker pull container-registry.oracle.com/database/enterprise

image

07:09 Start Pull

10:28 Start Extracting

image

10.30 Image is available, ready run containers off

image

The download took over three and a half hours. I was doing stuff over that time – so no time lost.

Once the pull was finished, the image was added to the local cache of Docker images. I can now run the database.

docker run -d -it –-name ORA12201_1 –P container-registry.oracle.com/database/enterprise:12.2.0.1

The value ORA12201_1 is the self-picked name for the container.

image

Here -P indicates that the ports can be chosen by docker. The mapped port can be discovered by executing

docker port ORA12201_1

image

In a few minutes – I am not sure exactly how long it took – the container status is healthy:

image

The Database server can be connected to – when the container status is Healthy – by executing sqlplus from within the container as

docker exec -it ORA12201_1 bash -c “source /home/oracle/.bashrc; sqlplus /nolog”

image

imageIn addition to connecting to the database from within the container – we can also just consider the container running the database as a back  box that exposes the database’s internal port 1521 at port 32769. And using any tool capable of communicating to a database can be used in a regular way – provided we also have the IP address for the Docker Host if the connect is not made from that machine itself:

image 

Creating a database connection in SQL Developer is done like this:

SNAGHTMLf64a329

Using SYS/Oradoc_db1 as the credentials, the Docker Host IP address for the hostname and the port mapped by Docker to port 1521 in the container, 32769 in this case. The Service Name is composed of the PDB name and the domain name:  ORCLPDB1.localdomain.

A sample query:imageConnecting with SQLcl is similar:

sql sys/Oradoc_db1@192.168.99.100:32769/ORCLPDB1.localdomain as sysdba

image

To stop the container – and the database:

docker stop 62eb

It takes a few seconds to stop cleanly.

image

Restarting takes about 1 minute before the database is up and running:

image

image

Note: with this basic approach, all database files are created in the container’s file system. And are not available elsewhere nor will they survive the removal of the container. A better way of handling these files is through the mounting of a host folder for storing files or through a Docker Volume.

Note: when running on Windows using Docker Toolbox, this may be convenient for increasing the size of memory and disk of the default VM: https://github.com/crops/docker-win-mac-docs/wiki/Windows-Instructions-(Docker-Toolbox)

11 Comments

  1. RJ August 22, 2019
    • Lucas Jellema August 23, 2019
  2. Juan Perez May 12, 2019
    • Franco Pan August 28, 2019
  3. Juan Perez May 12, 2019
  4. Chris Farmer February 1, 2019
    • Juan Perez May 12, 2019
  5. Jeffery October 18, 2018
  6. Ronald Kevin Burton September 18, 2018
  7. Ronald Kevin Burton September 18, 2018
    • Lucas Jellema September 18, 2018