docker部署oracle数据库
一、下载oracle镜像
[root@localhost ~]# docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
二、创建自定义网段
[root@localhost ~]# docker network create --driver bridge --subnet 172.18.0.0/16 --gateway 172.18.0.1 my_bridge
三、创建数据持久化目录
[root@localhost ~]# mkdir -pv /dev/shm
[root@localhost ~]# mkdir -pv /home/app/oracleout
四、将数据解压到指定目录
[root@localhost ~]# tar xf oradata.tar.gz -C /home/app/oracleout
五、创建容器
[root@localhost ~]# docker run --privileged -h chemdb.thinks.net.cn -d -p 1521:1521 --restart=always -v /dev/shm:/dev/shm -v /home/app/oracleout:/dockerfiles -v /home/app/oracleout/oradata:/opt/app/oracle/oradata --name chemdb --network my_bridge --ip 172.18.0.17 -t thinks/chemdb:oracle
六、进入数据库
[root@localhost ~]# docker exec -it chemdb bash
七、切换root用户
[oracle@chemdb /]$ su - root
Password: helowin
八、编辑环境变量
[root@chemdb ~]# tail -3 /etc/profile
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH
九、加载环境变量
[root@chemdb ~]# source /etc/profile
十、创建启动命令软连接
[root@chemdb ~]# ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
十一、退出root用户并登录
[root@chemdb ~]# exit
logout
[oracle@chemdb /]$ sqlplus / as sysdba
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
十二、启动数据库服务并开启监听
SQL> startup;
ORACLE instance started.Total System Global Area 1603411968 bytes
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@chemdb ~]$ lsnrctlLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-JUN-2025 23:28:24Copyright (c) 1991, 2009, Oracle. All rights reserved.Welcome to LSNRCTL, type "help" for information.LSNRCTL> start
TNS-01106: Listener using listener name LISTENER has already been started
LSNRCTL> status
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 16-JUN-2025 22:34:03
Uptime 3 days 0 hr. 54 min. 33 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/chemdb/listener/alert/log.xml
Listening Endpoints Summary...(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=chemdb.thinks.net.cn)(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
LSNRCTL> exit
十三、基本使用
1、创建用户并授权
[oracle@chemdb ~]$ sqlplus / as sysdba
SQL> create user lv identified by 123456;User created.SQL> grant dba to lv;Grant succeeded.
2、导入数据
将数据放到容器的挂在目录中,而后进入容器查看对应目录下是否有对应的数据.sql文件
[oracle@chemdb ~]$ sqlplus lv/123456
SQL> @/opt/app/oracle/admin/chemdb/dpdump/.sql
3、查看当前用户
SQL> show user;
4、查看表结构
SQL> desc dba_users;
5、启用锁定的用户
SQL> alter user username(用户名) account unlock;
6、设置用户的默认或者临时表空间
SQL> alter user username default|temporary tablespacetablespace_name;
#普通用户没有这个权限,管理员可以修改,也可以为普通用户设置
7、普通用户登录查看的数据表
SQL> select tablespace_name from user_tablespaces;
8、创建表空间
永久表空间
SQL> create tablespace tablespace_name datafile 'xx.dbf' size xx;
临时表空间
SQL> create temporary tablespace tablespace_name templile 'xx.dbf' size xx;
#DATAFILE:设置表空间数据文件,xx.dbf是数据文件的名称,最好设置数据文件的所在路径。SIZE:设置数据文件大小。
9、创建用户,随便分配表空间
SQL> create user username identified by "123456" default tablespace test profile default account unlock;
10、查询目录
SQL> select * from dba_directories;