阅读量: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 <oracle-db> sqlplus / as sysdba $ docker exec -it <oracle-db> sqlplus sys/<your_password>@<your_SID> as sysdba $ docker exec -it <oracle-db> sqlplus system/<your_password>@<your_SID> $ docker exec -it <oracle-db> sqlplus pdbadmin/<your_password>@<your_PDBname>
更改SYS用户的默认密码
在容器的第一次启动时,如果没有提供,将为数据库生成一个随机密码。在创建数据库并且相应的容器处于健康状态后,用户必须强制更改密码。
使用docker exec命令,通过调用容器中的setPassword.sh脚本来更改这些帐户的密码。请注意,容器必须正在运行。例如:
$ docker exec <oracle-db> ./setPassword.sh <your_password>
浏览器登录 Oracle EM Express
容器中的Oracle数据库还配置了Oracle Enterprise Manager Database Express(EM Express)。要访问EM Express,请使用浏览器访问以下URL:
注:其中 localhost 修改为自己实际的服务器 IP 地址。
点击链接《官方文档资料》 查阅官方资料关于容器创建后的更多详细说明。
(END)