Pete Freitag Pete Freitag

How to run Oracle DB on a Mac with Docker

Updated on August 10, 2020
By Pete Freitag
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.



docker oracle mac databases

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:

Discuss / Follow me on Twitter ↯

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
#7 14.77 sed: can't read /etc/security/limits.d/oracle-database-preinstall-18c.conf: No such file or directory

This error happens on a Mac M1
by Antonio Gil on 10/13/2021 at 11:46:13 AM UTC
Good evening, this tutorial was really useful and thanks.
But I can't execute the sqlplus command from my terminal since it is not recognized... also I don't know how to open Oracle Net Manager.
Can anyone help me?
Thank you.
by AGNERO on 02/23/2022 at 6:10:40 PM UTC
Thank you very much, this is great.

One small comment, for me i did not see
./buildDockerImage.sh script.
i used this buildContainerImage.sh and worked fine.

Thank you again.
by Mallesham Manchala on 03/16/2022 at 11:44:42 PM UTC
Hi. The build failed for me.

This is my directory >
dockerfiles % ls
1.0.1 12.1.0.2 18.3.0 19.3.0 buildContainerImage.sh
11.2.0.2 12.2.0.1 18.4.0 21.3.0

I ran BuildContainer 21.3.0 (most recent version)
./buildContainerImage.sh -x -v 21.3.0

and then I got this prompt telling me the image was not created

ERROR: Oracle Database container image was NOT successfully created.
ERROR: Check the output and correct any reported problems with the build operation.
by Anonymous on 06/08/2022 at 6:06:57 AM UTC
This seems like an outdated method, although I am not a computer expert. You can get it directly from Oracle with this command: docker pull container-registry.oracle.com/database/enterprise:latest. Is there any advantage of this method versus the "docker pull" from the registry?
by Mike on 06/13/2022 at 3:10:46 PM UTC