Pete Freitag Pete Freitag

How to run Oracle DB on a Mac with Docker

Updated: August 10, 2020
databases

Oracle puts out a Windows and Linux binary for their Oracle Database servers, but what if you want to run it on a Mac? The solution for a while was to use a VM and boot up the linux version. Nowadays using Docker is a little bit easier.

I will say that running Oracle DB on docker is not quite as easy as installing SQL Server on a Mac with Docker, but it is also not too difficult.

Download the Oracle Database Linux Binary

Your first step is to download the Download the Oracle Express Edition version 18c (xe) Linux rpm from oracle.com. Oracle's docker files do support other editions, but the Express Edition is sufficient for getting started.

Clone the Oracle Dockerfile Repo

Oracle has a GitHub repo with all its Dockerfiles, you can clone it (download it) by running:

git clone https://github.com/oracle/docker-images.git

Copy Binary to Dockerfiles dir

Within the git repository you just cloned, go to the OracleDatabase dockerfiles folder:

cd ./OracleDatabase/SingleInstance/dockerfiles

Copy the binary you downloaded in step 1 to the 18.4.0 folder within the dockerfiles folder:

cp ~/Downloads/oracle-database-xe-18c-1.0-1.x86_64.rpm ./18.4.0

Build a Docker Image

Run the script:

./buildDockerImage.sh -x -v 18.4.0

The -x tells the script that you are installing the express edition, and the -v 18.4.0 tells it which version you are installing.

This step will take a few minutes.

Look for local docker image

You should now have a docker image named oracle/database:18.4.0-xe which you can start using docker. Run docker images from Terminal to look for it and make sure it is there. The total size of the image will be around 8-9GB.

Start an Oracle Database Using docker-compose

Finally we'll create a docker-compose.yml file so we can easily startup the db whenever we need it:

version: "3"
services:
    oracle:
        image: oracle/database:18.4.0-xe
        ports:
            - "11521:1521"
        environment:
            - ORACLE_PWD=testing12345

Now we can start up our container by running:

docker-compose up

If you omit the ORACLE_PWD environment variable it will just generate a presumably random password and output it during startup. The startup takes a few minutes to initialize.

After it starts up you will have an oracle database that is accessible on your local machine on port 11521.


Like this? Follow me ↯

How to run Oracle DB on a Mac with Docker was first published on November 05, 2019.

If you like reading about docker, oracle, mac, or databases then you might also like:

Comments

Thank you very much, exactly what I was looking for!
by Oliver Weiler on 01/08/2020 at 12:39:28 PM UTC
I really found this blog useful! One thing I noticed though, in the docker-compose.yml file, I had to outdent the services block so that it became a sibling to version for it to parse correctly.
by Venka Ashtakala on 03/26/2020 at 2:32:34 AM UTC
Hello, thanks for the tutorial! I had to do the same as Venka Ashtakala to get the docker-compose.yml to parse correctly
by Jessica on 04/02/2020 at 2:08:37 PM UTC
Are you sure you need the DB binary files?

From: https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance

IMPORTANT: You will have to provide the installation binaries of Oracle Database (except for Oracle Database 18c XE) and put them into the dockerfiles/<version> folder.


The file is fetched during docker build:
INSTALL_FILE_1="https://download.oracle.com/otn-pub/otn_software/db-express/oracle-database-xe-18c-1.0-1.x86_64.rpm"
by Robert Reynisson on 04/22/2020 at 2:31:23 PM UTC
@Robert - I didn't work unless I downloaded it first when I attempted this, maybe that has changed. Let me know if it worked for you.

@Venka & Jessica - thanks I fixed the indentation.
by Pete Freitag on 05/14/2020 at 3:06:30 PM UTC
This post was really useful, Thanks!!!
One doubt I have is, what url is using to connect to the database? I mean, what username, password or databasename is using...

Thank you!!
by Jose Gomez on 10/13/2020 at 9:18:51 PM UTC
Building image 'oracle/database:11.2.0.2-xe' ...
Sending build context to Docker daemon 633.2MB
Step 1/8 : FROM oraclelinux:7-slim
Get https://registry-1.docker.io/v2/library/oraclelinux/manifests/7-slim: unauthorized: incorrect username or password

ERROR: Oracle Database container image was NOT successfully created.
ERROR: Check the output and correct any reported problems with the build operation.

I need a special account in docker-hub?

Thanks
by rleon on 01/22/2021 at 1:46:11 PM UTC
#7 17.83 sed: can't read /etc/security/limits.d/oracle-database-preinstall-18c.conf: No such file or directory
------
executor failed running [/bin/sh -c chmod ug+x $INSTALL_DIR/*.sh && sync && $INSTALL_DIR/$CHECK_SPACE_FILE && cd $INSTALL_DIR && yum -y install openssl oracle-database-preinstall-18c && sed -i -e 's/\(oracle\s\+hard\s\+nofile\)/# \1/' /etc/security/limits.d/oracle-database-preinstall-18c.conf && yum -y localinstall $INSTALL_FILE_1 && rm -rf /var/cache/yum && rm -rf /var/tmp/yum-* && mkdir -p $ORACLE_BASE/scripts/setup && mkdir $ORACLE_BASE/scripts/startup && ln -s $ORACLE_BASE/scripts /docker-entrypoint-initdb.d && mkdir -p $ORACLE_BASE/oradata /home/oracle && chown -R oracle:oinstall $ORACLE_BASE /home/oracle && mv $INSTALL_DIR/$RUN_FILE $ORACLE_BASE/ && mv $INSTALL_DIR/$PWD_FILE $ORACLE_BASE/ && mv $INSTALL_DIR/$CHECK_DB_FILE $ORACLE_BASE/ && mv $INSTALL_DIR/$CONF_FILE /etc/sysconfig/ && ln -s $ORACLE_BASE/$PWD_FILE / && cd $HOME && rm -rf $INSTALL_DIR && chmod ug+x $ORACLE_BASE/*.sh]: exit code: 2

ERROR: Oracle Database container image was NOT successfully created.
ERROR: Check the output and correct any reported problems with the build operation.
It says this error any solution?
by Om Verma on 03/25/2021 at 11:16:42 AM UTC
There must have been a recent change as the buildDockerImage.sh is now buildContainerImage.sh but it works the same.
by Bill Cunningham on 03/29/2021 at 5:41:31 PM UTC

Post a Comment