在centos7上使用Docker安裝oracle 11g

 

如果還沒安裝docker,可查看Centos7下安裝Docker(詳細安裝教程)

 

1、拉取 docker 鏡像:

[root@localhost ~]# docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
Using default tag: latest
latest: Pulling from helowin/oracle_11g
ed5542b8e0e1: Pull complete 
a3ed95caeb02: Pull complete 
1e8f80d0799e: Pull complete 
Digest: sha256:4c12b98372dfcbaafcd9564a37c8d91456090a5c6fb07a4ec18270c9d9ef9726
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g:latest

  該鏡像由阿里雲提供,比較大,可能需要下載一會

等待下載即可……

2、用 docker images 命令查看鏡像

[root@localhost ~]# docker images
REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE
registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g   latest              3fa112fd3642        3 years ago         6.85GB

運行鏡像

docker run -d -p 1521:1521 --name oracle registry.aliyuncs.com/helowin/oracle_11g

3、進入容器修改賬號密碼

3.1,檢查容器是否運行成功

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED              STATUS              PORTS                    NAMES
a151f9478f94        registry.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home/o…"   About a minute ago   Up 30 seconds       0.0.0.0:1521->1521/tcp   oracle

啓動oracle

[root@localhost ~]# docker start oracle

3.2,進入容器:docker exec -it oracle bash

[root@localhost ~]# docker exec -it oracle bash
[oracle@a151f9478f94 /]$

3.3,切換回root用戶

[oracle@a151f9478f94 /]$ exit
exit
[root@localhost ~]# 

3.4,編輯環境變量 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

(注意:按i進入編輯模式,輸入上述命令後,按ESC鍵退出編輯模式,再輸入:wq保存退出)

3.6,使得修改生效: 

[root@localhost ~]# source /etc/profile

3.7,進入容器(此處的id就是第一個命令下的id),加載一下用戶環境變量,進入容器後,自動是oracle用戶

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
a151f9478f94        registry.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home/o…"   3 hours ago         Up 3 hours          0.0.0.0:1521->1521/tcp   oracle

[root@localhost ~]# docker exec -it a151f9478f94 /bin/bash
[oracle@a151f9478f94 /]$ source ~/.bash_profile

 

[oracle@a151f9478f94 /]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Sep 4 14:44:44 2019
Copyright (c) 1982, 2009, Oracle.  All rights reserved.

 

SQL> conn / as  sysdba                                ## 使用sysdba 連接oracle,最大權限,os認證,只能在本機上登陸使用。
Connected.
SQL> alter user system identified by system;          ## 修改用戶 system 的密碼爲 oracle ,可以自定義
User altered.
SQL> alter user sys identified by sys;
User altered.
SQL> create user ETS identified by ETS;
User created.
SQL> grant connect,resource,dba to ETS ;
Grant succeeded.
SQL> exit      ##退出編輯SQL
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@a151f9478f94 /]$ exit    ##回到root用戶
exit
[root@localhost ~]# 

4.連接 賬號system密碼system服務名helowin

用Navicat連接

用plsql連接

爲方便plsql連接,可在本地instantclient_11_2配置tnsnames.ora文件

LS =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.116.129)(PORT = 1521))
    )
    (CONNECT_DATA =
       (SERVER = DEDICATED)
      (SERVICE_NAME = helowin)

    )
  )

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章