Oracle XE Database 21c服务器Docker镜像包含预构建的数据库,因此启动时间非常快。快速启动在CI/CD场景中非常有用。要启动Oracle数据库服务器实例,请运行以下命令,其中<container_name>是容器名称:
$ docker run -d --name <container_name> container-registry.oracle.com/database/express:21.3.0-xe
容器启动时,SYS、SYSTEM和PDBADMIN用户将使用随机密码。这称为默认密码。
[!NOTE]
- 在本文档中,尖括号
< >内的文字表示代码行中的变量。- 要更改默认密码,请参见:"更改SYS用户的默认密码"
- 要了解高级用例,请参见:"自定义配置"
当docker ps输出的STATUS字段显示(healthy)时,Oracle数据库服务器即准备就绪。
为便于自定义配置,Oracle数据库服务器容器提供了启动容器时可使用的配置参数。例如,以下是支持所有自定义配置的详细docker run命令:
docker run --name <container_name> \
-p <host_port>:1521 -p <host_port>:5500 \
-e ORACLE_PWD=<your_password> \
-e ORACLE_CHARACTERSET=<your_character_set> \
-v [<host_volume_name>|<host_directory>]:/opt/oracle/oradata \
container-registry.oracle.com/database/express:21.3.0-xe
参数说明:
--name: 容器名称(默认:自动生成)-p: 主机端口到容器端口的映射。暴露两个端口:1521(Oracle监听器)、5500(EM Express)-e ORACLE_PWD: Oracle数据库SYS、SYSTEM和PDB_ADMIN用户的密码(默认:自动生成)-e ORACLE_CHARACTERSET: 创建数据库时使用的字符集(默认:AL32UTF8)-v <host_volume_name>:/opt/oracle/oradata: 用于数据库的数据卷。必须可由容器内的Unix "oracle"(uid:54321)用户写入!如果省略,数据库将不会在容器重建后持久化。-v <host_directory>:/opt/oracle/scripts/startup | /docker-entrypoint-initdb.d/startup: 可选:包含数据库启动后要运行的自定义脚本的卷。有关详细信息,请参见下文"在设置后和启动时运行脚本"部分。-v <host_directory>:/opt/oracle/scripts/setup | /docker-entrypoint-initdb.d/setup: 可选:包含数据库设置后要运行的自定义脚本的卷。有关详细信息,请参见下文"在设置后和启动时运行脚本"部分。支持的配置选项:
SYS、SYSTEM和PDBADMIN用户的密码。此参数为可选,默认值随机生成。[!NOTE]
如果使用此选项,密码将作为容器环境变量可见,且后续无法更改。
[!NOTE]
请注意,此参数仅在创建新数据库时设置字符集,即运行镜像时使用
-v选项挂载主机系统目录(请参阅"挂载Docker卷/主机目录以实现数据库持久化"部分)。
Secret是一种向容器传递安全文本字符串(如ssh密钥或密码)的工具。要安全地指定SYS、SYSTEM和PDBADMIN用户的密码,请创建名为oracle_pwd的secret。命令如下:echo "<your_password>" | podman secret create oracle_pwd -
创建secret后,使用以下命令安全地启动容器:
podman run --name=<container_name> --secret=oracle_pwd container-registry.oracle.com/database/express:21.3.0-xe
/opt/oracle/oradata位置。这两个选项的区别如下:
/opt/oracle/oradata位置挂载Docker卷,则该卷会预填充镜像中已存在的数据文件。在这种情况下,启动速度非常快,类似于不挂载卷启动镜像。这些数据文件存在于镜像中,以实现数据库的快速启动。要将Docker卷用作数据卷,请运行以下命令:$ docker run -d --name <container_name> -v <host_volume_name>:/opt/oracle/oradata container-registry.oracle.com/database/express:21.3.0-xe
/opt/oracle/oradata位置挂载主机系统目录,则该位置已存在的数据文件将被覆盖,并且将开始全新的数据库设置。全新设置数据库需要相当长的时间(大约15分钟)。要将主机系统上的目录用作数据卷,请运行以下命令:$ docker run -d --name <container_name> -v <host_directory>:/opt/oracle/oradata container-registry.oracle.com/database/express:21.3.0-xe
如果未使用"自定义配置"部分中描述的-e选项提供密码,容器首次启动时会为数据库生成随机密码。要更改这些账户的密码,请使用docker exec命令运行容器中的setPassword.sh脚本。注意,运行脚本前容器必须处于运行状态。例如:
$ docker exec <container_name> ./setPassword.sh <new_password>
您可以使用以下命令访问数据库告警日志,其中<container_name>是容器名称:
$ docker logs <container_name>
容器内的Oracle XE数据库还配置了Oracle Enterprise Manager (OEM) Express。要访问OEM Express,请启动浏览器并输入OEM URL:
当Oracle数据库服务器指示容器已启动且STATUS字段显示(healthy)后,客户端应用程序即可连接到数据库。
您可以通过在容器内运行SQL*Plus命令连接到Oracle数据库服务器,使用以下命令之一:
$ docker exec -it <container_name> sqlplus / as sysdba
$ docker exec -it <container_name> sqlplus sys/<password>@XE as sysdba
$ docker exec -it <container_name> sqlplus system/<password>@XE
$ docker exec -it <container_name> sqlplus pdbadmin/<password>@XEPDB1
默认情况下,Oracle数据库使用Oracle的SQLNet协议暴露1521端口用于Oracle客户端连接。可以使用SQLPlus或任何Oracle Java Database Connectivity (JDBC)客户端从容器外部连接到数据库服务器。要从容器外部连接,请按照"自定义配置"部分中的详细Docker run命令所述,使用-p选项启动容器。通过运行以下命令发现映射的端口:
$ docker port <container_name>
要使用SQL*Plus从容器外部连接,请运行以下命令:
# 以sysdba身份连接到CDB$ROOT级别的数据库:
$ sqlplus sys/<password>@//localhost:<host_port>/XE as sysdba
# 以非sysdba身份连接到CDB$ROOT级别:
$ sqlplus system/<password>@//localhost:<host_port>/XE
# 连接到XE数据库中的默认可插拔数据库(PDB):
$ sqlplus pdbadmin/<password>@//localhost:<host_port>/XEPDB1
如果按照自定义配置部分中"挂载Docker卷/主机目录以实现数据库持久化"所述,使用挂载到容器内/opt/oracle/oradata位置的主机系统目录启动数据库,则即使容器被销毁,数据文件也会保持持久化。可以通过重用主机系统目录启动另一个使用相同数据文件的容器。要将主机系统上的此目录重用作数据卷,请运行以下命令:
$ docker run -d --name <container_name> -v <host_directory>:/opt/oracle/oradata container-registry.oracle.com/database/express:21.3.0-xe
Docker镜像可以配置为在设置后和启动时运行脚本。目前支持.sh和.sql扩展名。对于设置后脚本,挂载/opt/oracle/scripts/setup卷以包含此目录中的脚本。对于启动后脚本,挂载/opt/oracle/scripts/startup卷以包含此目录中的脚本。这两个位置也通过符号链接/docker-entrypoint-initdb.d表示。此配置与其他数据库Docker镜像提供了协同作用。您可以决定将设置和启动脚本放在/opt/oracle/scripts下还是/docker-entrypoint-initdb.d下。数据库设置或启动后,这些文件夹中的脚本将在容器内的数据库上运行。SQL脚本以SYSDBA身份运行,shell脚本以当前用户身份运行。
为确保脚本按顺序运行,Oracle建议为脚本添加数字前缀。例如:01_users.sql、02_permissions.sql等。
[!NOTE] 启动脚本在数据库首次设置完成后运行。
以下示例将本地目录/home/oracle/myScripts挂载到/opt/oracle/scripts/startup,然后会搜索此目录中的自定义启动脚本:
$ docker run -d --name <container_name> -v /home/oracle/myScripts:/opt/oracle/scripts/startup container-registry.oracle.com/database/express:21.3.0-xe
有关Oracle对可访问性的承诺,请访问Oracle可访问性计划网站:[***]
Oracle Database XE Release 21c (21.3.0.0) Docker Image Documentation Copyright © 2005, 2022, Oracle and/or its affiliates.
Oracle Free Use Terms and Conditions
Definitions
"You" and "Your" refers to (a) a company or organization (each an "Entity") accessing the Programs, if use of the Programs will be on behalf of such Entity; or (b) an individual accessing the Programs, if use of the Programs will not be on behalf of an Entity.
"Program(s)" refers to Oracle software provided by Oracle pursuant to the following terms and any updates, error corrections, and/or Program Documentation provided by Oracle.
"Program Documentation" refers to Program user manuals and Program installation manuals, if any. If available, Program Documentation may be delivered with the Programs and/or may be accessed from [***]
"Separate Terms" refers to separate license terms that are specified in the Program Documentation, readmes or notice files and that apply to Separately Licensed Technology.
"Separately Licensed Technology" refers to Oracle or third party technology that is licensed under Separate Terms and not under the terms of this license.
Separately Licensed Technology
Oracle may provide certain notices to You in Program Documentation, readmes or notice files in connection with Oracle or third party technology provided as or with the Programs. If specified in the Program Documentation, readmes or notice files, such technology will be licensed to You under Separate Terms. Your rights to use Separately Licensed Technology under Separate Terms are not restricted in any way by the terms herein. For clarity, notwithstanding the existence of a notice, third party technology that is not Separately Licensed Technology shall be deemed part of the Programs licensed to You under the terms of this license.
Source Code for Open Source Software
For software that You receive from Oracle in binary form that is licensed under an open source license that gives You the right to receive the source code ...
请登录使用轩辕镜像享受快速拉取体验,支持国内访问优化,速度提升
docker pull container-registry.oracle.com/database/express:21.3.0-xe探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务