Anvil

Installing Oracle on Docker

This article describes how to install Oracle Database on a Docker container running on macOS (10.13).

It is possible to buy a container with Oracle installed from the Docker store, but I wanted to keep my database files outside the container to avoid losing them. This is the approach followed below.

Install Docker

The easiest way to install Docker is to download it from Docker. Using Homebrew is a bit more convoluted.

Once installed, start Docker. You will see a whale icon on the top menu bar. Clicking on it shows Docker is running.

Download Oracle software

Download Oracle Database 12c Release 2 for Linux x86-64 from Oracle. Whatever the download is called, rename it to linuxx64_12201_database.zip. You will need an Oracle licence to obtain this.

Download the Oracle Github Docker images.

Create a Docker image

Copy linuxx64_12201_database.zip to docker-images-master/OracleDatabase/dockerfiles/12.2.0.1 linuxx64_12201_database.zip in the location you chose earlier.

From docker-images-master/OracleDatabase/dockerfiles, run this from the Terminal:

./buildDockerImage.sh -v 12.2.0.1 -e

You should see "Complete" if it has succeeded. The parameters for this command are:

  1. -v version to build
  2. * select one edition only: -e, -s, or -x
    1. -e: creates image based on 'Enterprise Edition'
    2. -s: creates image based on 'Standard Edition 2'
    3. -x: creates image based on 'Express Edition'
  3. -i: ignores the MD5 checksums
  4. -o: passes on Docker build option

Once done, check using:

docker images

You should see something like:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
oracle/database     12.2.0.1-ee         9e697a9504a3        3 minutes ago       13.3GB

Create the Docker container

To create a database (actually a container database ORCLCDB and one pluggable database ORCLPDB1), execute the docker run command as shown below. This maps a host directory to the container data directory, meaning that the container can fail or be removed without losing the data files.

docker run --name oracle -p 1521:1521 -p 5500:5500 -v your_path:/opt/oracle/oradata oracle/database:12.2.0.1-ee

The full command parameters are:

  1. --name name of the container (default: auto generated)
  2. -p host to container port mapping. Two are exposed: 1521 (Oracle Listener), 5500 (OEM Express)
  3. -e
    1. ORACLE_SID: Oracle Database SID (default: ORCLCDB)
    2. ORACLE_PDB: Oracle Database PDB name (default: ORCLPDB1)
    3. ORACLE_PWD: SYS, SYSTEM and PDB_ADMIN password (default: auto generated)
    4. ORACLE_CHARACTERSET: character set to use when creating the database (default: AL32UTF8)
  4. --v your_path /opt/oracle/oradata: host to container data volume mapping

Configure Oracle

Check the container status. You should see some output listing how long it has been up.

docker ps -a
CONTAINER ID    NAMES   IMAGE          				COMMAND   CREATED	STATUS    PORT                                                                                             
569cd48b2f86	sqlsvr	microsoft/mssql-server-linux:2017   				Exited (137) 2 days ago
4d10ed9b1ebd    oracle	oracle/database:12.2.0.1-ee  					Up 14 minutes (healthy)              

Set up a new SYS, SYSTEM and PDB_ADMIN password as the auto-generated one is not secure:

docker exec oracle ./setPassword.sh new_password

Connect to the container:

docker exec -it oracle /bin/bash

Create new tablespaces, schemas and non-admin users from inside the container using SqlPlus:

sqlplus sys/new_password@ORCLPDB1 AS SYSDBA

Mac SqlPlus Installation

Ignore the following if you have already installed SqlPlus. If not, this is straightforward using Homebrew, but requires more then a one-line command.

Download instantclient-basic-macos.x64-12.2.0.1.0.zip and instantclient-sqlplus-macos.x64-12.2.0.1.0.zip from Oracle to ~/Library/Caches/Homebrew, then run:

brew tap InstantClientTap/instantclient
brew install instantclient-basic
brew install instantclient-sqlplus

Connect from the host

Connect to the pluggable database using SqlPlus:

sqlplus your_schema/user_password@//localhost:1521/ORCLPDB1

If that works, one should be able to connect using an app such as DataGrip by creating a connection using the same details:

screen-shot

Starting and Stopping

Once set up, the container can be started and stopped using (remember to use the name you assigned):

docker start oracle
docker stop oracle