美文网首页运维那些事
Docker 安装Oracle12c

Docker 安装Oracle12c

作者: Bruce基 | 来源:发表于2020-03-30 12:31 被阅读0次

    查询docker镜像

      docker search oracle
    

    结果如下:

    [root@VM_0_2_centos app]# docker search oracle
    NAME                                  DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    oraclelinux                           Official Docker builds of Oracle Linux.         641                 [OK]
    jaspeen/oracle-11g                    Docker image for Oracle 11g database            155                                     [OK]
    oracleinanutshell/oracle-xe-11g                                                       88
    oracle/openjdk                        Docker images containing OpenJDK Oracle Linux   60                                      [OK]
    oracle/graalvm-ce                     GraalVM Community Edition Official Image        59                                      [OK]
    absolutapps/oracle-12c-ee             Oracle 12c EE image with web management cons…   38
    araczkowski/oracle-apex-ords          Oracle Express Edition 11g Release 2 on Ubun…   29                                      [OK]
    oracle/nosql                          Oracle NoSQL on a Docker Image with Oracle L…   23                                      [OK]
    bofm/oracle12c                        Docker image for Oracle Database                23                                      [OK]
    datagrip/oracle                       Oracle 11.2 & 12.1.0.2-se2 & 11.2.0.2-xe        18                                      [OK]
    truevoly/oracle-12c                   Copy of sath89/oracle-12c image (https://git…   13
    oracle/weblogic-kubernetes-operator   Docker images containing the Oracle WebLogic…   11
    openweb/oracle-tomcat                 A fork off of Official tomcat image with Ora…   8                                       [OK]
    iamseth/oracledb_exporter             A Prometheus exporter for Oracle modeled aft…   3
    softwareplant/oracle                  oracle db                                       2                                       [OK]
    paulosalgado/oracle-java8-ubuntu-16   Oracle Java 8 on Ubuntu 16.04 LTS.              2                                       [OK]
    18fgsa/oracle-client                  Hosted version of the Oracle Container Image…   2
    roboxes/oracle7                       A generic Oracle Linux 7 base image.            1
    publicisworldwide/oracle-core         This is the core image based on Oracle Linux…   1                                       [OK]
    bitnami/oraclelinux-runtimes          Oracle Linux runtime-optimized images           0                                       [OK]
    bitnami/oraclelinux-extras            Oracle Linux base images                        0                                       [OK]
    arm64v8/oraclelinux                   Official Docker builds of Oracle Linux.         0
    toolsmiths/oracle7-test                                                               0
    pivotaldata/oracle7-test              Oracle Enterprise Linux (OEL) image for GPDB…   0
    amd64/oraclelinux                     Official Docker builds of Oracle Linux.         0
    

    下载镜像

    [root@VM_0_2_centos app]# docker pull docker.io/truevoly/oracle-12c
    

    查看镜像

    下载完成使用命令查看镜像

    docker images
    

    结果:

    [root@VM_0_2_centos app]# docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    mysql                 5.7                 84164b03fa2e        3 weeks ago         456MB
    truevoly/oracle-12c   latest              21789d4d876f        13 months ago       5.7GB
    [root@VM_0_2_centos app]#
    

    创建备份数据存放目录

    mkdir /usr/local/oracle/data_temp  && chmod 777 /usr/local/oracle/data_temp
    

    创建一个文件目录,用于挂载到容器内,做oracle数据备份时数据存放的位置,保证备份数据不丢失。

    启动

     docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /usr/local/oracle/data_temp:/home/oracle/data_temp   -v /etc/localtime:/etc/localtime:ro  --name orac truevoly/oracle-12c
    

    结果:

    [root@VM_0_2_centos app]#  docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /usr/local/oracle/data_temp:/home/oracle/data_temp  --name orac truevoly/oracle-12c
    71827b1a5decb9a76720db1ace264117fe31f9e2e0ebeb43708572d57c86ee3b
    [root@VM_0_2_centos app]#
    

    查看安装进度

    docker logs -f 71827b1a5decb9a76720db1ace264117fe31f9e2e0ebeb43708572d57c86ee3b
    

    结果:

    [root@VM_0_2_centos data_temp]# docker logs -f 6f1c2f5372b5b60148d4be3a47d41d527fbbb1b1ae0c6a1090fd8b4472a48a4a
    Database not initialized. Initializing database.
    Starting tnslsnr
    Copying database files
    1% complete
    3% complete
    11% complete
    

    安装完成则Ctrl+C退出。

    获取运行的容器

    docker ps
    

    结果:

    [root@VM_0_2_centos data_temp]# docker ps
    CONTAINER ID        IMAGE                 COMMAND                          CREATED             STATUS              PORTS                                              NAMES
    6f1c2f5372b5        truevoly/oracle-12c   "/entrypoint.sh "        9 minutes ago       Up 9 minutes        0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp   orac
    d9fe468f1d89        mysql:5.7             "docker-entrypoint.s…"   2 hours ago         Up 17 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp                mysql
    

    运行id为6f1c2f5372b5容器

    docker exec -it 6f1c2f5372b5 /bin/bash
    

    进入Oracle

    sqlplus system/oracle@//localhost:1521/xe
    

    结果:

    root@6f1c2f5372b5:/# sqlplus system/oracle@//localhost:1521/xe
    
    SQL*Plus: Release 12.1.0.2.0 Production on Fri Mar 27 11:15:50 2020
    
    Copyright (c) 1982, 2014, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit     Production
    
    SQL>
    

    成功。使用pl/sql连接时,xe是这个镜像默认的服务

    进入数据库

    sqlplus /nolog
    connect sys as sysdba; #密码:oracle

    查看oracle现在的状态 ,状态为 OPEN 则正常,表

    select status from v$instance;   
    
    
    alter user system identified by oracle;    ## 修改用户 system 的密码为 oracle ,可以自定义
    

    创建账户

    create user 账户 identified by 密码;
    
    (create user testlu identified by LuQAZwsx;)
    
    GRANT CONNECT, RESOURCE, DBA TO testlu;
    

    创建用户名为test密码为LuQAZwsx的账户。

    给用户授予权限

    grant create session to testlu;
    grant connect,resource to testlu;
    

    查询所有账户

    SELECT * FROM ALL_USERS;
    

    使用以下命令获取安装的数据库的服务名称。

    select value from v$parameter where name='service_names';
    

    结果:

    SQL> select value from v$parameter where name='service_names';
    
    VALUE
    --------------------------------------------------------------------------------
    xe
    

    可以使用客户端链接了:
    账号:test
    密码:123456
    端口:1521
    服务名称:xe

    命令操作

    --首先查询一下用户的profile的类型
    select username ,profile from dba_users;
    
    --查看制定概要文件(默认为DEFAULT)的密码有效期:
    select  * from dba_profiles where profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';
    
    --然后将密码的有效期有180天设置为“无限制”;
    ALTER PROFILE  DEFAULT  LIMIT PASSWORD_LIFE_TIME UNLIMITED;
    
    -- 修改密码
    alter user hysjy identified by 123456;
    
    -- 查询所有用户
    SELECT * FROM ALL_USERS;
    
    
    -- 创建账户
    
    create user hysjy identified by 123456;
    GRANT CONNECT, RESOURCE, DBA TO hysjy;
    
    
    --  给用户授予权限
    grant create session to hysjy;
    grant connect,resource to hysjy;
    
    
    -- 解除锁定
    alter user hysjy account unlock;
    
    commit;
    

    说明

    本文只做学习参考,如有任何不准确的地方欢迎指正。

    我的邮箱:

    • lulongji2011@163.com

    相关文章

      网友评论

        本文标题:Docker 安装Oracle12c

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