使用Docker容器運(yùn)行Oracle數(shù)據(jù)庫方式
在實(shí)際開發(fā)中,大部分時(shí)間可能都在開發(fā)、測(cè)試和驗(yàn)證工作,有些時(shí)候我們需要快速使用一個(gè)臨時(shí) oracle 數(shù)據(jù)庫來做開發(fā)或者驗(yàn)證工作,而又會(huì)因?yàn)?oracle 安裝麻煩而煩惱。
這種快速臨時(shí)性需求,我們可以選中使用 docker 容器的方式運(yùn)行一個(gè) oracle 數(shù)據(jù)庫,官方也給出了對(duì)應(yīng)的鏡像,包括 amd64 和 arm64 架構(gòu)的都有。
啟動(dòng)容器
- docker-compose.yml
services: oracle: image: container-registry.oracle.com/database/enterprise:19.3.0.0 container_name: oracledb ports: - 1521:1521 - 5500:5500 volumes: - ./oracle/oradata:/opt/oracle/oradata environment: TZ: Asia/Shanghai ORACLE_SID: orcl ORACLE_PWD: oracle123456 ENABLE_ARCHIVELOG: true logging: driver: "json-file" options: max-size: "1g" max-file: "20"
- 或者直接運(yùn)行腳本啟動(dòng)容器:
docker run -d --name oracledb \ -p 1521:1521 -p 5500:5500 \ -e ORACLE_SID=orcl \ -e ORACLE_PWD=oracle123456 \ -e ENABLE_ARCHIVELOG=true \ -v /opt/soft/oracle/oradata:/opt/oracle/oradata \ container-registry.oracle.com/database/enterprise:19.3.0.0
注意提前創(chuàng)建 oradata 目錄,并且為該目錄設(shè)置 chmod 777 權(quán)限,否則會(huì)出現(xiàn)容器掛載后寫入數(shù)據(jù)不正常的問題(如果是權(quán)限問題日志中會(huì)有權(quán)限問題的相關(guān)內(nèi)容)。
- 容器環(huán)境變量更多參數(shù)說明如下:
Parameters: --name: The name of the container (default: auto generated -p: The port mapping of the host port to the container port. Two ports are exposed: 1521 (Oracle Listener), 5500 (OEM Express) -e ORACLE_SID: The Oracle Database SID that should be used (default:ORCLCDB) -e ORACLE_PDB: The Oracle Database PDB name that should be used (default: ORCLPDB1) -e ORACLE_PWD: The Oracle Database SYS, SYSTEM and PDBADMIN password (default: auto generated) -e INIT_SGA_SIZE: The total memory in MB that should be used for all SGA components (optional) -e INIT_PGA_SIZE: The target aggregate PGA memory in MB that should be used for all server processes attached to the instance (optional) -e ORACLE_EDITION: The Oracle Database Edition (enterprise/standard, default: enterprise) -e ORACLE_CHARACTERSET: The character set to use when creating the database (default: AL32UTF8) -e ENABLE_ARCHIVELOG: To enable archive log mode when creating the database (default: false). Supported 19.3 onwards. -v /opt/oracle/oradata The data volume to use for the database. Has to be writable by the Unix "oracle" (uid: 54321) user inside the container If omitted the database will not be persisted over container recreation. -v /opt/oracle/scripts/startup | /docker-entrypoint-initdb.d/startup Optional: A volume with custom scripts to be run after database startup. For further details see the "Running scripts after setup and on startup" section below. -v /opt/oracle/scripts/setup | /docker-entrypoint-initdb.d/setup Optional: A volume with custom scripts to be run after database setup. For further details see the "Running scripts after setup and on startup" section below.
常用命令
連接到容器內(nèi)SQLPlus
- 通過使用以下命令之一從容器中執(zhí)行SQL*Plus命令,可以連接到Oracle數(shù)據(jù)庫服務(wù)器:
$ docker exec -it <oracle-db> sqlplus / as sysdba $ docker exec -it <oracle-db> sqlplus sys/<your_password>@<your_SID> as sysdba $ docker exec -it <oracle-db> sqlplus system/<your_password>@<your_SID> $ docker exec -it <oracle-db> sqlplus pdbadmin/<your_password>@<your_PDBname>
更改SYS用戶的默認(rèn)密碼
在容器的第一次啟動(dòng)時(shí),如果沒有提供,將為數(shù)據(jù)庫生成一個(gè)隨機(jī)密碼。在創(chuàng)建數(shù)據(jù)庫并且相應(yīng)的容器處于健康狀態(tài)后,用戶必須強(qiáng)制更改密碼。
使用docker exec命令,通過調(diào)用容器中的setPassword.sh腳本來更改這些帳戶的密碼。請(qǐng)注意,容器必須正在運(yùn)行。
- 例如:
$ docker exec <oracle-db> ./setPassword.sh <your_password>
瀏覽器登錄 Oracle EM Express
容器中的Oracle數(shù)據(jù)庫還配置了Oracle Enterprise Manager Database Express(EM Express)。
要訪問EM Express,請(qǐng)使用瀏覽器訪問以下URL:
https://localhost:5500/em/
注:其中 localhost 修改為自己實(shí)際的服務(wù)器 IP 地址。
點(diǎn)擊鏈接《官方文檔資料》 查閱官方資料關(guān)于容器創(chuàng)建后的更多詳細(xì)說明。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
docker 在容器外執(zhí)行某個(gè)容器內(nèi)的某個(gè)命令操作
這篇文章主要介紹了docker 在容器外執(zhí)行某個(gè)容器內(nèi)的某個(gè)命令操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-11-11docker啟動(dòng)rabbitmq以及使用方式詳解
RabbitMQ是一個(gè)由erlang開發(fā)的消息隊(duì)列,下面這篇文章主要給大家介紹了關(guān)于docker啟動(dòng)rabbitmq以及使用的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08總結(jié)Docker不適合部署數(shù)據(jù)庫的7大原因
在本篇文章里小編給大家整理一篇關(guān)于Docker不適合部署數(shù)據(jù)庫的7大原因,有興趣的朋友們可以參考學(xué)習(xí)下。2021-01-01Docker?Compose構(gòu)建Jenkins的實(shí)現(xiàn)
本文主要介紹了Docker?Compose構(gòu)建Jenkins的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06Docker容器無法被stop or kill問題的解決方法
這篇文章主要介紹了Docker容器無法被stop or kill問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09Docker Swarm實(shí)現(xiàn)服務(wù)的滾動(dòng)更新的示例代碼
這篇文章主要介紹了Docker Swarm實(shí)現(xiàn)服務(wù)的滾動(dòng)更新的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04Docker部署ELK7.3.0日志收集服務(wù)最佳實(shí)踐
這篇文章主要介紹了Docker部署ELK7.3.0日志收集服務(wù)最佳實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10