Deploy Oracle Autonomous Database Free Container Image on Mac with Apple Silicon

Shadab Mohammad
Oracle Developers
Published in
5 min readSep 28, 2023

--

Photo by Louis Hansel on Unsplash

At Oracle Cloudworld on 19th September we announced a free container image for Autonomous DB. The ADB free container image comes pre-built with the following components exactly like our cloud offering:

- Apex
- Oracle Rest Data Services (ORDS)
- Database Actions including SQL Developer
- MongoDB API

Autonomous Database Free Container Image is now available on Oracle Container Registry *, you can perform local development with an ADB free container image and have the ability to merge your work later in a cloud instance.

Github Link :

[*] https://github.com/oracle/adb-free/pkgs/container/adb-free

In this blog post I will show you how you can deploy the ADB free container image with Docker on your Mac with Apple Silicon.

For this demo I’m using an M1 Macbook Pro, but this demo should work on most platforms where you can deploy containers using Docker or Podman

Total Cost of Solution : $0

Step 1. Install Docker on your Apple Silicon Mac

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

Step 2. Start Colima x86_64 Virtual Machine

Oracle Autonomous Database Free container needs 4 CPUs and 8 GiB memory

colima start --cpu 4 --memory 8 --arch x86_64

Step 3. Run ADB Free container

Oracle Autonomous Database Free Container image comes with 2 prebuilt Databases — MY_ATP and MY_ADW. These are similar to Transaction Processing and Data Warehouse workload type databases in Autonomous Database Serverless Cloud service.

The following key features are supported:

  • Oracle Rest Data Services (ORDS)
  • APEX
  • Database Actions
  • Mongo API enabled (by default routed to MY_ATP)

The storage size is limited to 20 GB for each Database

#Download and Run the ADB free container
sudo docker run -d \
-p 1521:1522 \
-p 1522:1522 \
-p 8443:8443 \
-p 27017:27017 \
--hostname localhost \
--cap-add SYS_ADMIN \
--device /dev/fuse \
--name adb_container \
container-registry.oracle.com/database/adb-free:latest

#Check docker image
docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE
container-registry.oracle.com/database/adb-free latest 8a4b5137f179 2 weeks ago 9.69GB

#Check container status
docker container ls

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63622f8976f7 container-registry.oracle.com/database/adb-free:latest "/bin/bash -c /u01/s…" 3 minutes ago Up 2 minutes (healthy) 0.0.0.0:1522->1522/tcp, :::1522->1522/tcp, 0.0.0.0:8443->8443/tcp, :::8443->8443/tcp, 0.0.0.0:27017->27017/tcp, :::27017->27017/tcp, 0.0.0.0:1521->1522/tcp, :::1521->1522/tcp adb_container

Note the following ports which are forwarded to the container process:

Step 4. Connect to ADB Container and deploy sample tables

The default password for admin schema for both MY_ATP and MY_ADW is Welcome_MY_ATP_1234 and Welcome_MY_ADW_1234 respectively. We need to reset the default passwords before we can login.

#Change default admin password for database MY_ATP

docker exec <container-id> /u01/scripts/change_expired_password.sh MY_ATP admin Welcome_MY_ATP_1234 <new_passwd>

docker exec <container-id> /u01/scripts/change_expired_password.sh MY_ADW admin Welcome_MY_ADW_1234 <new_passwd>

docker exec 63622f8976f7 /u01/scripts/change_expired_password.sh MY_ATP admin Welcome_MY_ATP_1234 YOurPWD_1234

docker exec 63622f8976f7 /u01/scripts/change_expired_password.sh MY_ADW admin Welcome_MY_ADW_1234 YOurPWD_1234
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Sep 27 13:27:42 2023
Version 19.20.0.1.0
Copyright (c) 1982, 2023, Oracle. All rights reserved.ERROR:
ORA-28001: the password has expired
Changing password for admin
New password:
Retype new password:
Password changed

Open SQL Developer web >>>> https://localhost:8443/ords/my_atp/sql-developer

Sign-in with previously reset admin username and password

Step 5. Download Wallet and Connect with sqlcl

# Copy the Wallet to your local machine
mkdir -p /Users/shadab/Downloads/wallet_adb_free_container

cd /Users/shadab/Downloads/wallet_adb_free_container

docker cp 63622f8976f7:/u01/app/oracle/wallets/tls_wallet ./

#You can see a folder called tls_wallet created which has the wallet files

#Export TNS_ADMIN variable with the location of the wallet
export TNS_ADMIN='/Users/shadab/Downloads/wallet_adb_free_container/tls_wallet'

#Check tnsnames.ora file in the tls_wallet folder for the tns entry for your ATP
cd tls_wallet/
ls -ltr
cat tnsnames.ora
echo $TNS_ADMIN

# Connect with sqlcl using the tns entry
sql admin/YOurPWD_1234@my_atp_high

SQLcl: Release 22.4 Production on Thu Sept 28 11:58:54 2023

Copyright (c) 1982, 2023, Oracle. All rights reserved.

Last Successful login time: Thu Sep 28 2023 11:58:57 +10:00

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.20.0.1.0

SQL>

Step 6. Create a sample table and insert n records

--Create a Sample Oracle Table called 'orders'--
CREATE TABLE orders (
order_id NUMBER(38) GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
customer_id NUMBER(38),
product_id NUMBER(38),
product_description VARCHAR2(500),
order_delivery_address VARCHAR2(500),
order_date_taken DATE,
order_misc_notes VARCHAR2(500)
);

--Create PL/SQL procedure to insert random n records to the table--
CREATE OR REPLACE PROCEDURE add_random_orders(n IN NUMBER)
IS
TYPE t_orders IS TABLE OF orders%ROWTYPE;
v_orders t_orders := t_orders();
BEGIN
-- Generate random orders and add to collection
FOR i IN 1..n LOOP
v_orders.EXTEND;
v_orders(i).customer_id := FLOOR(DBMS_RANDOM.VALUE(1, 100));
v_orders(i).product_id := FLOOR(DBMS_RANDOM.VALUE(1, 50));
v_orders(i).product_description := 'Product ' || (FLOOR(DBMS_RANDOM.VALUE(1, 10)) + 1);
v_orders(i).order_delivery_address := 'Address ' || (FLOOR(DBMS_RANDOM.VALUE(1, 10)) + 1);
v_orders(i).order_date_taken := TRUNC(SYSDATE) - FLOOR(DBMS_RANDOM.VALUE(1, 30));
v_orders(i).order_misc_notes := 'Note ' || (FLOOR(DBMS_RANDOM.VALUE(1, 10)) + 1);
END LOOP;
-- Insert collection into database using BULK COLLECT
FORALL i IN 1..v_orders.COUNT
INSERT INTO orders (customer_id, product_id, product_description, order_delivery_address, order_date_taken, order_misc_notes)
VALUES (v_orders(i).customer_id, v_orders(i).product_id, v_orders(i).product_description, v_orders(i).order_delivery_address, v_orders(i).order_date_taken, v_orders(i).order_misc_notes);
COMMIT;
DBMS_OUTPUT.PUT_LINE(n || ' random orders added.');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
ROLLBACK;
END;
/

-- Execute Procedure to Insert Data --
BEGIN
add_random_orders(100000);
END;
/

--Verify records--
select count(*) from admin.orders;

Step 7. Create a new user on the free container instance and connect to it

Create new user in ADB free container image:


CREATE USER APEXAPP IDENTIFIED BY "Demoapp_1234" QUOTA UNLIMITED ON DATA;

-- ADD ROLES
GRANT CONNECT TO APEXAPP;
GRANT CONSOLE_DEVELOPER TO APEXAPP;
GRANT DWROLE TO APEXAPP;
GRANT RESOURCE TO APEXAPP;


-- ENABLE REST
BEGIN
ORDS.ENABLE_SCHEMA(
p_enabled => TRUE,
p_schema => 'APEXAPP',
p_url_mapping_type => 'BASE_PATH',
p_url_mapping_pattern => 'apexapp',
p_auto_rest_auth=> TRUE
);
commit;
END;
/

-- QUOTA
ALTER USER APEXAPP QUOTA UNLIMITED ON DATA;

Connect with the new user using sqlcl:

export TNS_ADMIN='/Users/shadab/Downloads/wallet_adb_free_container/tls_wallet'

sql apexapp/Demoapp_1234@my_atp_high

This is a groundbreaking release, as you can develop on ADB locally and completely offline without internet access and then sync the data to your cloud ADB instance later! We hope you enjoy it.

--

--

Shadab Mohammad
Oracle Developers

Cloud Solutions Architect@Oracle (The statements and opinions expressed here are my own & do not necessarily represent those of my employer)