Before initializing the database engine, ensure the Docker runtime and Docker Compose plugin are installed, operational, and configured to support privileged network bridging.
Service Definition and Resource Mapping
Construct a Compose specification to encapsulate the database lifecycle. The configuration below establishes network isolation, maps listener and EM Express ports, secures the SYSADMIN credentials, and binds a host directory for persistent data storage.
version: '3.8'
services:
oracle_ent:
container_name: db_19c_primary
image: container-registry.oracle.com/database/enterprise:19.3.0.0
restart: unless-stopped
ports:
- "1521:1521"
- "5500:5500"
networks:
data_net:
external: true
environment:
ORACLE_PWD: "SysAdm!2024"
ORACLE_EDITION: enterprise
ORACLE_SID: ORCLCDB
volumes:
- ./persisted_db:/opt/oracle/oradata
- /etc/localtime:/etc/localtime:ro
networks:
data_net:
external: true
Lifecycle Management and Client Access
Instantiate the service in detached mode and verify container health:
docker compose up -d
docker compose ps --format "table {{.Name}}\t{{.Status}}"
External applications should target the following connection descriptor pattern:
jdbc:oracle:thin:@//<host-ip-address>:1521/ORCLCDB
Storage Provisioning and Account Creation
Attach to the running container and invoke SQL*Plus with elevated privileges. Execute the statements below to allocate dedicated storage volumes and provision a schema owner.
docker exec -it db_19c_primary bash -c "sqlplus / as sysdba"
-- Define temporary workspace
CREATE TEMPORARY TABLESPACE tmp_workspace
TEMPFILE '/opt/oracle/oradata/ORCLCDB/pdbseed/tmp_ws01.dbf'
SIZE 100M AUTOEXTEND ON NEXT 50M MAXSIZE 4096M
EXTENT MANAGEMENT LOCAL;
-- Allocate persistent data segment
CREATE TABLESPACE app_storage
LOGGING DATAFILE '/opt/oracle/oradata/ORCLCDB/pdbseed/app_data01.dbf'
SIZE 250M AUTOEXTEND ON NEXT 100M MAXSIZE 8192M
EXTENT MANAGEMENT LOCAL;
-- Provision service account
CREATE USER svc_operator
IDENTIFIED BY "Oper#Pass2024"
DEFAULT TABLESPACE app_storage
TEMPORARY TABLESPACE tmp_workspace;
-- Assign baseline privileges
GRANT CONNECT, RESOURCE, DBA TO svc_operator;
Automated Schema Extraction
Map a filesystem location to an Oracle directory object, then deploy a shell routine that handles export execution, compression, and retention cleanup. The script avoids undefined variables and correctly targets the specified directory alias.
#!/bin/bash
set -e
SCHEMA_ID="svc_operator"
SCHEMA_PWD="Oper#Pass2024"
DB_ALIAS="ORCLCDB"
DEST_PATH="/home/oracle/backup"
RUN_DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p "${DEST_PATH}"
EXP_DMP="exp_${SCHEMA_ID}_${RUN_DATE}.dmp"
EXP_LOG="exp_${SCHEMA_ID}_${RUN_DATE}.log"
expdp "${SCHEMA_ID}/${SCHEMA_PWD}@${DB_ALIAS}" \
DIRECTORY=BACKUP_LOC \
DUMPFILE="${EXP_DMP}" \
LOGFILE="${EXP_LOG}" \
SCHEMAS="${SCHEMA_ID}" \
COMPRESSION=DATA_ONLY
gzip -9 "${DEST_PATH}/${EXP_DMP}"
rm -f "${DEST_PATH}/${EXP_LOG}"
# Archive retention: purge files older than 7 days
find "${DEST_PATH}" -type f -name "*.dmp.gz" -mtime +7 -delete
Schema Restoration Procedure
Recreate the directory mapping within the target database instance and utilize the Data Pump Import utility to reconstruct the schema state from the archived dump file.
CREATE OR REPLACE DIRECTORY BACKUP_LOC AS '/home/oracle/backup';
GRANT READ, WRITE ON DIRECTORY BACKUP_LOC TO svc_operator;
-- Execute via OS shell after decompressing the archive if necessary
impdp svc_operator/Oper#Pass2024@ORCLCDB \
DIRECTORY=BACKUP_LOC \
DUMPFILE=exp_svc_operator_20231015_083000.dmp \
LOGFILE=imp_svc_operator_restore.log \
SCHEMAS=svc_operator \
TABLE_EXISTS_ACTION=REPLACE