Docker Oracle11g安装,运行和远程连接 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 # 拉取oracle11g镜像 docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g # 开启IPV4_Forwarding,不然docker run会报"docker WARNING: IPv4 forwarding is disabled"  #  在/usr/lib/sysctl.d/00-system.conf末尾追加net.ipv4.ip_forward=1 sudo vim /usr/lib/sysctl.d/00-system.conf #  重启network和docker sudo systemctl restart network sudo systemctl restart docker # 运行oracle11g实例 docker run -d -p 1521:1521 --name oracle11g registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g docker run -d --privileged --name oracle11g -p 1521:1521 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g 
 
docker run最后一个参数是IMAGE参数,通过docker images查看并选取。
查看创建的容器是否运行
 
若没运行使用
1 docker start `docker ps -ql` 
 
Oracle11g实例配置 
运行容器后,利用bash与容器通信
1 docker exec -it oracle11g bash 
 
可以看到是以oracle用户登录的bash
添加环境变量
1 [oracle@2e83efb795d2 ~]$ vi /home/oracle/.bashrc 
 
末尾追加
1 2 3 export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2 export ORACLE_SID=helowin export PATH=$ORACLE_HOME/bin:$PATH 
 
执行脚本
1 [oracle@2e83efb795d2 ~]$ source /home/oracle/.bashrc 
 
进入sqlplus
1 2 sqlplus /nolog conn /as sysdba 
 
接下来修改管理员用户的密码
修改用户密码格式为:ALTER USER 用户名 IDENTIFIED BY 密码;
 
普通管理员为system,超级管理员为sys。
1 2 alter user system identified by 123456; alter user sys identified by 123456; 
 
创建用户,并给用户赋予权限[可选]
1 2 create user test identified by 123456; grant connect,resource,dba to test; 
 
修改密码后执行以下命令刷新数据表
1 ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; 
 
退出sqlplus
 
远程连接Oracle11g实例(Navicat) 
 
远程连接Oracle11g实例(PLSQL) 
容器端-修改oracle11g容器上的listener.ora 
在与oracle11g实例沟通的bash中输入:
1 2 [oracle@2e506be866a3 /]$ lsnrctl status [oracle@2e506be866a3 /]$ vi /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora 
 
改为
1 2 3 4 5 6 7 8 9 10 11 12 # listener.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER =   (DESCRIPTION_LIST =     (DESCRIPTION =       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))       (ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))     )   ) ADR_BASE_LISTENER = /home/oracle/app/oracle 
 
这样最好改成0.0.0.0,listener是用来监听本容器某端口是否有incoming连接,那么这里就应该将host配置为0.0.0.0。
修改好了就重启下listener:
1 2 3 4 5 #  连接空闲时listener重启 [oracle@2e506be866a3 /]$ lsnrctl reload #  或者使用stop+start命令:强制切断listener所有连接并重启 [oracle@2e506be866a3 /]$ lsnrctl stop [oracle@2e506be866a3 /]$ lsnrctl start 
 
查看服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 [oracle@2e506be866a3 /]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 22-FEB-2021 15:04:04 Copyright (c) 1991, 2009, Oracle.  All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) STATUS of the LISTENER ------------------------ Alias                     LISTENER Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date                22-FEB-2021 14:23:50 Uptime                    0 days 0 hr. 40 min. 14 sec Trace Level               off Security                  ON: Local OS Authentication SNMP                      OFF Listener Parameter File   /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/2e506be866a3/listener/alert/log.xml Listening Endpoints Summary...   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=2e506be866a3)(PORT=1521))) Services Summary... Service "helowin" has 1 instance(s).   Instance "helowin", status READY, has 1 handler(s) for this service... Service "helowinXDB" has 1 instance(s).   Instance "helowin", status READY, has 1 handler(s) for this service... The command completed successfully 
 
可以看到有两个服务"helowin"和"helowinXDB",都来自于"helowin"实例。
PLSQL配置 
下载PLSQL 32位!使用管理员身份运行它。
配置如下图所示:
 
创建tnsnames.ora 
下载并解压instantclient_11_2。
在解压后的instantclient_11_2目录下创建tnsnames.ora文件,然后复制容器中的/home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/tnsnames.ora文件内容
1 [oracle@2e506be866a3 /]$ cat /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/tnsnames.ora  
 
instantclient_11_2/tnsnames.ora内容文件如下:
1 2 3 4 5 6 7 8 9 10 11 # tnsnames.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/dbhome_2/network/admin/tnsnames.ora # Generated by Oracle configuration tools. helowin =   (DESCRIPTION =     (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.5)(PORT = 1521))     (CONNECT_DATA = 	  (SERVER = DEDICATED)       (SERVICE_NAME = helowinXDB)     )   ) 
 
SERVICE_NAME = helowinXDB或SERVICE_NAME = helowin都可以。10.0.0.5是我Docker主机所在地址。
文件中"helowin ="标识符应该与docker容器lsnrctl status查询到的实例名称一致,SERVICE_NAME也是如此。
 
Database:主机/标识符。主机最好加上,不然有可能报找不到标识符的错误。
一旦你加上主机:Database这两种写法都可以连接到oracle11g容器:
1 2 10.0.0.5/helowin 10.0.0.5/helowinXDB 
 
 
参考:
docker-images/OracleDatabase/SingleInstance at main · oracle/docker-images 
Docker 拉取 oracle 11g镜像配置_荡漾-CSDN博客_docker oracle 
docker WARNING: IPv4 forwarding is disabled 问题解决 - 御用闲人 - 博客园 
ORACLE-BASE - Change Your Own Password in an Oracle Database 
How To List Users in the Oracle Database 
ORACLE-BASE - Oracle Network Configuration (listener.ora , tnsnames.ora , sqlnet.ora) 
Oracle client ORA-12541: TNS:no listener - Stack Overflow 
Linux Docker Oracle11g安装,运行和远程连接