1. 문제 정의
로컬 환경에서 oracle을 실행할 일이 생겼습니다.
하지만 Oracle의 경우 공식적인 oracle image를 제공하지 않기 때문에 oracle 로컬 구축에 어려움이 있습니다.
심지어 apple sillicon의 경우 docker-desktop을 이용해서는 컨테이너를 실행할 수 없습니다.
2. 해결 방법
2-1 colima 설치
가장 많이 나오는 해결 방법입니다.
oracle을 x86-64 환경에서 실행할 수 있도록 docker 의 새로운 context를 생성해줍니다.
해당 방법은 다른 블로그 글이 많이 때문에 생략하도록 하겠습니다.
2-2 oracle linux를 이용한 oracle db 생성
해결방법은 oracle 깃헙을 통해서 찾을 수 있었습니다.
oracle 내부 repository를 둘러보다 oracle dba를 발견하였고, 해결방법을 찾을 수 있었습니다.
우선 아래 repository를 clone 해줍니다.
git clone <https://github.com/oraclesean/cloud-native-oracle.git>
clone한 프로젝트 내부에서 아래의 쉘 스크립트를 실행해줍니다.
./buildDBImage.sh
아래 로그와 같이 뜬다면 성공입니다. (필자 기준 2분정도 소요됐습니다.)
# ./buildDBImage.sh
[+] Building 51.6s (8/8) FINISHED docker:desktop-linux
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile.oraclelinux.202307031409.jTxd 0.0s
=> => transferring dockerfile: 1.55kB 0.0s
=> [internal] load metadata for docker.io/library/oraclelinux:8-slim 1.3s
=> [internal] load build context 0.0s
=> => transferring context: 45.06kB 0.0s
=> CACHED [1/3] FROM docker.io/library/oraclelinux:8-slim@sha256:0226d80b442e93f977753e1d 0.0s
=> => resolve docker.io/library/oraclelinux:8-slim@sha256:0226d80b442e93f977753e1d269c8ec 0.0s
=> [2/3] COPY manageOracle.sh /opt/scripts/ 0.0s
=> [3/3] RUN chmod ug+x /opt/scripts/manageOracle.sh && /opt/scripts/manageOracle.sh 48.7s
=> exporting to image 1.5s
=> => exporting layers 1.5s
=> => writing image sha256:6cdb5ddeb9d8ffbfcaeba0cb1fad0c003dbffc3cd77b204a8ddc60292e184b 0.0s
=> => naming to docker.io/library/oraclelinux:8-slim-19c 0.0s
oraclelinux:8-slim-19c
[+] Building 193.8s (21/21) FINISHED docker:desktop-linux
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile.db.202307031410.NUni 0.0s
=> => transferring dockerfile: 5.11kB 0.0s
=> resolve image config for docker.io/docker/dockerfile:1.4 0.9s
=> CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531bd80fb0a858632727c 0.0s
=> [internal] load metadata for docker.io/library/oraclelinux:8-slim-19c 0.0s
=> [db 1/6] FROM docker.io/library/oraclelinux:8-slim-19c 0.0s
=> [internal] load build context 38.5s
=> => transferring context: 2.42GB 38.5s
=> [db 2/6] COPY --chown=oracle:oinstall manageOracle.sh /opt/scripts/ 0.6s
=> [stage-1 2/9] COPY --chown=oracle:oinstall ./config/dbca.* /opt/install/ 0.6s
=> [stage-1 3/9] COPY --chown=oracle:oinstall ./config/*.tmpl /opt/install/ 0.0s
=> [db 3/6] COPY --chown=oracle:oinstall ./config/inst.* /opt/install/ 0.0s
=> [db 4/6] COPY --chown=oracle:oinstall ./config/manifest.* /opt/install/ 0.0s
=> [stage-1 4/9] COPY --chown=oracle:oinstall manageOracle.sh /opt/scripts/ 0.0s
=> [db 5/6] COPY --chown=oracle:oinstall ./database/ /opt/install/ 6.3s
=> [db 6/6] RUN chmod ug+x /opt/scripts/manageOracle.sh && /opt/scripts/manageOracl 98.9s
=> [stage-1 5/9] COPY --chown=oracle:oinstall --from=db /u01/app/oraInventory /u01/app/o 0.0s
=> [stage-1 6/9] COPY --chown=oracle:oinstall --from=db /u01/app/oracle /u01/app/oracle 18.6s
=> [stage-1 7/9] COPY --chown=oracle:oinstall --from=db /opt/oracle/oradata /opt/orac 0.0s
=> [stage-1 8/9] RUN /opt/scripts/manageOracle.sh -R 0.5s
=> [stage-1 9/9] WORKDIR /home/oracle 0.0s
=> exporting to image 17.6s
=> => exporting layers 17.6s
=> => writing image sha256:4874efbbfe1cfb271e314ed8d6d0773e5a270d1a0b789861af76e59d4b6f82 0.0s
=> => naming to docker.io/oraclesean/db:19.19-EE 0.0s
2-2 oracle 실행하기
이미지 빌드가 끝나면 간단히 실행할 수 있습니다.
docker run -d --name oracle -p 1521:1521 ${이미지}
이렇게 실행할 경우 아래와 같은 에러를 만날 수 있습니다.
2024-05-09 15:10:27 [FATAL] [DBT-06006] Unable to create directory: (/u02/app/oracle/oradata/test/).
2024-05-09 15:10:27 CAUSE: Proper permissions are not granted to create the directory or there is no space left in the volume.
2024-05-09 15:10:27 [FATAL] [DBT-06006] Unable to create directory: (/u03/app/oracle).
2024-05-09 15:10:27 CAUSE: Proper permissions are not granted to create the directory or there is no space left in the volume.
2024-05-09 15:10:28 alter pluggable database all open
2024-05-09 15:10:28 *
2024-05-09 15:10:28 ERROR at line 1:
2024-05-09 15:10:28 ORA-01034: ORACLE not available
2024-05-09 15:10:28 Process ID: 0
2024-05-09 15:10:28 Session ID: 0 Serial number: 0
2024-05-09 15:10:28
2024-05-09 15:10:28
2024-05-09 15:10:28 alter pluggable database all save state
2024-05-09 15:10:28 *
2024-05-09 15:10:28 ERROR at line 1:
2024-05-09 15:10:28 ORA-01034: ORACLE not available
2024-05-09 15:10:28 Process ID: 0
2024-05-09 15:10:28 Session ID: 0 Serial number: 0
2024-05-09 15:10:28
2024-05-09 15:10:28
2024-05-09 15:10:28
2024-05-09 15:10:28 # ----------------------------------------------------------------------------------------------- #
2024-05-09 15:10:28 runDBCA: DBCA complete at 2024-05-09 05:10:28
2024-05-09 15:10:28 # ----------------------------------------------------------------------------------------------- #
2024-05-09 15:10:29 ERROR: Cannot locate /home/oracle/bin/sqlplus
2024-05-09 15:10:29 Exiting...
2024-05-09 15:10:29 WARNING: Database setup for test was unsuccessful.
2024-05-09 15:10:29 WARNING: Check log output for additional information.
2024-05-09 15:10:29
2024-05-09 15:10:29 # ----------------------------------------------------------------------------------------------- #
2024-05-09 15:10:29 Tailing alert_test.log:
2024-05-09 15:10:26 mkdir: cannot create directory '/u03/app/oracle/fast_recovery_area': Permission denied
2024-05-09 15:10:27 cat: /u01/app/oracle/cfgtoollogs/dbca/test/test.log: No such file or directory
2024-05-09 15:10:27 cat: /u01/app/oracle/cfgtoollogs/dbca/test.log: No such file or directory
2024-05-09 15:10:27 cat: /u01/app/oracle/cfgtoollogs/dbca/test/testPDB1/test.log: No such file or directory
2024-05-09 15:10:28 mkdir: cannot create directory '/u02/app/oracle/oradata/dbconfig': Permission denied
2024-05-09 15:10:29 /opt/scripts/manageOracle.sh: line 934: /home/oracle/bin/sqlplus: No such file or directory
2024-05-09 15:10:29 tail: cannot open '/u01/app/oracle/diag/rdbms/*/*/trace/alert*.log' for reading: No such file or directory
2024-05-09 15:10:29 tail: no files remaining
oracle 저장 디렉토리를 마운트하지 않아서 발생한 문제입니다.
디렉토리를 로컬 mac 에서 생성해 준 후 다음과 같이 실행해줍니다.
docker run -d --name oracle -e ORACLE_PWD=password123 \\
-p 1521:1521 \\
-v /사용자_경로/data/oracle/oradata:/u02/app/oracle/oradata \\
-v /사용자_경로/data/oracle/diag:/u01/app/oracle/diag \\
-v /사용자_경로/data/oracle/audit:/u01/app/oracle/admin \\
-v /사용자_경로/oracle/reco:/u03/app/oracle \\
-v /사용자_경로/data/oracle/scripts:/scripts \\
${ORACLE_DB_IMAGE}
로그를 출력해보면 다음과 같다.
oracle이 정상적으로 실행되기까지 대략 10여분 정도가 소요됐다.
# docker logs -f $CONTAINER_NAME
# ----------------------------------------------------------------------------------------------- #
Oracle password for SYS, SYSTEM and PDBADMIN: HB#K_xhkwM_O10
# ----------------------------------------------------------------------------------------------- #
# ----------------------------------------------------------------------------------------------- #
runDBCA: Running DBCA for database ARM at 2023-07-03 20:16:05
# ----------------------------------------------------------------------------------------------- #
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 03-JUL-2023 20:16:05
Copyright (c) 1991, 2023, Oracle. All rights reserved.
Starting /u01/app/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /u01/app/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/96bb65f2a1b7/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 03-JUL-2023 20:16:06
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/96bb65f2a1b7/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Services Summary...
Service "ARM" has 1 instance(s).
Instance "ARM", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
# ----------------------------------------------------------------------------------------------- #
runDBCA: Creating container database ARM and 3 pluggable database(s) with name ARMPDB at 2023-07-03 20:16:06
# ----------------------------------------------------------------------------------------------- #
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
63% complete
68% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
/u01/app/oracle/cfgtoollogs/dbca/ARM.
Database Information:
Global Database Name:ARM
System Identifier(SID):ARM
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ARM/ARM.log" for further details.
Pluggable database altered.
Pluggable database altered.
# ----------------------------------------------------------------------------------------------- #
runDBCA: DBCA complete at 2023-07-03 20:26:37
# ----------------------------------------------------------------------------------------------- #
# ----------------------------------------------------------------------------------------------- #
Database ARM with unique name ARM is open and available.
# ----------------------------------------------------------------------------------------------- #
# ----------------------------------------------------------------------------------------------- #
Tailing alert_ARM.log:
2023-07-03T20:26:36.493063+00:00
ARMPDB3(5):CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/opt/oracle/oradata/ARM/ARMPDB3/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
ARMPDB3(5):Completed: CREATE SMALLFILE TABLESPACE "USERS" LOGGING DATAFILE '/opt/oracle/oradata/ARM/ARMPDB3/users01.dbf' SIZE 5M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
ARMPDB3(5):ALTER DATABASE DEFAULT TABLESPACE "USERS"
ARMPDB3(5):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
2023-07-03T20:26:37.882084+00:00
alter pluggable database all open
Completed: alter pluggable database all open
alter pluggable database all save state
Completed: alter pluggable database all save state