8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux

Home » Articles » Linux » Here

Docker : Oracle Database on Docker

This article describes a simple build for running an Oracle database on Docker.

Related articles.

Assumptions

This article assumes the following.

Build the Image

The Dockerfile and scripts this article is based upon can be found here. The build expects the following file system. You will have to download the Oracle 19c database and APEX software yourself and place it in the "software" directory.

$ tree
.
├── Dockerfile
├── README.md
├── scripts
│   ├── healthcheck.sh
│   └── start.sh
└── software
    ├── apex_20.2_en.zip
    ├── LINUX.X64_193000_db_home.zip
    └── put_software_here.txt

$

The Dockerfile contains some basic instructions, which will be described further here.

With all the files in place you can build the image using the following command.

$ #Docker
$ docker build -t ol7_19:latest .

$ #Podman
$ docker build --format docker -t ol7_19:latest .

The build performs the following actions.

You will notice the build phase doesn't create a database. That is done on the first run of a container.

Run a Container

The database is created the first time the container is started, which means it can take some time for the container to be fully operational, especially because we are also doing an APEX installation into the database.

The simplest way to run a container based on this image is to accept all the defaults and run the following command. It gives the container a name (ol7_19_con), binds a host port to the exposed container port.

$ docker run -dit --name ol7_19_con \
             -p 1521:1521 \
             --shm-size="1G" \
             ol7_19:latest

In the previous example the storage is not persistent, so if the container were removed the database files would be lost. We can solve this problem by creating a directory on the host file system and mounting it to "/u02" in the container. Now the data files reside outside the container. See the Persistent Storage section about the setup of the host volume.

$ mkdir -p ~/volumes/ol7_19_con_u02/
$ docker run -dit --name ol7_19_con \
             -p 1521:1521 \
             --shm-size="1G" \
             -v /u01/volumes/ol7_19_con_u02/:/u02 \
             ol7_19:latest

We could have used a managed volume or a data volume container instead. These approaches are described here.

In the previous examples we've exposed the database to the outside world, but if we want other containers to speak directly to it, we must create a Docker network and associate the container with that network.

$ docker network create my_network

$ docker run -dit --name ol7_19_con \
             -p 1521:1521 -p 5500:5500 \
             --shm-size="1G" \
             --network=my_network \
             -v /u01/volumes/ol7_19_con_u02/:/u02 \
             ol7_19:latest

So far we have relied on the default settings for the database creation, but we can influence this by setting the appropriate environment variables in the run command.

$ docker run -dit --name ol7_19_con \
             -p 1521:1521 -p 5500:5500 \
             --shm-size="1G" \
             -v /u01/volumes/ol7_19_con_u02/:/u02 \
             -e "ORACLE_SID=cdb2" \
             -e "SYS_PASSWORD=SysPassword2" \
             -e "PDB_NAME=pdb2" \
             -e "PDB_PASSWORD=PdbPassword2" \
             -e "APEX_EMAIL=me2@example.com" \
             -e "APEX_PASSWORD=ApexPassword2" \
             ol7_19:latest

Persistent Storage

If you are using an external host volume for persistent storage, the build expects it to owned by a group with the group ID of 1042. This is described here.

start.sh Script

The start.sh script is responsible for creating the database on the first run of the container. It performs the following actions.

healthcheck.sh Script

The healthcheck.sh script is really simple. It connects to the database and runs a query. If the query is successful it returns "0", otherwise it returns "1".

Managing the Container

Once the container is running you can connect to a bash shell using the following command.

$ docker exec -it ol7_19_con bash

The container can be stopped and started using the following commands. The "--time" parameter give the database a chance to shutdown gracefully. Restarting the container has no impact on ephemeral storage, so no data will be lost, even if you are not using persistent storage.

$ docker stop --time=30 ol7_19_con
$ docker start ol7_19_con

The following command removes the container and the associated volumes. If you are not using persistent storage this will result in the loss of the database files.

$ docker rm -vf ol7_19_con 

For more information see:

Hope this helps. Regards Tim...

Back to the Top.