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
标签:oracle19c,master,oracle,镜像,docker,root,dockerfiles From: https://www.cnblogs.com/hxlasky/p/18410567