DEV Community

Hisyam Johan
Hisyam Johan

Posted on

2

Running Oracle 21c on Docker and Restoring a Backup

Bismillah...

Introduction

In this guide, we will cover how to run Oracle 21c on Docker and restore a backup from a dump file. This includes building a Docker image, running it as a container, and executing a backup restoration script.

Prerequisites

Ensure you have Docker installed on your system.

Step 1: Building the Docker Image

Create the following files:

Dockerfile:

FROM gvenzl/oracle-xe:21
# If you have a backup file
COPY start.sh /opt/oracle/start.sh
COPY data.sql /container-entrypoint-initdb.d/data.sql
RUN mkdir -p /opt/oracle/dbbackupdmp
COPY mydb.dmp /opt/oracle/dbbackupdmp/mydb.dmp
USER root
RUN chown oracle:oinstall /opt/oracle/dbbackupdmp/mydb.dmp
USER oracle
Enter fullscreen mode Exit fullscreen mode

data.sql:

create user <user.name> IDENTIFIED BY <user.password>;
grant connect,resource,dba to <user.name>;
grant create session, grant any privilege to <user.name>;
grant unlimited tablespace to <user.name>;

create directory datapump as '/opt/oracle/dbbackupdmp';
grant read, write on directory datapump to <user.name>;
Enter fullscreen mode Exit fullscreen mode

start.sh:

impdp <user.name>/<user.password> directory=datapump dumpfile=mydb.dmp logfile=mydb.log schemas=<user.1>,<user.2>
Enter fullscreen mode Exit fullscreen mode

Build the Docker image using:

docker build -t my/oracle:21 .

Step 2: Running the Docker Container

Run the image as a Docker container:

docker run -d -p 1521:1521 -e ORACLE_PASSWORD=P@ssw0rd --name=myoracle21 my/oracle:21

Step 3: Restoring the Backup (Optional)

Access the running container:

docker exec -ti myoracle21 bash

Navigate to the /opt/oracle directory and execute the restoration script:

bash start.sh

Conclusion

Following these steps, you should have Oracle 21c running in a Docker container with your backup data restored. This setup is efficient for testing and development environments.

Thank you.

Buy Me A Coffee

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay