2025年5月1日木曜日

Ubuntu 20.04のdockerでOracle APEXを実行する

Ubuntu 20.04のdockerでOracle APEXの実行環境を構成します。Oracle CloudでUbuntu 20.04のコンピュート・インスタンスを作成して作業していますが、実際はさくらインターネットさくらのVPSおすすめ構成に含まれるDocker実行環境に構成することを想定しています。

Ubuntu 20.04にdockerおよびdocker-composeがインストールされていることが前提です。

これからの作業では、dockerのバージョンは28.1.1、docker-composeはv2.35.1を使用します。

ubuntu@ubapex:~$ docker -v

Docker version 28.1.1, build 4eba377

ubuntu@ubapex:~$ 

ubuntu@ubapex:~$ docker compose version

Docker Compose version v2.35.1

ubuntu@ubapex:~$


グループoinstall、ユーザーoracleを作成します。

sudo groupadd -g 54321 oinstall
sudo useradd -u 54321 -g 54321 -m oracle

ubuntu@ubapex:~$ sudo groupadd -g 54321 oinstall

ubuntu@ubapex:~$ sudo useradd -u 54321 -g 54321 -m oracle

ubuntu@ubapex:~$ 


ユーザーoracleでdockerを使用可能にします。

sudo usermod -aG docker oracle

ubuntu@ubapex:~$ sudo usermod -aG docker oracle

ubuntu@ubapex:~


ユーザーoracleがログインしていなくてもサービスが実行できるように、以下のコマンドを実行します。

sudo loginctl enable-linger 54321

ubuntu@ubapex:~$ sudo loginctl enable-linger 54321

ubuntu@ubapex:~$ 


ユーザーoracleに切り替えて作業します。

sudo su - oracle

ubuntu@ubapex:~$ sudo su - oracle

$ 


あらかじめ、Oracle Database 23ai Freeのコンテナ・イメージをダウンロードします。

docker pull container-registry.oracle.com/database/free:latest

$ docker pull container-registry.oracle.com/database/free:latest

latest: Pulling from database/free

bc2da41e3d7a: Pull complete 

45946172daf4: Pull complete 

267aca2af8b5: Pull complete 

e75c46a944c1: Pull complete 

8fa9d70719ed: Pull complete 

98c750596418: Pull complete 

8768e23f2b25: Pull complete 

9e5951d51d8d: Pull complete 

f22aa7216fae: Pull complete 

e63d4fa6a272: Pull complete 

62a01ec99fe6: Pull complete 

594d5b772601: Pull complete 

e37163167ac7: Pull complete 

a929d2ad7ddf: Pull complete 

050ccaa83ceb: Pull complete 

aaeae0478ed7: Pull complete 

614b5a826d89: Pull complete 

dcabeeccf7cf: Pull complete 

68a2849e54ba: Pull complete 

b775cdac78fd: Pull complete 

c7a80918041e: Pull complete 

Digest: sha256:5c5b8d8499c4319f75555f51e4ec382c4ff98005c4e160adbfbf0bba2fe4331e

Status: Downloaded newer image for container-registry.oracle.com/database/free:latest

container-registry.oracle.com/database/free:latest

$ 


Oracle REST Data Servicesのコンテナ・イメージをダウンロードします。

docker pull container-registry.oracle.com/database/ords:latest

$ docker pull container-registry.oracle.com/database/ords:latest

latest: Pulling from database/ords

ac06ceafe5b9: Pull complete 

ada6a46d3df6: Pull complete 

1ebd134257ee: Pull complete 

da6e8ccba81d: Pull complete 

b694ec42ef2c: Pull complete 

Digest: sha256:48d6cf170e6ad4fed795b16af8dd592bdf4528ee9723f98b9804c2a892c20c46

Status: Downloaded newer image for container-registry.oracle.com/database/ords:latest

container-registry.oracle.com/database/ords:latest

$ 


Oracle APEXの最新のアーカイブをダウンロードします。

curl -OL https://download.oracle.com/otn_software/apex/apex-latest.zip

$ curl -OL https://download.oracle.com/otn_software/apex/apex-latest.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100  289M  100  289M    0     0  80.7M      0  0:00:03  0:00:03 --:--:-- 80.7M

$ 


ダウンロードしたzipファイルを解凍します。

unzip apex-latest.zip

$ unzip apex-latest.zip

Archive:  apex-latest.zip

  inflating: META-INF/MANIFEST.MF    

  inflating: META-INF/ORACLE_C.SF    

  inflating: META-INF/ORACLE_C.RSA   

   creating: apex/

  inflating: apex/apex_rest_config.sql  

  inflating: apex/apex_rest_config_cdb.sql  

  inflating: apex/apex_rest_config_core.sql  

  inflating: apex/apex_rest_config_nocdb.sql  

  inflating: apex/apexins.sql        

  inflating: apex/apexins1.sql       

  inflating: apex/apexins2.sql       

  inflating: apex/apexins3.sql       

  inflating: apex/apexins_adb.sql 


[中略]


  inflating: apex/utilities/debug/d2.sql  

  inflating: apex/utilities/debug/ds.sql  

   creating: apex/utilities/support/

  inflating: apex/utilities/support/apex_verify.sql  

$    


ディレクトリ/home/oracle/ords_config/home/oracle/oradataを作成します。

mkdir ords_config oradata

$ mkdir ords_config oradata

$ 


以下の内容でdocker-compose.ymlを作成します。Oracle DatabaseのSYSのパスワードがoracleと決め打ちで設定されている部分は、変更することが望ましいです。

services:
db23:
hostname: database
image: container-registry.oracle.com/database/free:latest
privileged: true
environment:
- ORACLE_PDB=FREEPDB1
- ORACLE_PWD=oracle
- DBHOST=database
ports:
- 1521:1521
volumes:
- /home/oracle/oradata:/opt/oracle/oradata
- /home/oracle/apex:/home/oracle/apex
ords-node1:
hostname: ords-node
image: container-registry.oracle.com/database/ords:latest
privileged: true
environment:
- DBSERVICENAME=FREEPDB1
- DBHOST=database
- DBPORT=1521
- ORACLE_PWD=oracle
ports:
- 80:8080
- 443:8443
- 27017:27017
volumes:
- /home/oracle/ords_config:/etc/ords/config
- /home/oracle/apex:/opt/oracle/apex
depends_on:
db23:
condition: service_healthy

$ vi docker-compose.yml

$ ls

META-INF  apex apex-latest.zip  docker-compose.yml  oradata  ords_config

$ pwd 

/home/oracle

$ 


docker composeを実行します。

docker compose up -d

$ docker compose up -d

[+] Running 2/3

  Network oracle_default         Created                                      0.0s 

  Container oracle-db23-1        Waiting                                     43.6s 

  Container oracle-ords-node1-1  Created                                      0.1s 



別ターミナルで実行状況を確認します。最初にコンテナoracle-db23-1でOracle Databaseの構成が実行されているため、ある程度の時間がかかります。データベース・ファイルなどは/opt/oracle/oradataにマウントしている/home/oracle/oradata以下に作成されます。この内容は永続するため、次回のコンテナ作成時はデータベースの構成はスキップされます。

docker logs -f oracle-db23-1

$ docker logs -f oracle-db23-1

Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:

Confirm the password:

Configuring Oracle Listener.

Listener configuration succeeded.

Configuring Oracle Database FREE.

Enter SYS user password: 

*********

Enter SYSTEM user password: 

*********

Enter PDBADMIN User Password: 

******

Prepare for db operation

7% complete

Copying database files



以下のようにDATABASE IS READY TO USE!と表示されると、データベースとしては構成完了です。

The Oracle base remains unchanged with value /opt/oracle

#########################

DATABASE IS READY TO USE!

#########################

The following output is now a tail of the alert.log:

2025-05-01T09:08:34.065354+00:00

FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN

Completed: Pluggable database FREEPDB1 opened read write 

Completed: ALTER DATABASE OPEN

2025-05-01T09:08:34.586923+00:00

===========================================================

Dumping current patch information

===========================================================

No patches have been applied

===========================================================

2025-05-01T09:08:53.390704+00:00

FREEPDB1(3):Resize operation completed for file# 12, fname /opt/oracle/oradata/FREE/FREEPDB1/system01.dbf, old size 286720K, new size 296960K

FREEPDB1(3):Resize operation completed for file# 15, fname /opt/oracle/oradata/FREE/FREEPDB1/users01.dbf, old size 7168K, new size 73728K

2025-05-01T09:09:20.492466+00:00


続いてOracle REST Data Servicesの構成が始まります。こちらもログを確認します。

docker logs -f oracle-ords-node1-1

/opt/oracle/apexにAPEXのインストール・イメージをマウントしているため、ORDSの初回起動時にデータベースにOracle APEXのインストールが行われます。この処理もある程度時間がかかります。

$ docker logs -f oracle-ords-node1-1 

INFO : Testing your connection variables.

INFO : Database connection established.

INFO : The Oracle REST Data Services are not installed on your database.

INFO : Installing The Oracle REST Data Services 25.1.0.

INFO : The Oracle REST Data Services 25.1.0 has been installed correctly on your database.

INFO : The container found Oracle APEX version 24.2.0 in the mounted volume.

INFO : Installing Oracle APEX on your DB, please be patient.



以下のように表示されたら、ORDSの構成は完了です。

2025-05-01T09:13:51.375Z WARNING     *** jdbc.MaxLimit in configuration |default|lo| is using a value of 10, this setting may not be sized adequately for a production environment ***

2025-05-01T09:13:51.625Z INFO        


Mapped local pools from /etc/ords/config/databases:

  /ords/                              => default                        => VALID     



2025-05-01T09:13:51.659Z INFO        Oracle REST Data Services initialized

Oracle REST Data Services version : 25.1.0.r1001652

Oracle REST Data Services server info: jetty/12.0.13

Oracle REST Data Services java info: Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (build: 21.0.2+13-LTS-jvmci-23.1-b30 mixed mode, sharing)


2025-05-01T09:13:51.697Z INFO        CursorMonitor 1

2025-05-01T09:13:51.697Z INFO        RequestMonitor 1

2025-05-01T09:13:51.697Z INFO        TransactionMonitor 1

2025-05-01T09:13:51.697Z INFO        AccessLogMonitor 1 0

2025-05-01T09:13:51.698Z INFO        WatchdogMonitor 1



これでOracle APEXの構成は完了していますが、日本語リソースがインストールされていません。

http://IPアドレス/ords/apex


日本語リソースの追加とOracle APEXの管理者パスワードの設定を行います。

docker exec -it oracle-db23-1 sh

$ docker compose up -d

[+] Running 3/3

  Network oracle_default         Created                                                   0.0s 

  Container oracle-db23-1        Healthy                                                 206.7s 

  Container oracle-ords-node1-1  Started                                                 206.8s 

$ docker exec -it oracle-db23-1 sh

sh-4.4$ 


日本語リソースをロードします。

cd apex
export NLS_LANG=American_America.AL32UTF8
sqlplus sys/oracle@localhost/freepdb1 as sysdba
@load_trans JAPANESE

sh-4.4$ cd apex

sh-4.4$ export NLS_LANG=American_America.AL32UTF8

sh-4.4$ sqlplus sys/oracle@localhost/freepdb1 as sysdba


SQL*Plus: Release 23.0.0.0.0 - Production on Thu May 1 10:04:44 2025

Version 23.7.0.25.01


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



Connected to:

Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.7.0.25.01


SQL> @load_trans JAPANESE


PL/SQL procedure successfully completed.


Installing Oracle APEX translation - JAPANESE


. ORACLE

.

. Oracle APEX Hosted Development Service Installation.

..............................................................


PL/SQL procedure successfully completed.



PL/SQL procedure successfully completed.


--application/set_environment

API Last Extended:20241130

Your Current Version:20241130

This import is compatible with version: 20241130

COMPATIBLE (You should be able to run this import without issues.)

ID offset during import: 0

New ID offset for application: 0

APPLICATION 4420 - Oracle APEX Builder, Wizard Messages and Native Plug-Ins

--application/delete_application

--application/create_application

--application/user_interfaces

--application/shared_components/navigation/lists/spotlight_custom_entries_global

--application/shared_components/navigation/lists/spotlight_custom_entries_app_level

--application/shared_components/navigation/lists/spotlight_custom_entries_page_designer

--application/shared_components/navigation/listentry

--application/plugin_settings

--application/shared_components/navigation/navigation_bar

--application/shared_components/logic/application_settings

--application/shared_components/navigation/tabs/standard

--application/shared_components/navigation/tabs/parent

--application/pages/page_groups


[中略]


--application/pages/page_00203

--application/pages/page_00204

--application/pages/page_00205

--application/pages/page_00206

--application/deployment/definition

--application/deployment/checks

--application/deployment/buildoptions

--application/end_environment

... elapsed: 2.32 sec

...done

Adjust instance settings


PL/SQL procedure successfully completed.


SQL> 


管理者パスワードを設定します。

@apxchpwd

SQL> @apxchpwd

...set_appun.sql

================================================================================

This script can be used to change the password of an Oracle APEX

instance administrator. If the user does not yet exist, a user record will be

created.

================================================================================

Enter the administrator's username [ADMIN] 

User "ADMIN" does not yet exist and will be created.

Enter ADMIN's email [ADMIN] 

Enter ADMIN's password [] **********

Created instance administrator ADMIN.


SQL> exit

Disconnected from Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free

Version 23.7.0.25.01

sh-4.4$ 


以上でOracle APEXの環境が構築されました。

参考:

Oracle CloudのUbuntu 20.04のコンピュート・インスタンスにdockerとdocker-composeをインストールした手順です。ChatGPTに「how can I install docker and docker-compose on ubuntu 20.04?」と聞いて教えてもらいました。

コンピュート・インスタンスにはユーザーubuntuで接続して作業しています。

インストール済みのdockerなどを削除します。実際にはインストール済みのコンポーネントはありませんでした。

sudo apt-get remove docker docker-engine docker.io containerd runc

ubuntu@ubapex:~$ sudo apt-get remove docker docker-engine docker.io containerd runc

Reading package lists... Done

Building dependency tree       

Reading state information... Done

Package 'docker.io' is not installed, so not removed

E: Unable to locate package docker

E: Unable to locate package docker-engine

ubuntu@ubapex:~$ 



パッケージ・インデックスのアップデートと事前に必要なパッケージをインストールします。

sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release

ubuntu@ubapex:~$ sudo apt update

Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [128 kB]

Get:2 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [3505 kB]

Get:3 http://iad-ad-3.clouds.archive.ubuntu.com/ubuntu focal InRelease [265 kB]

Get:4 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [510 kB]

Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [14.4 kB]

Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [3626 kB]

Get:7 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [508 kB]


[中略]


ubuntu@ubapex:~$ sudo apt install -y ca-certificates curl gnupg lsb-release

Reading package lists... Done

Building dependency tree       

Reading state information... Done

lsb-release is already the newest version (11.1.0ubuntu2).

lsb-release set to manually installed.

ca-certificates is already the newest version (20240203~20.04.1).


[中略]


Setting up gnupg (2.2.19-3ubuntu2.4) ...

Processing triggers for man-db (2.9.1-1) ...

Processing triggers for install-info (6.7.0.dfsg.2-5) ...

ubuntu@ubapex:~$ 


Dockerの公式PGPキーを追加します。

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
  sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

ubuntu@ubapex:~$ sudo mkdir -p /etc/apt/keyrings

ubuntu@ubapex:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \

>   sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

ubuntu@ubapex:~$ 


ステーブル・リポジトリを設定します。

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

ubuntu@ubapex:~$ echo \

>   "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \

>   https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \

>   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

ubuntu@ubapex:~$ 


再度、パッケージ・インデックスを更新します。

sudo apt update

ubuntu@ubapex:~$ sudo apt update

Get:1 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]

Get:2 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [59.9 kB]            

Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease                                

Get:4 http://iad-ad-3.clouds.archive.ubuntu.com/ubuntu focal InRelease [265 kB]          

Hit:5 http://iad-ad-3.clouds.archive.ubuntu.com/ubuntu focal-updates InRelease

Hit:6 http://iad-ad-3.clouds.archive.ubuntu.com/ubuntu focal-backports InRelease

Fetched 382 kB in 1s (432 kB/s)

Reading package lists... Done

Building dependency tree       

Reading state information... Done

27 packages can be upgraded. Run 'apt list --upgradable' to see them.

ubuntu@ubapex:~$ 


Docker関連のパッケージをインストールします。

sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

ubuntu@ubapex:~$ sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following additional packages will be installed:

  docker-ce-rootless-extras pigz slirp4netns

Suggested packages:

  cgroupfs-mount | cgroup-lite

The following NEW packages will be installed:

  containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras

  docker-compose-plugin pigz slirp4netns

0 upgraded, 8 newly installed, 0 to remove and 27 not upgraded.

Need to get 120 MB of archives.


[中略]


Setting up docker-ce-rootless-extras (5:28.1.1-1~ubuntu.20.04~focal) ...

Setting up docker-ce (5:28.1.1-1~ubuntu.20.04~focal) ...

Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.

Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.

Processing triggers for man-db (2.9.1-1) ...

Processing triggers for systemd (245.4-4ubuntu3.24) ...

ubuntu@ubapex:~$ 


Dockerのインストールは以上で完了です。動作確認をします。

sudo docker run hello-world

ubuntu@ubapex:~$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

e6590344b1a5: Pull complete 

Digest: sha256:c41088499908a59aae84b0a49c70e86f4731e588a737f1637e73c8c09d995654

Status: Downloaded newer image for hello-world:latest


Hello from Docker!

This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:

 1. The Docker client contacted the Docker daemon.

 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

    (amd64)

 3. The Docker daemon created a new container from that image which runs the

    executable that produces the output you are currently reading.

 4. The Docker daemon streamed that output to the Docker client, which sent it

    to your terminal.


To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:

 https://hub.docker.com/


For more examples and ideas, visit:

 https://docs.docker.com/get-started/


ubuntu@ubapex:~$ 


unzipをインストールします。

sudo apt-get install unzip

ubuntu@ubapex:~$ sudo apt-get install unzip

Reading package lists... Done

Building dependency tree       

Reading state information... Done

Suggested packages:

  zip

The following NEW packages will be installed:

  unzip

0 upgraded, 1 newly installed, 0 to remove and 27 not upgraded.

Need to get 169 kB of archives.

After this operation, 593 kB of additional disk space will be used.

Get:1 http://iad-ad-3.clouds.archive.ubuntu.com/ubuntu focal-updates/main amd64 unzip amd64 6.0-25ubuntu1.2 [169 kB]

Fetched 169 kB in 0s (1074 kB/s)

Selecting previously unselected package unzip.

(Reading database ... 69070 files and directories currently installed.)

Preparing to unpack .../unzip_6.0-25ubuntu1.2_amd64.deb ...

Unpacking unzip (6.0-25ubuntu1.2) ...

Setting up unzip (6.0-25ubuntu1.2) ...

Processing triggers for mime-support (3.64ubuntu1) ...

Processing triggers for man-db (2.9.1-1) ...

ubuntu@ubapex:~$ 


これから、Oracle APEXのインストール作業に移ります。