Oracle Database Enterprise Docker Developer Tier lacks practical documentation on how to use Oracle’s database effectively on Docker in a windows environment.
This quick start guide is intended for developers who are new to Oracle’s database offerings and are looking for the quickest way to setup a new Oracle database environment for exploratory development scenarios.
Perquisites
- Docker Desktop For Windows Installed on system using Windows Subsystem For Linux (WSL2).
- JetBrains DataGrip which has out of the box support for connecting to Oracle.
Windows Subsystem for Linux (WSL2): Limit CPU/Memory Use
You will need to prevent Oracle Database Enterprise Edition docker container and WSL2 from consuming all of your computer’s memory and CPU before you attempt to run the Oracle Database Enterprise Edition docker image. 😒
- Open Windows Terminal/CMD/PowerShell and run the commands below:
wsl --shutdown
notepad "$env:USERPROFILE/.wslconfig"
- Edit .wslconfig file with notepad and save.
[wsl2]
memory=3GB # Limits memory in WSL 2
processors=4 # Limits number of processors in WSL2
Docker Hub - Oracle Database Enterprise Edition
- Login to Docker Store with your credentials.
- Register for Oracle Database Enterprise Edition on Docker Hub and Accept the terms of service from the store.docker.com website.
Docker Desktop For Windows
- Open Windows Terminal/CMD/PowerShell and run the commands.
docker login
- Pull Oracle Database Enterprise Edition docker image.
docker pull store/oracle/database-enterprise:12.2.0.1
- Run Docker Image and map ports to host system to connect from outside the docker container.
docker run -d --network="bridge" -p 1521:1521 -p 5500:5500 -it --name Oracle_DB_Container store/oracle/database-enterprise:12.2.0.1
Connecting to database container
- Installing the drivers for databases on windows can be complicated and since this is a quick start guide I decided to use JetBrains DataGrip which has built in support for Oracle databases. Currently, DataGrip includes an evaluation license key for a free 30-day trial.
- Connection string to connect to docker container.
jdbc:oracle:thin:@localhost:1521:ORCLCDB
- The super user name and password.
User Name : sys
Password : Oradoc_db1
- Login into the database with the administrator account.
Create Database, User, and Grand Permissions
- Disclaimer: Intended for exploratory development/demonstration scenarios only
- Run following the SQL commands in the query window.
ALTER SESSION SET "_ORACLE_SCRIPT"=true;
-- Create New Table Space
CREATE TABLESPACE new_user_tablespace
DATAFILE 'new_user_tablespace.dbf'
SIZE 1m;
-- Create New User
CREATE USER new_user IDENTIFIED BY "YourPassword123";
-- Grant Permissions
grant create session to new_user;
grant create table to new_user;
grant create session to new_user;
grant create table to new_user;
alter user new_user quota unlimited on users;
grant create view, create procedure, create sequence to new_user;
-- Grant Permissions to Table Space
alter user new_user quota unlimited on new_user_tablespace;
grant UNLIMITED TABLESPACE TO new_user;
Connecting to the New User’s Database Also Known AS “SCHEMA”
- Connection string for connecting to the docker container.
jdbc:oracle:thin:@localhost:1521:ORCLCDB
- The user name and password.
User Name : new_user
Password : YourPassword123
- Login into the database with the new_user account.
- Disclaimer: Intended for exploratory development/demonstration scenarios only
- Run following the SQL commands in the query window.
-- Create New Table.
CREATE TABLE TEST_USER.posts (
id NUMBER(5) PRIMARY KEY,
subject VARCHAR2(15) NOT NULL,
content varchar2(2000))
TABLESPACE NEW_USER_TABLESPACE
STORAGE ( INITIAL 50K);
-- Insert Rows.
INSERT INTO TEST_USER.POSTS (ID, SUBJECT,CONTENT) values (1, 'subject', 'content');
COMMIT;
-- Selecting Rows.
SELECT * FROM TEST_USER.posts;
Conclusion
I hope you found this Quick Start Guide useful.