Local Oracle Database, using Docker June 11, 2019
Installation
- Create a Docker account and login to the Docker Hub
- Install Docker (the instructions vary depending on your OS)
- Navigate to the Oracle Database Docker image on Docker Hub
- Click on "Proceed to checkout"
- Accept the licence
- 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:
--name
will name the containeroracleDb
-p
will expose both the1521
and the5500
ports to the host machine-v
will create a volume namedoracleDbData
, so the database data will persist between uses
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:
-it
allows to type in an interactive shell
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:
-f
will keep following the logs in real time--tail
will show the last 500 lines of log
For more information, read docker logs --help
Docker Cheatsheet
Last updated on August 7, 2019
— Etienne Lamoureux