美文网首页Java从入门到放弃
MacOS下使用Docker安装Oracle 11g

MacOS下使用Docker安装Oracle 11g

作者: Deque | 来源:发表于2019-01-08 19:53 被阅读0次

    1.下载并安装Docker

    • 第一步:下载docker(500M左右)
      下载连接:https://download.docker.com/mac/stable/Docker.dmg

    • 第二步:点击Docker.dmg安装即可

    • 第三步:打开终端,输入命令docker version查看docker版本,看是否安装成功:

     Client: Docker Engine - Community
     Version:           18.09.2
     API version:       1.39
     Go version:        go1.10.8
     Git commit:        6247962
     Built:             Sun Feb 10 04:12:39 2019
     OS/Arch:           darwin/amd64
     Experimental:      false
    Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
    

    能得到上面的信息,证明docker已经安装就绪!

    • 第四步:在Launchpad找到Docker图标,点击并启动


    2.下载并安装Oracle 11g

    第一步:使用docker search docker-oracle-xe-11g命令,搜索docker远程仓库的镜像:

    终端输出结果:

    AME                                 DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    docker                               Docker in Docker!                               1024                [OK]
    oraclelinux                          Official Docker builds of Oracle Linux.         572                 [OK]
    jaspeen/oracle-11g                   Docker image for Oracle 11g database            98                                      [OK]
    carloscastillo/rgt-oracle-xe-11g     This is a simple image based on sath89/oracl…   10                                      [OK]
    deepdiver/docker-oracle-xe-11g                                                       8                                       [OK]
    pengbai/docker-oracle-xe-11g-r2      oracle xe 11g r2 with sql initdb and web con…   6                                       [OK]
    arahman/docker-oracle-xe-11g         phusion/baseimage based spin off of alexei-l…   5                                       [OK]
    oracleinanutshell/oracle-xe-11g                                                      5
    ukhomeofficedigital/oracle-xe-11g    Oracle Database Express Edition 11g Container   4                                       [OK]
    rafaelri/docker-oracle-xe-11g        Fork from wnameless/docker-oracle-xe-11g        3                                       [OK]
    ignatov/docker-oracle-xe-11g         Dockerfile of Oracle Database Express Editio…   2                                       [OK]
    christophesurmont/oracle-xe-11g      Clone of the wnameless/oracle-xe-11g.           1
    epiclabs/docker-oracle-xe-11g        Customized Oracle XE 11g build for CI and de…   1                                       [OK]
    rdehuyss/docker-oracle-xe-11g        Oracle Express 11g R2 on Ubuntu 14.04.2 LTS     0                                       [OK]
    kikicarbonell/docker-oracle-xe-11g   Docker image of Oracle Database Express Edit…   0                                       [OK]
    zigac/docker-oracle-xe-11g           Oracle xe 11g                                   0                                       [OK]
    deradam/docker-oracle-xe-11g         Oracle Express Edition 11g Release 2 on Ubun…   0
    jeromefromcn/docker-oracle-xe-11g    docker-oracle-xe-11g                            0                                       [OK]
    webdizz/oracle-xe-11g-sa             This is a simple image based on sath89/oracl…   0                                       [OK]
    gswteam/docker-oracle-xe-11g         Oracle XE 11g                                   0                                       [OK]
    ambientdocker/docker-oracle-xe-11g   oracle-xe-11g image                             0                                       [OK]
    deadok22/docker-oracle-xe-11g        docker-oracle-xe-11g                            0
    konnecteam/docker-oracle-xe-11g      Fork of https://github.com/wnameless/docker-…   0                                       [OK]
    lynxsolutions/docker-oracle-xe-11g   docker-oracle-xe-11g                            0                                       [OK]
    nguoianphu/docker-oracle-xe-11g      Oracle Express Edition 11g Release 2 on Ubun…   0                                       [OK]
    

    第二步:下载oracle 11g 输入如下命令:(笔者电脑只有128G,所以此处,我使用的是阉割版的docker-oracle-xe-11g,大家可根据自己的口味选取)

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

    命令解释:
    pull 是Docker 容器的拉取命令
    alexeiled/docker-oracle-xe-11g 为镜像的完整名字

    终端消息:显示下载的状态

    Using default tag: latest
    latest: Pulling from alexeiled/docker-oracle-xe-11g
    759d6771041e: Pulling fs layer
    8836b825667b: Pulling fs layer
    c2f5e51744e6: Pulling fs layer
    a3ed95caeb02: Pull complete
    787648ea7b44: Pull complete
    46f20000ce59: Pull complete
    2a190e47ca3f: Pull complete
    f8043f470a85: Pull complete
    0f6111a00dd6: Pull complete
    deacbfda2b11: Pull complete
    6eb979936fa3: Pull complete
    5194f2505f56: Pull complete
    a63e30990791: Pull complete
    994cf2ce199e: Pull complete
    5eba4c64e295: Pull complete
    01227e9ca0a6: Pull complete
    076b6fa27478: Pull complete
    d6407a7221b5: Pull complete
    bbc5a28168da: Pull complete
    dd783b45fa26: Pull complete
    0a686089bc7e: Pull complete
    73fac5e681c5: Pull complete
    afaede9e60b1: Pull complete
    a5d9cef8ef2a: Pull complete
    32bcfcf46e45: Pull complete
    aa896f927427: Pull complete
    f99ab5aba6e5: Pull complete
    Digest: sha256:35448e199115012a742ff9098da3287c666ce52d18efcf4658e0437892ed3ee6
    Status: Downloaded newer image for alexeiled/docker-oracle-xe-11g:latest
    

    下载完成后,启动镜像为容器:

    aiuiot:~ root# docker run -h "oracle" --name "oracle" -d -p 49160:22 -p 49161:1521 -p 49162:8080 alexeiled/docker-oracle-xe-11g
    

    3、进入容器并启动Oracle

    第一步:在终端中执行命令进入容器:

    aiuiot:~ root# docker exec -it 0677fc709d77 /bin/bash
    

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

    aiuiot:~ root# docker ps
    CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORTS                                                                     NAMES
    0677fc709d77        alexeiled/docker-oracle-xe-11g   "/bin/sh -c /start.sh"   5 minutes ago       Up 5 minutes        0.0.0.0:49160->22/tcp, 0.0.0.0:49161->1521/tcp, 0.0.0.0:49162->8080/tcp   oracle
    aiuiot:~ root# docker exec -it 0677fc709d77 /bin/bash
    

    进入容器后,输入sqlplus system/oracle命令登录:

    root@oracle:/# sqlplus system/oracle
    
    SQL*Plus: Release 11.2.0.2.0 Production on Tue Jan 8 08:46:58 2019
    
    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
    

    4.创建用户并分配权限

    查看用户:

    SQL> select username,password from dba_users;
    
    USERNAME               PASSWORD
    ------------------------------ ------------------------------
    SYS
    ANONYMOUS
    SYSTEM
    APEX_PUBLIC_USER
    APEX_040000
    XS$NULL
    OUTLN
    FLOWS_FILES
    MDSYS
    CTXSYS
    XDB
    
    USERNAME               PASSWORD
    ------------------------------ ------------------------------
    HR
    
    12 rows selected.
    

    创建新用户:用户名为 deque 密码 123

    SQL> create user deque identified by 123;
    
    User created.
    

    输入命令select * from all_users;查看是否有用户deque:

    SQL> select * from all_users;
    
    USERNAME              USER_ID CREATED
    ------------------------------ ---------- ---------
    XS$NULL                2147483638 28-AUG-11
    DEQUE                      48 08-JAN-19
    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
    
    USERNAME              USER_ID CREATED
    ------------------------------ ---------- ---------
    SYSTEM                  5 28-AUG-11
    SYS                 0 28-AUG-11
    
    13 rows selected.
    

    4.1 给新创建的用户授权

    给用户deque赋予connect,resource角色,这俩角色含有许多权限.
    connect:是保证该用户能连接数据库;
    resource:是该用户可以使用数据库资源。

    输入命令grant connect,resource to deque;

    SQL> grant connect,resource to deque;
    
    Grant succeeded.
    

    连接到

    5.删除用户

    因为oracle数据库是基于用户去创建表,如果想删除自己创建的用户,可用命令是:drop user deque;
    注意:分号不可少,且当前连接数据库的用户必须具有删除用户权限(如sys)。

    6.在Docker 停止或启动服务

    • docker stop oracle 停止oracle

      停止oracle操作
    • docker start oracle 启动oracle

      启动oracle操作

    7、常用命令

    • docker ps 查看正在运行的容器

    常见问题:

    1、Docker未正常启动

    命令行提示信息:

    Cannot connect to the Docker daemon at unix:
    ///var/run/docker.sock. Is the docker daemon running?
    

    解决:启动你的Docker

    2、未正常拉取镜像,仓库不存在或者需要登录
    Using default tag: 
    latest Error response from daemon: 
    pull access denied for alexeiled/docker-oracle-xe-11g, 
    repository does not exist or may require 'docker login'
    

    错误提示:使用默认标记:

    来自守护程序的最新错误响应:
    拒绝对 alexeled/docker-oracle-xe-11g 的拉入访问,
    存储库不存在,或者可能需要“Docker登录”

    解决方案:
    ① 在终端输入登录命令docker login登录docker账号

    Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
    Username: aiuiot
    Password:
    Login Succeeded
    

    ② 使用搜索命令docker search docker-oracle-xe-11g搜索仓库有用的镜像,并拉取

    补充内容:

    如何与SQL管理工具链接

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

    端口映射情况

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

    编辑链接

    相关文章

      网友评论

        本文标题:MacOS下使用Docker安装Oracle 11g

        本文链接:https://www.haomeiwen.com/subject/xblbrqtx.html