Dockerfile制作Oracle19c镜像
Dockerfile文件
cat > Dockerfile << 'EOF'
# 使用 Oracle Linux 8 作为基础镜像
FROM oraclelinux:8
# 复制 Oracle 19c 安装包
COPY oracle-database-ee-19c-1.0-1.x86_64.rpm /tmp/
# 安装 Oracle 19c 数据库和依赖
RUN yum localinstall -y /tmp/oracle-database-ee-19c-1.0-1.x86_64.rpm && \
yum -y clean all && \
rm -f /tmp/oracle-database-ee-19c-1.0-1.x86_64.rpm
# 初始化数据库脚本
COPY Instance_initialization.sh /opt/oracle/scripts/Instance_initialization.sh
RUN chmod +x /opt/oracle/scripts/Instance_initialization.sh
# 切换Oracle
USER oracle
# 设置环境变量
ENV ORACLE_BASE=/opt/oracle \
ORACLE_HOME=/opt/oracle/product/19c/dbhome_1 \
ORACLE_VERSION=19.3.0 \
PATH=/opt/oracle/product/19c/dbhome_1/bin:$PATH
# 创建目录用于挂载持久化表空间和 dump 文件
RUN mkdir -p $ORACLE_BASE/oradata && \
mkdir -p $ORACLE_BASE/admin/dump
# 暴露端口
EXPOSE 1521 5500
# 配置数据库启动时的命令
CMD ["/usr/bin/sh /opt/oracle/scripts/Instance_initialization.sh"]
EOF
初始化脚本
vim Instance_initialization.sh
#!/bin/bash
# 设置数据库环境变量
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=${ORACLE_SID:-orcl}
export ORACLE_PWD=${ORACLE_PWD:-oracle}
export DB_USER=${DB_USER:-oracleuser}
export DB_PWD=${DB_PWD:-oraclepwd}
# 创建监听
netca -silent -responsefile $ORACLE_HOME/assistants/netca/netca.rsp
# 创建实例配置文件--dbca.rsp
cat > $ORACLE_BASE/scripts/dbca.rsp << EOF
responseFileVersion=$ORACLE_HOME/assistants/rspfmt_dbca_response_schema_v19.0.0
gdbName=$ORACLE_SID
sid=$ORACLE_SID
databaseConfigType=SI
templateName=General_Purpose.dbc
sysPassword=$ORACLE_PWD
systemPassword=$ORACLE_PWD
datafileDestination=$ORACLE_HOME/oradata
recoveryAreaDestination=$ORACLE_HOME/flash_recovery_area
characterSet=ZHS16GBK
nationalCharacterSet=AL16UTF16
totalMemory=4096
listeners=LISTENER
sampleSchema=true
databaseType=OLTP
emConfiguration=NONE
EOF
# 创建实例
dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile $ORACLE_BASE/scripts/dbca.rsp
# 查看监听
lsnrctl status
# 创建普通用户并授权远程登录
sqlplus / as sysdba <<EOF
CREATE USER $DB_USER IDENTIFIED BY $DB_PWD;
GRANT CREATE SESSION TO $DB_USER;
EXIT;
EOF
# 保持容器运行
tail -f /dev/null
totalMemory: 修改为实际内存值
制作镜像
docker build -t oracle-19c .
docker-compose文件
version: '3'
services:
oracle-db:
image: oracle-19c:latest
container_name: oracle19c
user: oracle
environment:
- ORACLE_SID=orcl
- ORACLE_PWD=oracle#2012
- DB_USER=orcl
- DB_PWD=orcl#2012
ports:
- "1521:1521"
- "5500:5500"
volumes:
- ./oradata:/opt/oracle/oradata # 数据持久化
- ./dump:/opt/oracle/admin/dump # DUMP 文件持久化
networks:
- oracle-network
restart: unless-stopped
networks:
oracle-network:
driver: bridge