目录
1.下载Docker Desktop
如果不能下载,访问此页面手动点击下载:Docker中文网 官网
2.安装Docker Desktop
允许下载后的安装文件,按提示安装完成。允许Docker Desktop后发现软件无法正常启动,执行如下命令更新wls,更新成功后运行正常。
wsl --update
3.下载oracle11g
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
1)Powershell查看image
docker images
2)Docker Desktop查看image
4.创建并运行oracle11g容器
docker run -d -p 1521:1521 --name oracle11g registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
docker命令解释参考:Docker 命令大全 | 菜鸟教程
1)启动失败,Docker Desktop Containers的status是Exited 139。
解决方法:在%userprofile%文件夹下创建一个.wslconfig文件。
.wslconfig文件内容为:
[wsl2]
kernelCommandLine = vsyscall=emulate
文件创建完毕,重启wsl。
wsl --shutdown
重启电脑,允许Docker Desktop,运行oracle11g正常。
5.进入数据库配置
1)进入容器
docker exec -it oracle11g bash
2)root用户设置新密码
原密码:helowin
su root
passwd
3)修改环境变量,创建软连接,便于在oracle账户连接oracle数据库。
修改环境变量:
vim /home/oracle/.bashrc
在该文件的末尾加三行:
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH
环境变量生效:
source /home/oracle/.bashrc
创建数据库运行命令软连接:
ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
连接数据库:
sqlplus /nolog
conn /as sysdba
修改密码为oraclen:
alter user system identified by oraclen;
alter user sys identified by oraclen;
alter user scott account unlock;
alter user scott identified by oraclen;
6.Navicat连接数据库
数据库默认服务名:helowin
地址:localhost
使用用户:scott
密码:oraclen
连接成功:
7.本地数据导入容器
进入需要导入的数据所在上一级文件夹,输入如下命令,数据导入容器指定文件夹
docker cp .\db cb45256c75ad:/home/oracle/app/db
8.dump数据导入oracle数据库
1)进入到导入文件所在文件夹db后连接数据库
sqlplus /nolog
conn /as sysdba
2)导入数据
impdp scott/oraclen@helowin directory=/home/oracle/app/db/db/ dumpfile=xxxxx_head.dmp logfile=import_log.log
导入出错:directory name xxx is invalid
原因:需要在数据库中创建目录,而不是指dmp文件的物理目录路径。
连接数据库后数据库中创建目录:
sqlplus /nolog
conn /as sysdba
#创建目录
CREATE OR REPLACE DIRECTORY oracledb AS '/home/oracle/app/db/db';
#目录授权给scott
grant read,write on directory oracledb to scott;
再次导入出错:dump file "xxx_head.dmp" may be an original export dump file
改用imp工具导入:
imp scott/oraclen@helowin file="/home/oracle/app/db/db/xxx_head.dmp" log=importlog.log full=y ignore=y
又报错:vlue too large for column "SCOTT"."xxx_HEAD"."xxx_NAME"(actual:21,maximum:14)
解决方法待撰写:《Win11安装Docker Desktop运行oracle11g(二)》
9.参考资料
1.windows环境下使用docker安装oracle11g_docker oracle11g镜像_让天地一先的博客-CSDN博客