在 Docker 容器中安装 Oracle 19c 是可行的,但它相较于其他数据库(如 MySQL、PostgreSQL 等)会复杂一些,因为 Oracle 数据库有一些特定的要求,如操作系统和库的依赖,以及许可证问题。
不过,Oracle 官方已经提供了 Oracle Database 19c Docker 镜像,你可以使用它来快速启动 Oracle 19c 数据库。
- Oracle 19c Docker 镜像
Oracle 提供了官方的 Docker 镜像,你可以通过以下步骤来使用:
1.1 拉取 Oracle 19c 镜像
Oracle 在 Docker Hub 上并没有直接提供 19c 镜像,而是通过 Oracle 官方的 GitHub 仓库发布了 Dockerfiles,你可以从中构建自己的镜像。Oracle 官方提供的 GitHub 地址:Oracle Docker GitHub
首先,访问 Oracle 的 GitHub 页面,获取 19c 的 Docker 镜像构建方法,或者直接使用以下命令从 Docker Hub 拉取已构建的镜像。
对于 Oracle 19c,通常你需要拉取的是 oracle/database:19.3.0-ee(Enterprise Edition)或者 oracle/database:19.3.0-se2(Standard Edition 2)。
例如:
docker pull oracle/database:19.3.0-ee
1.2 启动 Oracle 19c 容器
拉取完镜像后,可以使用以下命令启动 Oracle 19c 容器:
docker run -d -it --name oracle19c
-p 1521:1521 -p 5500:5500
-e ORACLE_PDB=ORCLPDB1
-e ORACLE_PASSWORD=your_password
oracle/database:19.3.0-ee
解释:
–name oracle19c:为容器指定一个名称(例如 oracle19c)。
-p 1521:1521:将容器的 1521 端口(Oracle 默认端口)映射到宿主机的 1521 端口。
-p 5500:5500:将容器的 5500 端口映射到宿主机的 5500 端口(用于 Oracle Enterprise Manager Express)。
-e ORACLE_PDB=ORCLPDB1:指定 PDB(Pluggable Database)名称。
-e ORACLE_PASSWORD=your_password:设置 Oracle 数据库的密码。替换为你想要设置的密码。
该命令会在后台启动 Oracle 容器,并将 1521 和 5500 端口映射到宿主机。你可以通过宿主机的 localhost:1521 来连接到 Oracle 数据库。
- 使用 Dockerfile 自定义构建
如果你想构建自定义的 Oracle 19c 镜像,Oracle 提供了相应的 Dockerfile,你可以根据以下步骤进行构建:
克隆 Oracle Docker 镜像的 GitHub 仓库:
git clone https://github.com/oracle/docker-images.git
cd docker-images\OracleDatabase\SingleInstance\dockerfiles\19.3.0
copy download/LINUX.X64_193000_db_home.zip .
cd docker-images\OracleDatabase\SingleInstance\dockerfiles
构建镜像: 在构建之前,确保你已经安装了 Docker。然后使用以下命令构建 Oracle 19c 镜像:
./buildContainerImage.sh -v 19.3.0 -t oracle/database:19.3.0-ee -e
这将构建一个名为 oracle/database:19.3.0-ee 的镜像。
Administrator@desktop-02 MINGW64 /e/workspace_docker/docker-images/OracleDatabase/SingleInstance/dockerfiles (main)
$ ./buildContainerImage.sh -v 19.3.0 -t oracle/database:19.3.0-ee -e
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile
Checking Docker version.
Dockerfile
Checking if required packages are present and valid...
LINUX.X64_193000_db_home.zip: OK
==========================
Container runtime info:
Client:
Version: 27.4.0
Context: desktop-linux
Debug Mode: false
Plugins:
ai: Ask Gordon - Docker Agent (Docker Inc.)
Version: v0.5.1
Path: C:\Users\Administrator\.docker\cli-plugins\docker-ai.exe
buildx: Docker Buildx (Docker Inc.)
Version: v0.19.2-desktop.1
Path: C:\Users\Administrator\.docker\cli-plugins\docker-buildx.exe
compose: Docker Compose (Docker Inc.)
构建情况:
Administrator@desktop-02 MINGW64 /e/workspace_docker/docker-images/OracleDatabase/SingleInstance/dockerfiles (main)
$ ./buildContainerImage.sh -v 19.3.0 -t oracle/database:19.3.0-ee -e
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile
Checking Docker version.
Dockerfile
Checking if required packages are present and valid...
LINUX.X64_193000_db_home.zip: OK
==========================
Container runtime info:
Client:
Version: 27.4.0
Context: desktop-linux
Debug Mode: false
Plugins:
ai: Ask Gordon - Docker Agent (Docker Inc.)
Version: v0.5.1
Path: C:\Users\Administrator\.docker\cli-plugins\docker-ai.exe
buildx: Docker Buildx (Docker Inc.)
Version: v0.19.2-desktop.1
Path: C:\Users\Administrator\.docker\cli-plugins\docker-buildx.exe
compose: Docker Compose (Docker Inc.)
Version: v2.31.0-desktop.2
Path: C:\Users\Administrator\.docker\cli-plugins\docker-compose.exe
debug: Get a shell into any image or container (Docker Inc.)
Version: 0.0.37
Path: C:\Users\Administrator\.docker\cli-plugins\docker-debug.exe
desktop: Docker Desktop commands (Beta) (Docker Inc.)
Version: v0.1.0
Path: C:\Users\Administrator\.docker\cli-plugins\docker-desktop.exe
dev: Docker Dev Environments (Docker Inc.)
Version: v0.1.2
Path: C:\Users\Administrator\.docker\cli-plugins\docker-dev.exe
extension: Manages Docker extensions (Docker Inc.)
Version: v0.2.27
Path: C:\Users\Administrator\.docker\cli-plugins\docker-extension.exe
feedback: Provide feedback, right in your terminal! (Docker Inc.)
Version: v1.0.5
Path: C:\Users\Administrator\.docker\cli-plugins\docker-feedback.exe
init: Creates Docker-related starter files for your project (Docker Inc.)
Version: v1.4.0
Path: C:\Users\Administrator\.docker\cli-plugins\docker-init.exe
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
Version: 0.6.0
Path: C:\Users\Administrator\.docker\cli-plugins\docker-sbom.exe
scout: Docker Scout (Docker Inc.)
Version: v1.15.1
Path: C:\Users\Administrator\.docker\cli-plugins\docker-scout.exe
Server:
Containers: 4
Running: 0
Paused: 0
Stopped: 4
Images: 3
Server Version: 27.4.0
Storage Driver: overlayfs
driver-type: io.containerd.snapshotter.v1
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
CDI spec directories:
/etc/cdi
/var/run/cdi
Swarm: inactive
Runtimes: io.containerd.runc.v2 nvidia runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111
runc version: v1.1.13-0-g58aa920
init version: de40ad0
Security Options:
seccomp
Profile: unconfined
Kernel Version: 5.15.167.4-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 7.688GiB
Name: docker-desktop
ID: b354966b-6f88-4b9c-a5e4-5a8422fbc482
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Labels:
com.docker.desktop.address=npipe://\\.\pipe\docker_cli
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5555
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile
==========================
Building image 'oracle/database:19.3.0-ee' ...
[+] Building 789.4s (16/16) FINISHED docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 5.21kB 0.0s
=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 25) 0.0s
=> [internal] load metadata for docker.io/library/oraclelinux:7-slim 2.8s
=> [auth] library/oraclelinux:pull token for registry-1.docker.io 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [base 1/4] FROM docker.io/library/oraclelinux:7-slim@sha256:1add6ed8602ea996528110fe75f4b03c2ca7ffdbe9497148dbb46c3cc9ce6acd 0.0s
=> => resolve docker.io/library/oraclelinux:7-slim@sha256:1add6ed8602ea996528110fe75f4b03c2ca7ffdbe9497148dbb46c3cc9ce6acd 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 537B 0.0s
=> [base 2/4] COPY setupLinuxEnv.sh checkSpace.sh /opt/install/ 0.0s
=> [base 3/4] COPY runOracle.sh startDB.sh createDB.sh createObserver.sh dbca.rsp.tmpl setPassword.sh checkDBStatus.sh runUserScripts.sh relinkOracleBinary.sh configTcps.sh /opt/oracle/ 0.1s
=> [base 4/4] RUN chmod ug+x /opt/install/*.sh && sync && /opt/install/checkSpace.sh && /opt/install/setupLinuxEnv.sh && rm -rf /opt/install 44.3s
=> [builder 1/2] COPY --chown=oracle:dba LINUX.X64_193000_db_home.zip db_inst.rsp installDBBinaries.sh /opt/install/ 97.2s
=> [builder 2/2] RUN chmod ug+x "/opt/install"/*.sh && sync && "/opt/install"/"installDBBinaries.sh" ee 291.3s
=> [stage-2 1/4] COPY --chown=oracle:dba --from=builder /opt/oracle /opt/oracle 86.2s
=> [stage-2 2/4] RUN "/opt/oracle"/oraInventory/orainstRoot.sh && "/opt/oracle/product/19c/dbhome_1"/root.sh 2.7s
=> [stage-2 3/4] WORKDIR /home/oracle 0.1s
=> [stage-2 4/4] RUN echo 'ORACLE_SID=${ORACLE_SID:-ORCLCDB}; export ORACLE_SID=${ORACLE_SID^^}' > .bashrc 0.7s
=> exporting to image 235.6s
=> => exporting layers 178.8s
=> => exporting manifest sha256:89a64ba178832bf56c89b4086023281875c1881cee742d49d3a735893fa94ab1 0.0s
=> => exporting config sha256:17e13d7dbb70cffae764691fb1207c1947e21e425595c1cf01be09d76d340fd2 0.0s
=> => exporting attestation manifest sha256:d7992dc6df324c174a6c2cbe8292c1379aa01a0c99b74742d93425e120734dcd 0.0s
=> => exporting manifest list sha256:9b96b9c8d56fad3b211a564d23b42e599aa52613688108febc029dc34f497ca5 0.0s
=> => naming to docker.io/oracle/database:19.3.0-ee 0.0s
=> => unpacking to docker.io/oracle/database:19.3.0-ee 56.7s
1 warning found (use docker --debug to expand):
- FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 25)
Oracle Database container image for 'ee' version 19.3.0 is ready to be extended:
--> oracle/database:19.3.0-ee
Build completed in 792 seconds.
Administrator@desktop-02 MINGW64 /e/workspace_docker/docker-images/OracleDatabase/SingleInstance/dockerfiles (main)
通过docker desktop可以看到该image已经创建:
构建完成后,使用 docker run 命令启动容器:
docker run -d -it --name oracle19c -p 1521:1521 -p 5500:5500 -e ORACLE_PDB=ORCLPDB1 -e ORACLE_PASSWORD=password oracle/database:19.3.0-ee
- 注意事项
资源要求:Oracle 19c 数据库有比较高的资源需求,特别是内存和 CPU。确保你的机器有足够的资源来运行 Oracle 容器。一般来说,至少需要 2 GB 的内存和 2 核的 CPU。
许可证问题:Oracle 数据库是商用软件,使用时需要遵循 Oracle 的许可证。Oracle 提供的 Docker 镜像是商用版本,你需要确保有合法的许可证来使用它。如果你只是进行开发和测试,可以使用 Oracle 提供的免费开发许可证。
Oracle 实例初始化:在第一次启动 Oracle 容器时,它会初始化数据库,这可能需要一些时间。你可以查看容器的日志,确认初始化是否完成:
docker logs -f oracle19c
日志情况 |
---|
C:\Users\Administrator>docker logs -f oracle19c |
ORACLE EDITION: ENTERPRISE
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 24-JAN-2025 01:50:13
Copyright © 1991, 2019, Oracle. All rights reserved.
Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait…
TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/867211d171c1/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 24-JAN-2025 01:50:14
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/867211d171c1/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully
Prepare for db operation
8% complete
Copying database files
31% complete
Creating and starting Oracle instance
32% complete
36% complete
40% complete
43% complete
46% complete
Completing Database Creation
51% complete
54% complete
Creating Pluggable Databases
58% complete
77% complete
Executing Post Configuration Actions
100% complete
Database creation complete. For details check the logfiles at:
/opt/oracle/cfgtoollogs/dbca/ORCLCDB.
Database Information:
Global Database Name:ORCLCDB
System Identifier(SID):ORCLCDB
Look at the log file “/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log” for further details.
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jan 24 02:03:36 2025
Version 19.3.0.0.0
Copyright © 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL>
System altered.
SQL>
System altered.
SQL>
Pluggable database altered.
SQL>
PL/SQL procedure successfully completed.
SQL> SQL>
Session altered.
SQL>
User created.
SQL>
Grant succeeded.
SQL>
Grant succeeded.
SQL>
Grant succeeded.
SQL>
User altered.
SQL> SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
The Oracle base remains unchanged with value /opt/oracle
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
ORCLPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE “USERS”
2025-01-24T02:03:36.547120+00:00
ALTER SYSTEM SET control_files=‘/opt/oracle/oradata/ORCLCDB/control01.ctl’ SCOPE=SPFILE;
2025-01-24T02:03:36.553039+00:00
ALTER SYSTEM SET local_listener=‘’ SCOPE=BOTH;
ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
Completed: ALTER PLUGGABLE DATABASE ORCLPDB1 SAVE STATE
2025-01-24T02:03:36.940030+00:00
XDB initialized.
2025-01-24T02:13:25.058000+00:00
ORCLPDB1(3):Resize operation completed for file# 10, old size 327680K, new size 337920K
- 连接到 Oracle 数据库
一旦容器启动并运行,你可以使用任何支持 Oracle 数据库连接的客户端(如 SQL*Plus、Oracle SQL Developer 等)连接到数据库。
一些19c的简单查询语句:
col account_status format a12;
col username format a20;
select account_status,username from dba_users order by 1;
set linesize 99;
col guid format a32;
col name format a32;
select con_id,dbid,guid,name,open_mode from v$pdbs;
show con_name
show pdbs
例如,通过 SQL*Plus 连接到 Oracle 19c 容器:
sqlplus sys/your_password@localhost:1521/ORCLPDB1 as sysdba
通过登录docker进行数据库操作:
docker exec -it oracle19c bash
bash-4.2$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 24-JAN-2025 02:35:30
Copyright © 1991, 2019, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 24-JAN-2025 01:50:14
Uptime 0 days 0 hr. 45 min. 16 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/867211d171c1/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=867211d171c1)(PORT=5500))(Security=(my_wallet_directory=/opt/oracle/admin/ORCLCDB/xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary…
Service “2c6b220cd5711311e063020011ace476” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “ORCLCDB” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “ORCLCDBXDB” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
Service “orclpdb1” has 1 instance(s).
Instance “ORCLCDB”, status READY, has 1 handler(s) for this service…
The command completed successfully
bash-4.2$ sqlplus sys/password as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jan 24 03:21:28 2025
Version 19.3.0.0.0
Copyright © 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> alter session set container=ORCLPDB1;
Session altered.
SQL>
SQL>
SQL> create user test01 identified by test01 default tablespace users;
User created.
SQL> grant connect,resource,select any table,select any dictionary ,create view to test01;
Grant succeeded.
SQL> alter session set container=orclpdb1;
Session altered.
SQL> alter user test01 quota unlimited on users;
User altered.
对在orclpdb1数据库容器上创建的test01用户进行测试
bash-4.2$ sqlplus test01/test01@localhost:1521/orclpdb1
SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jan 24 03:33:25 2025
Version 19.3.0.0.0
Copyright © 1982, 2019, Oracle. All rights reserved.
Last Successful login time: Fri Jan 24 2025 03:26:21 +00:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL>
SQL> create table tmp1 (a varchar(100));
Table created.
SQL> insert into tmp1 values(‘11111’);
1 row created.
SQL> commit;
Commit complete.
SQL> quit
通过图形界面的数据库工具查看:
- 停止和删除容器
如果你不再需要 Oracle 容器,可以停止并删除容器:
停止容器:
docker stop oracle19c
删除容器:
docker rm oracle19c
总结
在 Docker 容器中安装 Oracle 19c 是可行的,Oracle 提供了官方的 Docker 镜像和构建方法。
你可以从 Docker Hub 拉取 Oracle 19c 镜像,或使用 Oracle 提供的 Dockerfile 自定义构建镜像。
启动容器时,使用适当的端口映射和环境变量来设置数据库密码和 PDB 名称。
需要考虑资源要求和许可证问题,确保在合法和合适的环境中使用。