Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Running Oracle in a Docker Container

Introduction to Docker and Oracle Integration

Docker is a popular platform for developing, shipping, and running applications inside containers. Running Oracle in a Docker container provides flexibility, scalability, and ease of deployment for Oracle databases.

Prerequisites

Before starting, ensure you have Docker installed on your machine. You can download Docker Desktop for your operating system from the official Docker website.

Creating a Dockerfile for Oracle

To run Oracle in Docker, you need to create a Dockerfile that defines the environment and configurations.

Example Dockerfile for Oracle:

FROM oracle/database:19.3.0-ee

# Environment variables
ENV ORACLE_SID=ORCLCDB
ENV ORACLE_PDB=ORCLPDB1
ENV ORACLE_PWD=your_password

# Scripts to run during container startup
COPY setup.sql /opt/oracle/scripts/setup.sql
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Expose ports
EXPOSE 1521
EXPOSE 5500

# Container startup command
ENTRYPOINT ["/entrypoint.sh"]
                

Building the Docker Image

Build the Docker image using the Dockerfile. Navigate to the directory containing your Dockerfile and execute the build command.

Example command to build Docker image:

docker build -t oracle-database:19.3 .
                

Running the Oracle Container

Once the image is built, you can run a container based on the image.

Example command to run Oracle container:

docker run -d -p 1521:1521 -p 5500:5500 --name oracle-container oracle-database:19.3
                

Accessing Oracle in Docker

You can now access Oracle running in the Docker container using SQL*Plus or any Oracle client tool.

Example command to connect using SQL*Plus:

sqlplus sys/your_password@//localhost:1521/ORCLCDB as sysdba
                

Cleaning Up

To stop and remove the Oracle Docker container, use the following commands:

Example commands to stop and remove Docker container:

docker stop oracle-container
docker rm oracle-container
                

Conclusion

Running Oracle in a Docker container simplifies deployment and management of Oracle databases, offering scalability and portability across different environments.