基於 Docker 快速搭建 Oracle 開發環境
阿新 • • 發佈:2018-05-18
docker Oracle
要給開發人員搭建 Oracle 測試環境,準備基於 Docker 構建,同時建立一個 Docker 私有倉庫,誰需要就讓他裝一個 Docker,才從這私有倉庫 pull 鏡像即可。
環境如下:
CentOS 7
docker-ce-18.03.1.ce-1.el7.centos.x86_64
Oracle 12c
安裝Docker
# step 1: 安裝必要的一些系統工具 yum install -y yum-utils device-mapper-persistent-data lvm2 # Step 2: 添加軟件源信息 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # Step 3: 更新並安裝Docker-CE yum makecache && yum -y install docker-ce # Step 4: 開啟Docker服務 systemctl start docker 配置加速器請參考阿裏雲官方文檔。 https://yq.aliyun.com/articles/29941
搜索並下載Oracle鏡像
列出收藏數大於100的鏡像 [root@Docker ~]# docker search -s 100 oracle Flag --stars has been deprecated, use --filter=stars=3 instead NAME DESCRIPTION STARS OFFICIAL AUTOMATED oraclelinux Official Docker builds of Oracle Linux. 451 [OK] frolvlad/alpine-oraclejdk8 The smallest Docker image with OracleJDK 8 (… 303 [OK] sath89/oracle-12c Oracle Standard Edition 12c Release 1 with d… 296 [OK] alexeiled/docker-oracle-xe-11g This is a working (hopefully) Oracle XE 11.2… 252 [OK] sath89/oracle-xe-11g Oracle xe 11g with database files mount supp… 185 [OK] # pull第三個鏡像 # docker pull sath89/oracle-12c
運行鏡像
#-P, 在容器中任何需要的網絡端口都映射到主機。即將Docker鏡像中的Oracle 1521端口映射到宿主機。 #-v 把docker 容器中某目錄的數據 加載到 宿主機的某個目錄。即將docker Oracle鏡像的數據存儲到/data/db 下 docker run -d -p 8080:8080 -p 1521:1521 -v /data/db/:/u01/app/oracle sath89/oracle-12c 啟動速度較慢,我們可以去查看日誌 # docker logs -f 032d6b2097e8cf3d4dfc3bf173a229bda0a5c8a8a51434299274c652698964a7 Database not initialized. Initializing database. Starting tnslsnr Copying database files 1% complete 3% complete 11% complete 18% complete 26% complete 37% complete Creating and starting Oracle instance 40% complete 45% complete 50% complete 55% complete 56% complete 60% complete 62% complete Completing Database Creation 66% complete 70% complete 73% complete 85% complete 96% complete 100% complete Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/xe.log" for further details. Configuring Apex console Database initialized. Please visit http://#containeer:8080/em http://#containeer:8080/apex for extra configuration if needed Starting web management console PL/SQL procedure successfully completed. Starting import from ‘/docker-entrypoint-initdb.d‘: found file /docker-entrypoint-initdb.d//docker-entrypoint-initdb.d/* [IMPORT] /entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* Import finished Database ready to use. Enjoy! ;) 查看進程 [root@Docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3ceb1ae8637e sath89/oracle-12c "/entrypoint.sh " 10 seconds ago Up 4 seconds 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp unruffled_kare
配置Oracle
接下來進入鏡像的 bash 做進一步操作。
[root@Docker ~]# docker exec -it 3ceb1ae8637e /bin/bash
root@3ceb1ae8637e:/#
root@3ceb1ae8637e:/# ss -nlpt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:42983 *:*
LISTEN 0 128 *:8080 *:*
LISTEN 0 128 *:1521 *:*
接下來登陸數據庫
# sqlplus system/oracle@//localhost:1521/xe
SQL*Plus: Release 12.1.0.2.0 Production on Fri May 18 09:27:11 2018
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Last Successful login time: Fri May 18 2018 09:26:42 +00:00
Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
SQL> show parameter service_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string xe
SQL>
pl/sql 連接 Oracle
下載一個plsql development,還有一個Oracle客戶端
新建下面3個環境變量
NLS_LANG
AMERICAN_AMERICA.AL32UTF8
ORACLE_HOME
D:\instantclient_11_2
TNS_ADMIN
d:\instantclient_11_2\network\ADMIN
解壓oracle客戶端以後,新建 network\ADMIN 文件夾
新建文件 tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.153.32)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.site)
)
)
基於 Docker 快速搭建 Oracle 開發環境