Build Oracle Docker Image
Deploying an Oracle Database within a Docker container can significantly streamline development and testing processes. This guide outlines the necessary steps to build and run an Oracle Docker image efficiently.
Prerequisites
Ensure git is installed on your system. Begin by cloning the Oracle Docker images repository:
git clone https://github.com/oracle/docker-images.git
Download Oracle Installation Binaries:
Download the required Oracle Database 19c binaries for Linux x86-64 or ARM architecture from the Oracle website. Place the binaries under the appropriate directory:
Oracle Database 19c (19.3) for Linux x86-64
https://www.oracle.com/database/technologies/oracle19c-linux-downloads.html
LINUX.X64_193000_db_home.zip
Oracle Database 19c (19.19) for LINUX ARM (aarch64)
https://www.oracle.com/database/technologies/oracle19c-linux-arm64-downloads.html
LINUX.ARM64_1919000_db_home.zip
Copy the zip file under docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0
Build Docker Image
Navigate to the Dockerfiles directory and execute the build script:
cd docker-images/OracleDatabase/SingleInstance/dockerfiles
./buildContainerImage.sh -e -v 19.3.0 -o "--memory=4g --memory-swap=4g --build-arg SLIMMING=false" >> /root/oracleimg.log
This process may take around 3 minutes.
Create Docker Compose File
Next, we'll create a Docker compose file that defines our Oracle database container.
oracle-docker-compose.yml
version: "3"
services:
oracle_src:
image: oracle/database:19.3.0-ee
container_name: oracle_src
restart: always
shm_size: 1gb
ports:
- "1521:1521"
environment:
- ORACLE_SID=ORCLCDB
- ORACLE_PDB=ORCLPDB1
- ORACLE_PWD=Password1234
- ENABLE_ARCHIVELOG=true
volumes:
- oradata:/opt/oracle/oradata
networks:
- orcl-network
networks:
orcl-network:
driver: bridge
volumes:
oradata:
This file defines the services that will be used to run Oracle. It also sets up the necessary volumes and networks.
Start the Container
Now that we have our Docker compose file set up, it's time to start the container! Run the following command:
docker-compose -f oracle-docker-compose.yml up -d
This will start all the container/service in detached mode, meaning it will run in the background.
This database setup takes some time to become fully operational, allow approximately 10 minutes.
Setup Oracle Database
Access the Oracle database with the following credentials:
- Host: 127.0.0.1
- Port: 1521
- SID: ORCLCDB
- User: sys
- Password: Password1234
- Role: SYSDBA
Execute the provided SQL commands to configure users, roles, and privileges.
ALTER SESSION SET CONTAINER=CDB$ROOT;
CREATE USER C##MYUSER IDENTIFIED BY PASSWORD QUOTA UNLIMITED ON USERS CONTAINER=ALL;
ALTER USER C##MYUSER SET CONTAINER_DATA = (CDB$ROOT, ORCLPDB1) CONTAINER=CURRENT;
GRANT CONNECT, CREATE SESSION, ALTER SESSION, SET CONTAINER TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$DATABASE TO C##MYUSER CONTAINER=ALL;
GRANT FLASHBACK ANY TABLE TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ANY TABLE TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ANY DICTIONARY TO C##MYUSER CONTAINER=ALL;
GRANT SELECT_CATALOG_ROLE TO C##MYUSER CONTAINER=ALL;
GRANT EXECUTE_CATALOG_ROLE TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ANY TRANSACTION TO C##MYUSER CONTAINER=ALL;
GRANT LOGMINING TO C##MYUSER CONTAINER=ALL;
GRANT CREATE TABLE TO C##MYUSER CONTAINER=ALL;
GRANT LOCK ANY TABLE TO C##MYUSER CONTAINER=ALL;
GRANT CREATE SEQUENCE TO C##MYUSER CONTAINER=ALL;
GRANT CREATE TRIGGER TO C##MYUSER CONTAINER=ALL;
GRANT EXECUTE ON SYS.DBMS_LOGMNR TO C##MYUSER CONTAINER=ALL;
GRANT EXECUTE ON SYS.DBMS_LOGMNR_D TO C##MYUSER CONTAINER=ALL;
GRANT EXECUTE ON SYS.DBMS_LOGMNR_LOGREP_DICT TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$LOG TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$LOG_HISTORY TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$LOGMNR_LOGS TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$LOGMNR_CONTENTS TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$LOGMNR_PARAMETERS TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$LOGFILE TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$ARCHIVED_LOG TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$ARCHIVE_DEST_STATUS TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$TRANSACTION TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$MYSTAT TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON V_$STATNAME TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON SYSTEM.LOGMNR_COL$ TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON SYSTEM.LOGMNR_OBJ$ TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON SYSTEM.LOGMNR_USER$ TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON SYSTEM.LOGMNR_UID$ TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON GV_$DATABASE TO C##MYUSER CONTAINER=ALL;
GRANT SELECT ON GV_$ARCHIVED_LOG TO C##MYUSER CONTAINER=ALL;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
ALTER SESSION SET CONTAINER=ORCLPDB1;
CREATE USER ORCL_USER IDENTIFIED BY Password1234;
ALTER USER ORCL_USER QUOTA UNLIMITED ON USERS;
GRANT DBA to ORCL_USER;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (ALL) COLUMNS;
CREATE TABLE ORCL_USER.CONSULTANTS("ID" INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,"FIRST_NAME" VARCHAR(50),"LAST_NAME" VARCHAR(50),"EMAIL" VARCHAR(50),"RATE" NUMBER(8,2),"STATUS" VARCHAR(20),"CREATED_AT" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ,"UPDATED_AT" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL);
GRANT SELECT ON ORCL_USER.CONSULTANTS TO C##MYUSER;
Let's add some data
ALTER SESSION SET CONTAINER=ORCLPDB1;
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('John', 'Doe', 'john.doe@gmail.com', 3000.00, 'perm');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Tom', 'Hanks', 'tom.hanks@yahoo.com', 3500.75, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Jane', 'Doe', 'jane.doe@moneybank.com', 3500.75, 'perm');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Duke', 'Johnson', 'duke@hello.com', 4500.25, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Peter', 'Parker', 'peter@gmail.com', 5000, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Rick', 'Nice', 'rick@gmail.com', 4900, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Tommy', 'Hill', 'tommy@gmail.com', 4100, 'perm');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Jill', 'Stone', 'jill@gmail.com', 4250.50, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Honey', 'Bee', 'honey@gmail.com', 3200, 'perm');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Bell', 'Doe', 'bell@gmail.com', 34000, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Jim', 'Anderson', 'jim@gmail.com', 5000, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Joe', 'Star', 'joe@gmail.com', 3000, 'contract');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Joey', 'Moon', 'joey@gmail.com', 4000, 'perm');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Donald', 'Duck', 'donald@gmail.com', 2500, 'perm');
INSERT INTO ORCL_USER.CONSULTANTS(FIRST_NAME, LAST_NAME, EMAIL, RATE, STATUS) VALUES ('Nat', 'Hill', 'nay@gmail.com', 6000, 'perm');
COMMIT;
By following these steps, you can quickly set up an Oracle Database within a Docker container, facilitating a robust and portable database environment for your applications.