参考

https://www.hangge.com/blog/cache/detail_2797.html

Docker 搭建 Oracle

安装步骤

拉取镜像

1
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

默认配置运行

1
docker run -d -p 1521:1521 --name oracle11g registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

自定义配置运行「不推荐」

  1. 创建 docker/oracle11g目录,拷贝容器数据目录到本地

    1
    docker container cp oracle11g:/home/oracle/app/oracle/oradata study/docker/oracle11g
  2. 启动

    1
    docker run -d -p 1521:1521 --name oracle11g registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g -v /Users/mac126/study/docker/oracle11g/oradata/helowin:/home/oracle/app/oracle/oradata/helowin

配置客户端

  1. 进入 oracle 的命令环境

    1
    docker exec -it oracle11g bash
  2. 切换到 oracle 数据库的 root 用户下(原密码为:helowin,修改为 123456)

    1
    2
    3
    4
    su root

    #修改 root 密码
    passwd
  3. 编辑 profile 文件,在末尾处添加如下 ORACLE 环境变量参数后保存退出「SID 不做修改」

    1
    2
    3
    4
    5
    vi /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
  4. 创建软连接

    1
    ln -s $ORACLE_HOME/bin/sqlplus /usr/bin
  5. 切换到 oracle 用户

    1
    su - oracle
  6. 登录 sqlplus

    1
    2
    sqlplus /nolog
    conn /as sysdba
  7. 连接测试「SIDhelowin

使用

1
2
3
4
5
6
7
8
docker exec -it oracle11g bash
su root
su - oracle

imp scm/scm file=scm.dmp full=y

sqlplus /nolog
conn /as sysdba