docker安装oracle

我参考了 https://blog.csdn.net/u010148813/article/details/126152734

1、我用的虚拟机(宿主机)是Ubuntu

root@jin-virtual-machine:/etc/docker# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

出于我在win11上安装oracle19c的实例,一直卡在54%,走不下去,这个原因,我无奈采用在虚拟机上,用docker安装oracle。

首先是有docker-ce环境,参考https://www.cnblogs.com/wuyicode/p/11594514.html

 

2、下载image

docker pull registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c

# 镜像文件还挺大的。一定提前设置docker源,或者加速镜像。

root@jin-virtual-machine:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle 19c 7b5eb4597688 2 years ago 6.61GB

 

3、准备启动容器

# 创建目录
mkdir -p /mydata/oracle/oradata
 
chmod 777 -R  /mydata
docker run -d  \
-p 1525:1521 -p 5500:5500 \
-e ORACLE_SID=ORCL \
-e ORACLE_PDB=ORCLPDB \
-e ORACLE_PWD=orcl \
-e ORACLE_EDITION=standard \
-e ORACLE_CHARACTERSET=ZHS16GBK \
-v /mydata/oracle/oradata:/opt/oracle/oradata \
--name oracle19c \
registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c

#1525是宿主机的端口
# 容器名字叫oracle19c 
root@jin-virtual-machine:~# docker ps -a
CONTAINER ID   IMAGE                                                   COMMAND                  CREATED        STATUS                      PORTS     NAMES
5f14c00c937a   registry.cn-hangzhou.aliyuncs.com/zhuyijun/oracle:19c   "/bin/sh -c 'exec $O…"   44 hours ago   Exited (137) 17 hours ago             oracle19c

# 启动
root@jin-virtual-machine:~# docker start oracle19c
oracle19c

#查看日志
root@jin-virtual-machine:~# docker logs -ft oracle19c

 

4、sqlplus连接

#进入容器
root@jin-virtual-machine:~# docker exec -it oracle19c /bin/bash
[oracle@5f14c00c937a ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jan 13 03:21:08 2023
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 pdbs;

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 ORCLPDB                        READ WRITE NO
SQL> select name from v$database;

NAME
---------
ORCL

SQL> alter session set container=ORCLPDB;

Session altered.

SQL> select name from v$database;

NAME
---------
ORCL
#创建用户,授权
#在alter session set container=ORCLPDB;之后执行以下命令。
alter session set container=ORCLPDB;

create user jin identified by 123456;

grant connect, resource, dba to jin;
grant sysdba to jin;

#查看新建的用户是否存在
select username from v$pwfile_users;

#在容器里,执行 sqlplus jin/123456@localhost:1521/orclpdb

 

 



#由于我的linux宿主机没有sqlplus命令,那么我直接在windows上执行sqlplus。
#从https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html下载client

 

#使用cmd命令连接 

D:\PLSQL\instantclient_19_17>sqlplus jin/123456@192.168.232.128:1525/orclpdb

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jan 13 11:30:32 2023
Version 19.17.0.0.0

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

Last Successful login time: Thu Jan 12 2023 16:07:33 +08:00

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

SQL>

 

#使用dbeaver工具连接,测试连接,联网自动下载驱动。

 

 

 

 

 

posted on 2023-01-13 11:37  wuyicode  阅读(1312)  评论(0编辑  收藏  举报