…or a 12.2…or a 11.2 image…
To quickly build an Oracle database Docker image, you can clone the official Oracle Git repository and run the included build script. This isn’t too difficult and worked really nicely on my MacBook Pro.
However, when I tried setting it up on an Oracle cloud compute instance, I came across an error that forced me to learn a few more things about Docker in order to get it to work.
The basic steps are outlined in the README.md file. However, when following the steps, the build script failed due to a memory error.
First I wanted to make sure that all docker images and containers will run on a mount point that had plenty of room. In my case, this was /u01. So I needed to change the Docker configuration to use that directory rather than the default of /var/lib/docker. To do that follow these instructions and change the /lib/systemd/system/docker.service file. I commented out the original text and added the new version of ExecReload:
# ExecStart=/usr/bin/dockerd ExecStart=/usr/bin/dockerd -g /u01/docker
The second thing I had to do is change the Docker base image size. To see what that is use:
$ docker info | grep mem Total Memory: 10GiB
To build the Oracle database image you need a minimum of 15GB. To do this edit or create the file /etc/sysconfig/docker-storage and add
DOCKER_STORAGE_OPTIONS= –storage-driver devicemapper –storage-opt dm.basesize=25G
Now bounce the Docker daemon and check the base image size:
$ systemctl stop docker $ systemctl start docker $ docker info | grep mem Total Memory: 21.47GB
I also had to make sure that my system is clean, i.e. no other Docker images or containers.
$ docker system prune -f --volumes $ docker system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 0 0 0B 0B Containers 0 0 0B 0B Local Volumes 0 0 0B 0B Build Cache 0B 0B
Now I was able to run the build script as per instructions and build the database image.
$ cd /u01/git/docker-images/OracleDatabase/dockerfiles $ ./buildDockerImage.sh -v 22.214.171.124 -e
Running the Image
Once the image is built, you need to run it mapping the ordadata directory to a directory on the host. I used /u01/oracle/oradata/docker-126.96.36.199ee, which is owned by the OS user cruepprich and group cruepprich. The oracle user inside the container needs to have permissions to that directory. The UID of the oracle user inside the container is 54321. So add that UID to the host and assign it to the group owning the directory:
# useradd 54321 # usermod -G cruepprich 54321
In order to pull the Oracle image, you need to log into your docker account:
$ docker login -p yourUsername -u yourPassword
Now run the container from a shell script that looks something like this:
#!/bin/bash docker run --name oracle12 \ -p 1521:1521 -p 5500:5500 \ -e ORACLE_SID=orcl \ -e ORACLE_PDB=pdb1 \ -e ORACLE_PWD=oracle \ -e ORACLE_CHARACTERSET=AL32UTF8 \ -v /u01/oracle/oradata/docker-188.8.131.52ee:/opt/oracle/oradata \ -d \ store/oracle/database-enterprise:184.108.40.206
You can follow the startup log with:
$ docker log -f <container ID>
To log into SQL*Plus as sysdba use:
$ docker exec -it oracle12 bash -c "source /home/oracle/.bashrc; sqlplus / as sysdba"
For further commands, and documentation see: