数据库
首页 > 数据库> > Docker安装Oracle 11g(以Mac OS为例)

Docker安装Oracle 11g(以Mac OS为例)

作者:互联网

  1. 安装Docker

    1. 地址:https://www.docker.com/products/docker-desktop

      image-20210306142519601
    2. 下载完成后,我们得到Docker.dmg文件,点击拖动到application文件夹进行安装。

      image-20210306142820692
  2. 注册一个Docker账号

    地址:https://www.docker.com/

    注意:如果不登录Docker,使用docker pull命令是可能会报错
    Error response from daemon: pull access denied for alexeiled/docker-oracle-xe-11g, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
    
  3. 安装完成后,你就可以在launchpad中看到Docker图标,点击打开;并且点击右上角的Sing In进行登录。

    image-20210306144324507
  4. Docker 设置国内镜像源

    image-20210306144807557
    "registry-mirrors": [
        "https://md4nbj2f.mirror.aliyuncs.com"
    ]
    
    1. 阿里云容器 服务:https://cr.console.aliyun.com
    2. 中国科技大学:https://docker.mirrors.ustc.edu.cn
    3. Docker中国区官方镜像:https://registry.docker-cn.com
    
    注意:本人使用Docker中国区官方镜像源,使用docker pull命令会报错
    Error response from daemon: pull access denied for alexeiled/docker-oracle-xe-11g, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
    
  5. 拉取Oracle镜像

    1. 打开终端,登录Docker:

      docker login
      
      Authenticating with existing credentials...
      Login Succeeded
      
    2. 拉取Oracle 11g镜像:

    docker pull alexeiled/docker-oracle-xe-11g

    
    ![](https://www.icode9.com/i/l/?n=20&i=blog/2071466/202103/2071466-20210306155311063-999972894.png)
    
    
  6. 下载完成后,启动镜像为容器

    docker run -h "oraclehost" --name "oracle" -d -p 1521:1521 alexeiled/docker-oracle-xe-11g
    
    -h "oraclehost":指定容器的hostname为oracle
    --name "oracle":将容器命名为oracle
    -d:在后台运行
    -p: 端口映射,格式为:主机(宿主)端口:容器端口
    
  7. 进入容器并启动Oracle

    1. 在终端中执行命令进入容器

      docker exec -it c816db8e8d52 /bin/bash
      
      root@oraclehost:/#
      

      其中c816db8e8d52是容器id,可使用docker ps命令获得

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c816db8e8d52 alexeiled/docker-oracle-xe-11g "/bin/sh -c /start.sh" 10 minutes ago Up 10 minutes 0.0.0.0:1521->1521/tcp, 8080/tcp oracle
```

  1. 进入容器后,使用如下命令登录:(使用普通身份登陆)

    sqlplus system/oracle
    
    root@oraclehost:/# sqlplus system/oracle
    
    SQL*Plus: Release 11.2.0.2.0 Production on Sat Mar 6 07:20:06 2021
    
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    
    ERROR:
    ORA-28002: the password will expire within 7 days
    
    
    
    Connected to:
    Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
    
    SQL>
    
  2. 查看数据库用户:

    SQL> select * from all_users;
    
    USERNAME			  USER_ID CREATED
    ------------------------------ ---------- ---------
    XS$NULL 		       2147483638 28-AUG-11
    APEX_040000			       47 28-AUG-11
    APEX_PUBLIC_USER		       45 28-AUG-11
    FLOWS_FILES			       44 28-AUG-11
    HR				       43 28-AUG-11
    MDSYS				       42 28-AUG-11
    ANONYMOUS			       35 28-AUG-11
    XDB				       34 28-AUG-11
    CTXSYS				       32 28-AUG-11
    OUTLN					9 28-AUG-11
    SYSTEM					5 28-AUG-11
    
    USERNAME			  USER_ID CREATED
    ------------------------------ ---------- ---------
    SYS					0 28-AUG-11
    
    12 rows selected.
    
    SQL>
    
  3. 使用Navicat创建连接

    1. 使用docker container ls命令,查看端口情况

      docker container ls
      
      docker container ls
      CONTAINER ID   IMAGE                            COMMAND                  CREATED          STATUS          PORTS                              NAMES
      c816db8e8d52   alexeiled/docker-oracle-xe-11g   "/bin/sh -c /start.sh"   35 minutes ago   Up 35 minutes   0.0.0.0:1521->1521/tcp, 8080/tcp   oracle
      

      可以看到1521端口被映射到容器的1521端口,1521被映射带容器的1521端口。我们访问本机的1521端口即可在SQL管理工具访问。

      image-20210306152751036

      image-20210306152834337

  4. 修改system密码

    alter user system identified by 您的新密码;
    
  5. 退出Oracle

    exit
    
    SQL> exit
    Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
    root@oraclehost:/#
    
  6. 关闭oracle服务和开启oracle服务

    docker stop oracle
    docker start oracle
    

标签:11,11g,AUG,为例,28,Mac,1521,oracle,docker
来源: https://www.cnblogs.com/hetongxue/p/14491039.html