oracle製作docker映象

slnngk發表於2024-09-12

1.下載官方的 dockerfile 構建包
下載地址:
https://github.com/oracle/docker-images

2.下載oracle安裝包
我這裡下載的是19C
LINUX.X64_193000_db_home.zip

最後下載的2個檔案如下:

[root@master soft]# ls -lrt
total 2991400
-rw-r--r-- 1 root root 3059705302 Sep 13  2020 LINUX.X64_193000_db_home.zip
-rw-r--r-- 1 root root    3482131 Sep 12 09:08 docker-images-main.zip

3.解壓docker-images-main.zip
[root@master soft]# unzip docker-images-main.zip
進入 ./docker-images-main/OracleDatabase/SingleInstance/dockerfiles

[root@master soft]# cd ./docker-images-main/OracleDatabase/SingleInstance/dockerfiles
[root@master dockerfiles]# ls
11.2.0.2 12.1.0.2 12.2.0.1 18.3.0 18.4.0 19.3.0 21.3.0 23.5.0 buildContainerImage.sh
[root@master dockerfiles]# ls -1
11.2.0.2
12.1.0.2
12.2.0.1
18.3.0
18.4.0
19.3.0
21.3.0
23.5.0
buildContainerImage.sh

根據需要進入對應的版本目錄(本例 19.3.0)
[root@master dockerfiles]# cd 19.3.0
將下載的 Oracle zip 附件複製到該目錄中

[root@master 19.3.0]# ls -1
checkDBStatus.sh
checkSpace.sh
Checksum.ee
Checksum.ee.arm64
Checksum.se2
configTcps.sh
createDB.sh
createObserver.sh
dbca.rsp.tmpl
db_inst.rsp
Dockerfile
installDBBinaries.sh
LINUX.X64_193000_db_home.zip
relinkOracleBinary.sh
runOracle.sh
runUserScripts.sh
setPassword.sh
setupLinuxEnv.sh
startDB.sh

4.構建DOCKER映象
[root@master dockerfiles]# cd /soft/docker-images-main/OracleDatabase/SingleInstance/dockerfiles
[root@master dockerfiles]#./buildContainerImage.sh -v 19.3.0 -e

我這裡提示如下錯誤,提示空間不足
 > [base 4/4] RUN chmod ug+x /opt/install/*.sh &&     sync &&     /opt/install/checkSpace.sh &&     /opt/install/setupLinuxEnv.sh &&     rm -rf /opt/install:                                                                             
0.551 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!               
0.551 checkSpace.sh: ERROR - There is not enough space available in the container.
0.551 checkSpace.sh: The container needs at least 18 GB, but only 12 GB are available.
0.551 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
------

磁碟擴容後繼續執行如上命令,完成以後使用 docker images 可以看到已經有成功構建的 Oracle 19c映象了,同時構建了Oracle Linux 7的基礎映象,如下:

[root@master dockerfiles]# docker images
REPOSITORY                                         TAG              IMAGE ID       CREATED         SIZE
oracle/database                                    19.3.0-ee        f9f2615a4afc   2 minutes ago   6.54GB

####################執行 Oracle 容器##########################

1.建立oracle使用者和組
注意oracle使用者的id 和組id必須跟docker映象裡的一致
groupadd -g 54321 oinstall
groupadd -g 54322 dba
groupadd -g 54323 oper
useradd -u 54321 -g oinstall -G dba,oper -d /home/oracle -s /bin/bash -c "Oracle Software Owner" oracle
echo "oracle" | passwd --stdin oracle

容器裡的ID
[root@master docker]# docker exec -it oracle19c /bin/bash

bash-4.2$ id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)

2.切換到 oracle 使用者,然後建立資料目錄
su - oracle
mkdir -p /home/oracle/oradata/oracle19c
chown oracle:oinstall /home/oracle/oradata/oracle19c

3.啟動 oracle 容器
su - root
[root@master dockerfiles]#
docker run -itd --name oracle19c -p 1521:1521 -p 5500:5500 -v /home/oracle/oradata/oracle19c:/opt/oracle/oradata oracle/database:19.3.0-ee

4.密碼
容器啟動後,透過 docker logs -f oracle19c 檢視日誌,能看到自動生成的SYS等使用者的密碼,如下示例
docker exec -it oracle19c /bin/bash

修改密碼為oracle
[root@master dockerfiles]# docker exec oracle19c ./setPassword.sh oralce

5.登入驗證
預設以oracle賬號登入
docker exec -it oracle19c /bin/bash

以root賬號登入
docker exec -it --user root oracle19c bash
可以安裝which yum vi
yum install which
yum install yum
yum install vi

6.自定義sid
docker run -itd --name oracle19c \
-p 1521:1521 -p 5500:5500 \
-e ORACLE_SID=ORCL \
-e ORACLE_PDB=MYPDB1 \
-v /home/oracle/oradata/oracle19c:/opt/oracle/oradata \
oracle/database:19.3.0-ee

相關文章