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.
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/126.96.36.199 linuxx64_12201_database.zip in the location you chose earlier.
From docker-images-master/OracleDatabase/dockerfiles, run this from the Terminal:
./buildDockerImage.sh -v 188.8.131.52 -e
You should see "Complete" if it has succeeded. The parameters for this command are:
- -v version to build
- * select one edition only: -e, -s, or -x
- -e: creates image based on 'Enterprise Edition'
- -s: creates image based on 'Standard Edition 2'
- -x: creates image based on 'Express Edition'
- -i: ignores the MD5 checksums
- -o: passes on Docker build option
Once done, check using:
You should see something like:
REPOSITORY TAG IMAGE ID CREATED SIZE oracle/database 184.108.40.206-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:220.127.116.11-ee
The full command parameters are:
- --name name of the container (default: auto generated)
- -p host to container port mapping. Two are exposed: 1521 (Oracle Listener), 5500 (OEM Express)
- ORACLE_SID: Oracle Database SID (default: ORCLCDB)
- ORACLE_PDB: Oracle Database PDB name (default: ORCLPDB1)
- ORACLE_PWD: SYS, SYSTEM and PDB_ADMIN password (default: auto generated)
- ORACLE_CHARACTERSET: character set to use when creating the database (default: AL32UTF8)
- --v your_path /opt/oracle/oradata: host to container data volume mapping
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:18.104.22.168-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-22.214.171.124.0.zip and instantclient-sqlplus-macos.x64-126.96.36.199.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:
If that works, one should be able to connect using an app such as DataGrip by creating a connection using the same details:
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