Local Oracle Database, using Docker June 11, 2019


Installation

  1. Create a Docker account and login to the Docker Hub
  2. Install Docker (the instructions vary depending on your OS)
  3. Navigate to the Oracle Database Docker image on Docker Hub
    • Click on "Proceed to checkout"
    • Accept the licence
  4. Run the following docker commands:
> docker login
Authenticating with existing credentials...
Login Succeeded
> docker run -d -it --name oracleDb -p 1521:1521 -p 5500:5500 -v oracleDbData:/ORCL store/oracle/database-enterprise:12.2.0.1-slim

Where:

For more information, read docker run --help

Usage

The Docker container running the database can be used in the same way as any other instance of an Oracle database. This means you can connect to it using SQL*Plus or any other database access tool, such as DBeaver.

Oracle database connection strings are formatted like so: jdbc:oracle:thin:@<host>:<port>:<database>. The driver's class name is oracle.jdbc.driver.OracleDriver. The table below contains the default connection information.

Parameter Value
Connection string jdbc:oracle:thin:@localhost:1521:ORCLCDB
Host localhost or 10.0.75.1 (Windows)
Port 1521
Database ORCLCDB
User sys (might need to use sys AS SYSDBA)
Password Oradoc_db1
Role SYSDBA or SYSOPER

Maintenance

Connecting using sqlplus bash

To connect using sqlplus bash, simply run the following docker command:

docker exec -it oracleDb bash -c "source /home/oracle/.bashrc; sqlplus /nolog"

Where:

For more information, read docker exec --help

To connect to the database itself, run the following commands:

SQL> connect SYS AS SYSDBA
Enter password: Oradoc_db1
Connected.
...
SQL> exit

Adding a new user and database

To add a new user and database, start by connecting to the container using sqlplus bash, then simply run the following commands:

ALTER SESSION SET "_ORACLE_SCRIPT" = true;
CREATE USER <username> IDENTIFIED BY <password>;
GRANT RESOURCE TO <username>;
GRANT CONNECT TO <username>;
GRANT CREATE VIEW TO <username>;
GRANT CREATE SESSION TO <username>;
GRANT UNLIMITED TABLESPACE TO <username>;
GRANT SELECT ON SYS.DBA_RECYCLEBIN TO <username>;
exit

For more information, see this link

Tailing the logs

To tail the logs, simply run the following docker command:

docker logs -f oracleDb --tail 500

Where:

For more information, read docker logs --help


Docker Cheatsheet
Last updated on August 7, 2019

— Etienne Lamoureux