Oracle 12c docker setup on Apple M1

Solution 1:

Oracle Database on M1 Mac

This is a doozy.. Oracle Database isn't supported on MacOS, however, with Docker virtualizing linux, it can be. Unfortunately, even though Docker supports M1 Mac ARM virtualization, Oracle Database relies heavily on some low level kernel calls that Docker and Rosetta 2 can't handle. This leads us to the only possible solution to run locally: Using full emulation (a virtual machine).

  1. Install Lima with HomeBrew. Lima is a sort of unofficial "macOS subsystem for Linux" with support for running VMs with different architecture (like running an x86 OS on top of ARM MacOS):
brew install lima
  1. Create a new Impish Ubuntu (default) Virtual Machine:
limactl start
  1. Select Open an editor to override the configuration.
  2. Using the default editor (vi) modify the arch field to the following (i to enter insert mode, make the change, ESC to enter command mode, :wq to exit and save).
arch: "x86_64"
  1. Run the newly created default Lima VM, and change directories to the new VM's home directory. (All commands past this should be run in the newly started shell unless specified otherwise).
lima
cd ~
  1. Install Docker for Ubuntu in the Lima VM (You probably need to get a commercial license for this by opening a service-now ticket).
  2. Add your user to the docker group, and activate the changes to be able to run docker commands without root access:
sudo usermod -aG docker $USER
newgrp docker
  1. Clone the git repository containing oracle docker images: 
git clone https://github.com/oracle/docker-images.git
  1. Build the docker image for the version and edition of the Oracle database that you want to spin up by running the following 2 commands below. In the 2nd command below, please note that 18.4.0 is the version number and x i.e. express is the edition. This will take a long time (over an hour).
cd docker-images/OracleDatabase/SingleInstance/dockerfiles
./buildContainerImage.sh -v 18.4.0 -x
  1. After the image has been built, verify that it is available by running the following command. There should be an image named oracle/database with a tag matching the version that you specified in the step above.
docker images
mkdir ~/dev

sudo chmod 775 ~/dev -R
sudo chown 54321:54321 ~/dev -R
  1. Spin up a container for the created docker image by running the below command (a successful completion will take over an hour).
docker run --name oracledb \
  -d \
  -p 1521:1521 \
  -p 5500:5500 \
  -e ORACLE_PWD=oracle \
  -v ~/dev/docker/oracledb/oradata:/opt/oracle/oradata \
  -v ~/dev/docker/oracledb/scripts/setup:/opt/oracle/scripts/setup \
  -v ~/dev/docker/oracledb/scripts/startup:/opt/oracle/scripts/startup \
  oracle/database:18.4.0-xe
  1. The above script may error on certain file permissions. You can check for errors with docker logs oracledb. If you see file permission issues, run the following commands, then rerun the previous step:
docker stop oracledb

sudo chmod 775 ~/dev -R
sudo chown 54321:54321 ~/dev -R
  1. Verify the database setup was successful:
docker logs oracledb

You should look for the following message:

#########################
DATABASE IS READY TO USE!
#########################
  1. Ensure you can connect to the database either through a GUI such as DBeaver, SQL Developer, or command line using sqlplus with the following connection string: system/[email protected]:1521/xe

Performance

At the end of the day, this is not going to be a snappy database. Running in the background the underling qemu process takes up 5.2 GB. In comparison The qemu process for Docker Desktop was taking up 3 GB without running an Oracle Database. So all things considered, the ram hit isn't as massive as it could be.

Running the query SELECT owner, table_name FROM all_tables; returned results in about 6 seconds.