Install Oracle 11g via Docker

此安裝方法只適用個人自行開發之用途。

JeffChang
5 min readMay 21, 2019

前置作業

電腦內已經安裝Docker。

Step1. 尋找資源檔

docker search oracle

Step2. 下載映像檔

docker pull jaspeen/oracle-11g

Step3. 去Oracle官方網站下載oracle 11g

因為要在Mac Pro中使用,故下載linux.x64_11gR2_database_1of2.ziplinux.x64_11gR2_database_2of2.zip 這兩個檔案,下載完成後,透過Terminal指令先對1of2解壓縮,再對2of2解壓縮。

unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

解壓縮後結構如下:

/Users/yuan/
└─oracle11g
└─database
├─doc
├─install
├─response
├─rpm
├─sshsetup
├─stage
├─runInstaller
└─welcome.html

注意事項

會需要解壓縮成這個結構有原因的,看一下jaspeen/oracle-11g提供的安裝Script

#!/usr/bin/env bash
set -e
source /assets/colorecho

trap "echo_red '******* ERROR: Something went wrong.'; exit 1" SIGTERM
trap "echo_red '******* Caught SIGINT signal. Stopping...'; exit 2" SIGINT

if [ ! -d "/install/database" ]; then
echo_red "Installation files not found. Unzip installation files into mounted(/install) folder"
exit 1
fi

echo_yellow "Installing Oracle Database 11g"

su oracle -c "/install/database/runInstaller -silent -ignorePrereq -waitforcompletion -responseFile /assets/db_install.rsp"
/opt/oracle/oraInventory/orainstRoot.sh
/opt/oracle/app/product/11.2.0/dbhome_1/root.sh

從Script中可以看到他會讀取/install/database 的資料夾,如果不存在會回傳提示訊息Installation files not found. Unzip installation files into mounted(/install) folder

Step4. 執行Image安裝oracle

docker run --privileged --name oracle11g -p 1521:1521 -v /Users/yuan/oracle11g/database:/install/database jaspeen/oracle-11g// --privileged 是給予權限,安裝oracle時可能會需要root權限
// -v 將路徑掛載到另一個指令路徑

這裡會需要安裝一點時間,完成時會看到100%的字樣。安裝到這邊就算完成了,接下來要進行設定。

Step5. 設定oracle

首先我們要先連進容器

docker exec -it oracle11g /bin/bash

連線成功後,切換成oracle使用者

[root@41ac96c4ba62 /]# su — oracle

透過sqlplus 登入

sqlplus / as sysdba

就可以進行建立帳號、設定權限。

完成之後就可以在本機上面使用囉!

--

--

JeffChang
JeffChang

Written by JeffChang

Java Backend Engineer In DDIM.

No responses yet