镜像地址:
阿里云:https://cr.console.aliyun.com/cn-hangzhou/instances/images
DockerHub:https://hub.docker.com/
我使用的是阿里云的镜像,下载速度更块。
一、oracle10g、oracle12c
1、配置
安装oracle10和oracle12比较顺利,基本没有什么坑,下面记录一下
docker pull registry.cn-hangzhou.aliyuncs.com/chenyl/oracle-xe-10g #下载镜像
docker images #查看镜像
docker run -d -p 1521:1521 --name oracle10g registry.cn-hangzhou.aliyuncs.com/chenyl/oracle-xe-10g #运行镜像
#其中-d表示后台运行,这样退出终端docker容器不会挂掉,--name给容器起一个名字
docker exec -it oracle10g bash #进入容器
#-i表示交互方式,t表示终端
#修改密码
sqlplus /nolog
connect sys/oracle as sysdba
# alter user username identified by password;
alter user system identified by "123456";
alter user sys identified by "123456";
#创建用户并设置密码
create user oracle10 identified by "123456“;
#oracle密码默认有效期是180天好像,设置这个密码不过期
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
#oracle12c的镜像安装也是这样,只是拉取的镜像不一样而已
docker pull registry.cn-hangzhou.aliyuncs.com/clearcodecn/oracle12c
如果出现Connected to an idle instance;可以试一下重启oracle服务:service oracle restart,或者数据库监听未启动
这样就安装好了,可以使用navicat连接了
2、连接
进入容器之后,使用如下命令查看数据库提供监听服务的名字
lsnrctl status
这里有很多个监听服务,随便连接一个都可以:
二、oracle11g
为什么把oracle11g单独拿出来呢?因为这个镜像需要自己设置一下配置文件,比较奇怪...
这里需要自己配置一下环境变量,其他的基本一样
我们安装oracle10和12的时候,运行容器后进入可以之间操作数据库了,但是oracle11会报错
这里需要我们在docker里面设置一下环境变量
su root
#密码为helowin
vi /ect/profile
# 追加
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
export ORACLE_SID=helowin
export PATH=$ORACLE_HOME/bin:$PATH
#source一下使配置生效
source /etc/profile
#切换回oracle用户
su oracle
#因为重启docker之后echo$ORACLE_HOME为空,并且lsnrctl status不能使用,发现只有再次source /etc/profile之后才可以使用,所以在oracle用户下~/.bashrc中增加
source /etc/profile
这样之后你就可以按照前面的步骤进行修改密码等操作了。