zoukankan      html  css  js  c++  java
  • Lab1: Running Oracle in Docker

    1.安装准备

    1.1. Docker

    Download and Install Docker Desktop

    https://www.docker.com/products/docker-desktop

    1.2. SQL Developer

    Download SQL Developer and extract to a folder (e.g. d:SQLDevelooper)

    https://www.oracle.com/tools/downloads/sqldev-downloads.html

    There may be an issue about small font size when running SQL Developer under windows 10. Refer to thefollowing page for the solution.

    https://stackoverflow.com/questions/50138830/how-to-increase-size-of-gui-font-everything-of-oracle-sqldeveloper-18-1.

    1.3.SQL Plus

    Download and Install SQL Plus

    https://www.oracle.com/hk/database/technologies/instant-client/downloads.html

    Download the basic package and SQL*Plus Package and unzip and put the content of the two zipped folder in same folder (e.g. d:sqlplus).

    Alternatively, you can also install the Oracle Database Express 18C.

    https://www.oracle.com/database/technologies/xe-downloads.html

    In this case, both Oracle Database Server and SQL Plus will be installed and it will consume around 10GB of storage in your hard drive.

    1.4.Docker基本操作

    1.4.1 把docker镜像上传到Docker Hub中

    docker pull kamiljedrzejuk/oracle18c-xe-initialized:latest

     可能会遇到网络问题,无法上传,这个时候找到.docker文件夹中的daemon.json文件中加入一行镜像设置

    "registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]

    1.4.2. 测试一下运行

    docker run hello-world

     显示所有的docker镜像

    docker image ls

    1.4.3.下载ubuntu镜像,并尝试进入看看

    docker pull ubuntu

    docker run ubuntu
    docker run -it ubuntu

     退出

    1.4.4.查看所有docker的容器,测试基本命令

    docker ps -a

    docker container ls -a

     查看

     让容器运行

    docker run -it ubuntu

     让容器停止运行,用这个容器名字的前几位就行(prefix)

    docker container stop 0e0d 15a9

     移除容器

    docker container rm 0e0d 15a9

     

    1.4.5.测试安装nginx

    docker run -p 2008:80 nginx

     

     

    docker run -d -p 20080:80 --name ws1 nginx
    docker run -d -p 20081:80 --name ws2 nginx
    docker run -d -p 20082:80 --name ws3 nginx
    docker exec ws1 /bin/bash -c "echo 'This is server 1' > /usr/share/nginx/html/index.html"
    docker exec ws2 /bin/bash -c "echo 'This is server 2' > /usr/share/nginx/html/index.html"
    docker exec ws3 /bin/bash -c "echo 'This is server 3' > /usr/share/nginx/html/index.html"

     

     

    docker volume prune

    1.4.6查看所有volume

    docker volume ls

     删除所有

    docker volume prune

    2.在Docker上运行Oracle

    打开Oracle SQL Developer

     运行docker,设定名称,版本,端口,路径

    docker run --name oracle-xe -d -p 51521:1521 -v D:ProjectsCoursedocker_share:/share kamiljedrzejuk/oracle18c- xe-initialized

     

     在Linux Shell中,首先在oracle用户的.bashrc文件中添加SQL Plus可执行文件的路径

    echo "export PATH=$PATH:$ORACLE_HOME/bin/">/home/oracle/.bashrc

    将用户更改为“ oracle”

    su oracle

    运行以下命令以验证Oracle侦听器正在侦听连接

    lsnrctl status

     使用sqlplus连接到数据库。 将“系统”用户的密码更改为“ 12345”

    sqlplus / as sysdba

    alter user system identified by "12345";

     

    exit;

    3. 使用SQL Plus和SQL Developer连接到Oracle

    在主机上,使用sqlplus连接到oracle

    sqlplus system/12345@localhost:51521/XE

     连接

    select * from all_users;

      

    4.开启HR账户

    查看账户名称

    show con_name

    alter session set container = xepdb1;

     

     

    select username, account_status from dba_users where username='HR';

     

     解锁HR账户

    alter user hr identified by hr account unlock;

     

    在SQL Plus内,如下所述按HR连接

    或退出,改为

    sqlplus hr/hr@localhost:51521/xepdb1

     尝试运行

    select table_name from user_tables ; 
    describe jobs;

     

    要在Docker容器外壳内部使用sqlplus命令行连接到HR帐户,可以使用以下命令

    sqlplus hr/hr@XEPDB1

    要使用主机中的sqlplus命令行连接到HR帐户,可以使用以下命令

    sqlplus hr/hr@localhost:51521/XEPDB1

    要在SQL Developer中连接到XEPDB PDB,请指定XEPDB1作为服务名称(而不是SID)

    select * from employees;

    5.移除Docker容器

    使用docker container ls命令检查容器ID

    使用容器ID(或容器ID的前缀)停止并删除容器

    docker rm -f [container_id]

    6.将数据保留在Oracle DB中

    停止并删除容器后,Docker容器文件系统中的任何更改(例如,对数据库表所做的更改)都将消失

    docker volume create --driver local --opt type=none --opt device=d:/oracle_mount --opt o=bind oracle_vol
  • 相关阅读:
    Access sql语句创建表及字段类型
    30条HTML代码编写指南 for入门者
    21 个HTML网页转RSS Feeds的工具
    51 个漂亮的电子商务网站设计分享
    如何更改列表项前的New标记的天数设置(daystoshownewicon )
    如何使Layouts里的页面应用站点母板页
    SPCAMLEditor使用系列(2)利用SPCAMLEditor,实现列表顺序号。
    在SharePoint中使用自定义的服务器控件(Web Control)
    开发支持三级目录的导航菜单
    CAML查询时用户类型字段的处理
  • 原文地址:https://www.cnblogs.com/ak918xp/p/13834975.html
Copyright © 2011-2022 走看看