由于docker安装的oracle 12c有很多莫名其妙的bug,很多正常的SQL被它报错,比如:

SYS@lhrcdb1> @/par/day9.sql
  where case when s.sid>s.cnt-2 then s.sid+2-s.cnt else s.sid+2 end=s1.sid
              *
ERROR at line 24:
ORA-00923: FROM keyword not found where expected

基本无法使用。所以又重新拉取了oracle 19c的镜像,在建立容器的时候,遇到一些问题。
记录如下:

  1. 拉取oracle 19c的镜像
docker pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c
Trying to pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c...
Getting image source signatures
Copying blob 67f2dfeb2f1b done
Copying blob bce8f778fef0 done
Copying blob 3fc3fd32c0bc done
Copying blob 02948dd6d654 done
Copying blob b94f01bb60c6 done
Copying blob 2e42d8039fd9 done
Copying config 7b5eb45976 done
Writing manifest to image destination
Storing signatures
7b5eb4597688552155896cfba326482bb1622a9d1727dbd12232f819a6266ba0
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker image list -a
REPOSITORY                                                              TAG         IMAGE ID      CREATED        SIZE

registry.cn-hangzhou.aliyuncs.com/lhrbest/oracle_12cr2_ee_lhr_12.2.0.1  2.0         eb1a87913afe  5 years ago    16.2 GB
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle                       19c         7b5eb4597688  5 years ago    6.64 GB

注意两个镜像的大小,19c的反而更小,两者拉取的blob文件分别是5.6GB和2.6GB。

  1. 运行容器

第一次用了上次12c的同样命令行,结果出错了。

docker run -itd --name oracle19c  \
--privileged=true \
--restart=always \
-p 1521:1521 \
-p 5500:5500 \
-p 5501:5501 \
-p 5522:22 \
-p 3389:3389 \
-v /mnt/c/d/oracle12g/ora_data:/par  \
7b5eb4597688 init
7c0cc5ea36052fac64413cf177d886792110b34d1d9200b0caf2618dc3b307cd
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it oracle19c /bin/bash

[oracle@7c0cc5ea3605 ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 21 11:13:10 2025
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

ERROR:
ORA-12162: TNS:net service name is incorrectly specified


Enter user-name: ^C[oracle@7c0cc5ea3605 ~]$

查看环境变量没有ORACLE_SID。

[oracle@7c0cc5ea3605 ~]$ env

ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
container=podman
INSTALL_DB_BINARIES_FILE=installDBBinaries.sh
_=/usr/bin/env

人工指定ORACLE_SID,也不行

[oracle@7c0cc5ea3605 ~]$ export ORACLE_SID=ORCLCDB
[oracle@7c0cc5ea3605 ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 21 11:15:20 2025
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/opt/oracle/product/19c/dbhome_1/dbs/initORCLCDB.ora'
SQL> Disconnected

第二次使用了网上给出的命令行, 比第一次强,实例起来了,但是建表出错,然后丢失连接。

docker run -d -p 1521:1521  -p 5502:5500   -e ORACLE_SID=ORCLCDB  -e ORACLE_PDB=ORCLPDB  -e ORACLE_PWD=oracle  -e ORACLE_EDITION=standard  -e ORACLE_CHARACTERSET=AL32UTF8  -v /mnt/c/d/oracle12g/ora_data:/par --name  oracle19c 7b5eb4597688
318bd09d0a35d914b9a0a32911f776c2d2dc7c78e34a625ee952212d111fe1fc
root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it oracle19c /bin/bash
[oracle@318bd09d0a35 ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 21 11:23:15 2025
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> show sga;

Total System Global Area 3137338784 bytes
Fixed Size                  9141664 bytes
Variable Size             654311424 bytes
Database Buffers         2466250752 bytes
Redo Buffers                7634944 bytes
SQL> create table day9 as
select 1 id,7 x,1 y  from dual union all
select 2,11,1 from dual union all
select 3,11,7 from dual union all
select 4,9,7  from dual union all
select 5,9,5  from dual union all
select 6,2,5  from dual union all
select 7,2,3  from dual union all  2    3    4    5    6    7    8
  9  select 8,7,3  from dual ;
create table day9 as
*
ERROR at line 1:
ORA-03135: connection lost contact
Process ID: 604
Session ID: 733 Serial number: 61391


SQL> show sga;
ERROR:
ORA-03114: not connected to ORACLE

然后折腾了很久,停止容器,重启都用了,都连不上。
然后看到了这篇文章, 里面提到很重要的一点是,

2.4 查看安装过程
执行运行命令后,可以马上执行日志查看命令。创建实例的过程会比较长,请耐心等待。

docker logs -ft oracle19c

执行docker logs -ft oracle19c在日志中看到一个明显的出错信息

2025-12-21T19:29:57.196716000+08:00 ########### E R R O R ###############
2025-12-21T19:29:57.197027000+08:00 DATABASE SETUP WAS NOT SUCCESSFUL!
2025-12-21T19:29:57.197120000+08:00 Please check output for further info!
2025-12-21T19:29:57.197450000+08:00 ########### E R R O R ###############

联想到刚才的镜像大小,明白了,这两个镜像的内容不同,12c那个是安装完毕的,19c这个是未安装完的,所以刚才示例起来了是假象,实际还没创建完成,我中间的折腾破坏了安装过程,然后任何操作都出错。
再次关闭并删除错误的容器,重新运行刚才的docker run命令,并观察安装进度日志。

docker run -d -p 1521:1521  -p 5502:5500   -e ORACLE_SID=ORCLCDB  -e ORACLE_PDB=ORCLPDB  -e ORACLE_PWD=oracle  -e ORACLE_EDITION=standard  -e ORACLE_CHARACTERSET=AL32UTF8  -v /mnt/c/d/oracle12g/ora_data:/par --name  oracle19c 7b5eb4597688
113bf6abbd5961b60fcc7cee23eae34e7e29631a0e0dd3b721487b559e3dc423

docker logs -ft oracle19c

2025-12-21T20:26:30.510370000+08:00 #########################
2025-12-21T20:26:30.511001000+08:00 DATABASE IS READY TO USE!
2025-12-21T20:26:30.511491000+08:00 #########################

...

2025-12-21T20:26:30.517997000+08:00 ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
2025-12-21T20:26:30.518364000+08:00    ALTER PLUGGABLE DATABASE ORCLPDB SAVE STATE
2025-12-21T20:26:30.518899000+08:00 Completed:    ALTER PLUGGABLE DATABASE ORCLPDB SAVE STATE
2025-12-21T20:26:30.519175000+08:00
2025-12-21T20:26:30.519271000+08:00 XDB initialized.

这个时候登录就没问题了。

root@DESKTOP-59T6U68:/mnt/c/Users/lt# docker exec -it oracle19c /bin/bash
[oracle@113bf6abbd59 ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Dec 21 12:30:18 2025
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> create table day9 as
select 1 id,7 x,1 y  from dual union all
select 2,11,1 from dual union all
select 3,11,7 from dual union all
select 4,9,7  from dual union all
select 5,9,5  from dual union all
select 6,2,5  from dual union all
select 7,2,3  from dual union all
select 8,7,3  from dual ;

Table created.

SQL> @/par/day9.sql

        X1         Y1         X2         Y2       AREA
---------- ---------- ---------- ---------- ----------
         9          5          2          3         24

创建表成功,12c中报错的SQL也成功返回结果了。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐