8i | 9i | 10g | 11g | 12c | 13c | 18c | 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 18c database and APEX software yourself and place it in the "software" directory.

$ tree
.
├── Dockerfile
├── README.md
├── scripts
│   ├── healthcheck.sh
│   └── start.sh
└── software
    ├── apex_18.1_en.zip
    ├── LINUX.X64_180000_db_home.zip
    └── put_software_here.txt

2 directories, 7 files
$

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 build -t ol7_183: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_183_con), binds a host port to the exposed container port.

$ docker run -dit --name ol7_183_con \
             -p 1521:1521 \
             --shm-size="1G" \
             ol7_183: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.

$ mkdir -p ~/volumes/ol7_183_con_u02/
$ docker run -dit --name ol7_183_con \
             -p 1521:1521 \
             --shm-size="1G" \
             -v /home/docker_user/volumes/ol7_183_con_u02/:/u02 \
             ol7_183: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_183_con \
             -p 1521:1521 -p 5500:5500 \
             --shm-size="1G" \
             --network=my_network \
             -v /home/docker_user/volumes/ol7_183_con_u02/:/u02 \
             ol7_183: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_183_con \
             -p 1521:1521 -p 5500:5500 \
             --shm-size="1G" \
             -v /home/docker_user/volumes/ol7_183_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_183:latest

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_183_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_183_con
$ docker start ol7_183_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_183_con 

For more information see:

Hope this helps. Regards Tim...

Back to the Top.