使用Docker制作Python環(huán)境連接Oracle鏡像
Python連接Oracle本地測試
依賴安裝準備
Python、鏈接Oracle需要Python依賴和本地Oracle客戶端,測試環(huán)境Oracle版本12.1.0.2.0,開發(fā)和測試環(huán)境為linux,先安裝linux客戶端,選擇zip解壓免安裝版本

解壓到某個目錄
unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
解壓后新建/network/admin文件夾
cd /opt/instantclient_12_1/ mkdir -p /network/admin
修改root用戶的環(huán)境變量
vim /etc/profile export ORACLE_HOME=/opt/instantclient_12_1 export TNS_ADMIN=$ORACLE_HOME/network/admin export NLS_LANG="SIMPLIFIED CHINESE_CHINA".ZHS16GBK export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss" export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH export PATH=$ORACLE_HOME:$PATH
source /etc/profile
下一步安裝Python依賴
pip install cx_Oracle
Python腳本測試
root@ubuntu:~# python
Python 3.7.6 (default, Jan 8 2020, 19:59:22)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle as cx
>>> con = cx.connect('username', 'password', 'xxx.xxx.xxx.xxx:1521/ORCL')
>>> cursor = con.cursor()
>>> cursor.execute("select * from emp")
<cx_Oracle.Cursor on <cx_Oracle.Connection to c##als770ud1@192.168.61.79:1521/ORCL>>
>>> cursor.fetchall()
[(1, '張三'), (2, '李四'), (3, '王五')]
>>>
制作Docker鏡像
創(chuàng)建Dockerfile
touch Dockerfile # 將oracle本地客戶端文件夾移動到同一級目錄 cp -r /opt/instantclient_12_1/ ./
Dockerfile
FROM python:3.7 ENV PIPURL "https://mirrors.aliyun.com/pypi/simple/" RUN pip install cx_Oracle --default-timeout=1000 COPY instantclient_12_1 /opt/instantclient_12_1 ENV ORACLE_HOME=/opt/instantclient_12_1 ENV TNS_ADMIN=$ORACLE_HOME/network/admin ENV NLS_LANG="SIMPLIFIED CHINESE_CHINA".ZHS16GBK ENV NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss" ENV LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH ENV PATH=$ORACLE_HOME:$PATH RUN apt-get update RUN apt-get install -y libaio1
鏡像構建
docker build -t xiaogp/python_oraqcle:v3 .
構建完成
root@ubuntu:~/docker/PYTHON_ORACLE# docker images REPOSITORY TAG IMAGE ID CREATED SIZE xiaogp/python_oraqcle v3 bb0100d9c3f5 39 seconds ago 1.1GB
啟動鏡像測試一下
root@ubuntu:~/docker/PYTHON_ORACLE# docker run -it bb0100d9c3f5 /bin/bash
root@fbff875ba4d5:/# python
Python 3.7.9 (default, Jan 12 2021, 17:26:22)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle as cx
>>> con = cx.connect('username', 'password', 'xxx.xxx.xxx.xxx:1521/ORCL')
>>> cursor = con.cursor()
>>> cursor.execute("select * from emp")
<cx_Oracle.Cursor on <cx_Oracle.Connection to c##als770ud1@192.168.61.79:1521/ORCL>>
>>> cursor.fetchall()
[(1, '張三'), (2, '李四'), (3, '王五')]可以鏈接,制作結束
以上就是使用Docker制作Python環(huán)境連接Oracle鏡像的詳細內容,更多關于docker鏡像Python環(huán)境連接Oracle的資料請關注腳本之家其它相關文章!
相關文章
python實現(xiàn)不同文件夾下的函數(shù)相互調用
這篇文章主要介紹了python實現(xiàn)不同文件夾下的函數(shù)相互調用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08
使用Python合成圖片的實現(xiàn)代碼(圖片添加個性化文本,圖片上疊加其他圖片)
這篇文章主要介紹了使用Python合成圖片的實現(xiàn)代碼(圖片添加個性化文本,圖片上疊加其他圖片),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
基于python traceback實現(xiàn)異常的獲取與處理
這篇文章主要介紹了基于python traceback實現(xiàn)異常的獲取與處理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-12-12

