使用 Docker 容器运行 Oracle 数据库
创始人
2024-11-04 12:09:40
0

在实际开发中,大部分时间可能都在开发、测试和验证工作,有些时候我们需要快速使用一个临时 oracle 数据库来做开发或者验证工作,而又会因为 oracle 安装麻烦而烦恼。

这种快速临时性需求,我们可以选中使用 docker 容器的方式运行一个 oracle 数据库,官方也给出了对应的镜像,包括 amd64 和 arm64 架构的都有。

启动容器

docker-compose.yml

services:   oracle:     image: container-registry.oracle.com/database/enterprise:19.3.0.0     container_name: oracledb     ports:       - 1521:1521       - 5500:5500     volumes:       - ./oracle/oradata:/opt/oracle/oradata     environment:       TZ: Asia/Shanghai       ORACLE_SID: orcl       ORACLE_PWD: oracle123456       ENABLE_ARCHIVELOG: true     logging:       driver: "json-file"       options:         max-size: "1g"         max-file: "20"  

或者直接运行脚本启动容器:

docker run -d --name oracledb \  -p 1521:1521 -p 5500:5500 \  -e ORACLE_SID=orcl \  -e ORACLE_PWD=oracle123456 \  -e ENABLE_ARCHIVELOG=true \  -v /opt/soft/oracle/oradata:/opt/oracle/oradata \ container-registry.oracle.com/database/enterprise:19.3.0.0 

注意提前创建 oradata 目录,并且为该目录设置 chmod 777 权限,否则会出现容器挂载后写入数据不正常的问题(如果是权限问题日志中会有权限问题的相关内容)。

容器环境变量更多参数说明如下:

Parameters:  --name:                 The name of the container (default: auto generated  -p:                     The port mapping of the host port to the container port.                          Two ports are exposed: 1521 (Oracle Listener), 5500 (OEM Express)  -e ORACLE_SID:          The Oracle Database SID that should be used (default:ORCLCDB)  -e ORACLE_PDB:          The Oracle Database PDB name that should be used (default: ORCLPDB1)  -e ORACLE_PWD:          The Oracle Database SYS, SYSTEM and PDBADMIN password (default: auto generated)  -e INIT_SGA_SIZE:       The total memory in MB that should be used for all SGA components (optional)  -e INIT_PGA_SIZE:       The target aggregate PGA memory in MB that should be used for all server processes attached to the instance (optional)  -e ORACLE_EDITION:      The Oracle Database Edition (enterprise/standard, default: enterprise)  -e ORACLE_CHARACTERSET: The character set to use when creating the database (default: AL32UTF8)  -e ENABLE_ARCHIVELOG:   To enable archive log mode when creating the database (default: false). Supported 19.3 onwards.  -v /opt/oracle/oradata                          The data volume to use for the database. Has to be writable by the Unix "oracle" (uid: 54321) user inside the container                          If omitted the database will not be persisted over container recreation.  -v /opt/oracle/scripts/startup | /docker-entrypoint-initdb.d/startup                          Optional: A volume with custom scripts to be run after database startup.                          For further details see the "Running scripts after setup and on                          startup" section below.  -v /opt/oracle/scripts/setup | /docker-entrypoint-initdb.d/setup                          Optional: A volume with custom scripts to be run after database setup.                          For further details see the "Running scripts after setup and on startup" section below. 

常用命令

连接到容器内SQLPlus

通过使用以下命令之一从容器中执行SQL*Plus命令,可以连接到Oracle数据库服务器:

$ docker exec -it  sqlplus / as sysdba $ docker exec -it  sqlplus sys/@ as sysdba $ docker exec -it  sqlplus system/@ $ docker exec -it  sqlplus pdbadmin/@ 

更改SYS用户的默认密码

在容器的第一次启动时,如果没有提供,将为数据库生成一个随机密码。在创建数据库并且相应的容器处于健康状态后,用户必须强制更改密码。
使用docker exec命令,通过调用容器中的setPassword.sh脚本来更改这些帐户的密码。请注意,容器必须正在运行。例如:

$ docker exec  ./setPassword.sh  

浏览器登录 Oracle EM Express

容器中的Oracle数据库还配置了Oracle Enterprise Manager Database Express(EM Express)。要访问EM Express,请使用浏览器访问以下URL:

https://localhost:5500/em/

注:其中 localhost 修改为自己实际的服务器 IP 地址。

点击链接《官方文档资料》 查阅官方资料关于容器创建后的更多详细说明。


(END)

相关内容

热门资讯

技巧辅助挂!pokermast... 技巧辅助挂!pokermaster修改器,丹东约战麻将辅助器,演示教程(有挂细节)1、点击下载安装,...
现场直击!wepokerplu... 现场直击!wepokerplus万能挂,丰城双剑新版最强高分攻略,操作教程(有挂方针)1.丰城双剑新...
插件辅助挂!wepoker有辅... 插件辅助挂!wepoker有辅助器吗,乐平包王攻略,学习教程(有挂方略)1、首先打开乐平包王攻略辅助...
据玩家消息!拱趴大菠萝辅助神器... 据玩家消息!拱趴大菠萝辅助神器,多乐跑得快辅助器,机巧教程(证实有挂)1、在拱趴大菠萝辅助神器插件功...
此事备受玩家关注!来玩app破... 此事备受玩家关注!来玩app破解版,h5能反杀吗,绝活教程(有挂详细)1、打开软件启动之后找到中间准...
值得注意的是!aapoker破... 值得注意的是!aapoker破解侠是真的吗,蜀山四川游戏修改工具,经验教程(有挂助手)1、金币登录送...
第三方辅助!wepoker脚本... 第三方辅助!wepoker脚本,广东星悦有外开挂辅助器吗,法门教程(有挂分析)广东星悦有外开挂辅助器...
此事引发广泛关注!德州透视脚本... 此事引发广泛关注!德州透视脚本,崇阳斗棋辅助脚本视频,诀窍教程(的确有挂)暗藏猫腻,小编详细说明崇阳...
黑科技辅助挂!wepoker买... 黑科技辅助挂!wepoker买脚本靠谱吗,情怀七喜游戏辅助,法门教程(有挂方法)1、每一步都需要思考...
方法辅助挂!aapoker怎么... 方法辅助挂!aapoker怎么设置提高好牌几率,蘑菇云辅助使用视频,绝活儿教程(讲解有挂)1、完成蘑...