Sunday, February 12, 2023

Install Oracle Database using docker in Mac M1

1:26 PM Posted by Dilli Raj Maharjan , , No comments

 


   

    The new Mac with Apple Silicon is ARM 64-bit architecture and does not directly support x86_64 or AMD 64-bit applications. There are multiple ways to make an x86_64 bit application run with the arm processor. There is no easy and straightforward way to install Oracle Database using docker in mac with M1/M2 chip. Following is the step-by-step guide to install the Oracle database using docker in a mac M1 processor.


Install Homebrew and other required packages.

    Homebrew is a package manager for macOS. It is one of the first tools that need to install on your mac to install docker for x86_64 containers. It is used to install (and remove) software programs for the terminal, or CLI. Almost every useful open-source package is available through Homebrew. Installing Homebrew is pretty easy. Execute the command below in the terminal window to install Homebrew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

    Set environment variables to include brew binary in the PATH environment variable. Execute the following command in the terminal

export PATH=/opt/homebrew/bin:$PATH

    Uninstalled any docker package installed by App Store or using dmg files. It will avoid any crossover with the software. Install the following brew packages. Here, Docker is an open platform for developing, shipping, and running applications using Docker containers. Similarly, Docker Compose is a tool that was developed to help define and share multi-container applications. Colima is a container runtime on MacOS (and Linux) with minimal setup. Colima is almost a drop-in replacement for Docker Desktop. Colima directly supports the ARM chip and it can start up the VM that will run the x86_64 containers. Qemu is an emulator for x86 and arm chips.

$ brew install colima
$ brew reinstall qemu
$ brew install docker
$ brew install docker-compose

    Start a VM to run an x86_64 docker container.  Execute command in the terminal. The command below starts a VM that uses 4 CPUs, and 12G of memory, and supports the x86_64 architecture. This should allow me to download and run an x86_64 container.

colima start -c 4 -m 12 -a x86_64

Validate the status of the VM that was started.

colima list

Once docker everything is ready, export a running docker x86_64 container with the Oracle database running. I tried to install the Oracle database using
Oracle's official docker repo but encountered some java related issues. The second time, I installed OEL 7.9 and tried to install Oracle database software and Oracle database but it failed again with the Java issue. I will troubleshoot the issue later but for this post, I am saving my running Intel-based x86_64 docker container image to a file and loading a file to the docker with an M1 chip.

    Due to a license issue, I cannot share my Oracle Database docker Image file. I am assuming ora19c.gz is a file where I have loaded Oracle docker Image.


Syntax to load the docker image to a file.

docker save oracle/database:19.3.0-ee | gzip  > ora19c.gz

    Once the docker image is saved to the file with the name ora19c.gz. Ship the file to the Mac book Maching with M1 chip. Load the image file copy with the command below.

docker load < ora19c.gz


Create and run a new container from an image oracle.

docker run -d -t -i --privileged --name=oracle19c --hostname=oracle19c -p 1522:1521 -v /Users/raj:/mnt ora19c oracle/database:19.3.0-ee


Verify docker container is running.

docker ps 


Execute /bin/bash command in a running docker container.

docker exec -it -u oracle oracle19c /bin/bash


Starting Oracle Database container later.


Verify if colima is started, if not start with the command below.

/opt/homebrew/bin/colima list
/opt/homebrew/bin/colima start



Start Oracle Database container.

docker start oracle19c


Execute /bin/bash in the running oracle database container.


docker exec -it -u oracle oracle19c /bin/bash