1.docker第一次安裝失敗,下一次會提示同名的容器已經存在,解決辦法:html
docker container ls -alinux
根據上面執行的接口,選擇一個containerid,而後帶入到下面的命令sql
docker container rm -f containeriddocker
2.安裝的時候報文件找不到數據庫
我是在WINDOWS上經過CHROME瀏覽器下載並在WINDOWS上解壓的(經驗告訴我解壓第一個PART會自動解壓第二個,可是並無),只解壓了第一個oracle安裝文件(linux.x64_11gR2_database_1of2.zip),第二個(linux.x64_11gR2_database_2of2.zip)沒有解壓。。。因此報錯。centos
3.修改sys/system用戶密碼瀏覽器
使用sqlplus / as sysdba登錄進去以後執行以下命令:bash
alter user sys identified by abc123;
alter user system identified by abc123;服務器
4.建立新用戶session
使用sqlplus / as sysdba登錄進去以後執行以下命令或者使用IDE工具以SYS/SYSTEM登陸以後執行:
create user acct identified by abc123;
grant resource,connect to acct;
grant select any table to acct;
grant debug any procedure,debug connect session to acct;
5.查看ORACLE SID或者SERVICENAME
通常來講SID和SERVICENAME是一致的
使用sqlplus / as sysdba登錄進去以後執行以下命令:
select instance_name from V$instance;
6.重啓服務器以後重啓docker(要求root權限)
執行命令:
docker start 043afeb3a74d
檢查oracle是否啓動成功
netstat -anp|grep 1521
7.設置開機啓動
7.1首先docker本身得先開機啓動
systemctl enable docker.service
7.2將oracle容器設置爲開機啓動
要求容器沒有運行
docker run --restart=always 043afeb3a74d
要求containerid=043afeb3a74d的容器是運行着的(我本身測試這種方式)
docker update --restart=always 043afeb3a74d
測試:先reboot機器
而後執行netstat -anp|grep 1521
使用Docker安裝oracle 11g
Oracle Database,又名Oracle RDBMS,或簡稱Oracle。是甲骨文公司的一款關係數據庫管理系統。
藉助docker,安裝oracle再也不困難,只須要幾步便可。
若是沒有root用戶或者你的用戶沒有加入sudoers列表,你是無法玩的
yum update
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.06.3.ce-3.el7
docker search oracle NAME DESCRIPTION STARS OFFICIAL AUTOMATED oraclelinux Official Docker builds of Oracle Linux. 573 [OK] jaspeen/oracle-11g Docker image for Oracle 11g database 99 [OK] oracle/openjdk Docker images containing OpenJDK Oracle Linux 55 [OK] ……
docker pull jaspeen/oracle-11g
docker images REPOSITORY TAG IMAGE ID CREATED SIZE jaspeen/oracle-11g latest 0c8711fe4f0f 3 years ago 281MB
注意,這個鏡像沒有直接安裝好oracle,他幫咱們配置好了環境,提供了安裝腳本,咱們只須要按照要求把oracle的安裝目錄配置好,啓動鏡像,便可
從oracle 官網 下載所須要的安裝包,這裏咱們以oracle 11g 爲例子,分別下載 linux.x64_11gR2_database_1of2.zip
和 linux.x64_11gR2_database_2of2.zip
兩個壓縮包,下載完成後解壓到home目錄(以下目錄結構)
home └─database ├─doc ├─install ├─response ├─rpm ├─sshsetup ├─stage ├─runInstaller └─welcome.html
爲何要解壓成上面的目錄結構,咱們先來看看jaspeen/oracle-11g
鏡像提供的安裝腳本
#!/usr/bin/env bash set -e source /assets/colorecho trap "echo_red '******* ERROR: Something went wrong.'; exit 1" SIGTERM trap "echo_red '******* Caught SIGINT signal. Stopping...'; exit 2" SIGINT if [ ! -d "/install/database" ]; then echo_red "Installation files not found. Unzip installation files into mounted(/install) folder" exit 1 fi echo_yellow "Installing Oracle Database 11g" su oracle -c "/install/database/runInstaller -silent -ignorePrereq -waitforcompletion -responseFile /assets/db_install.rsp" /opt/oracle/oraInventory/orainstRoot.sh /opt/oracle/app/product/11.2.0/dbhome_1/root.sh
從腳本里能夠看到它會讀取/install/database
目錄,若是不存在會給出提示Installation files not found. Unzip installation files into mounted(/install) folder
命令的解釋:
/home
對應容器 /install/database
)docker run --privileged --name oracle11g -p 1521:1521 -v /home:/install jaspeen/oracle-11g Database is not installed. Installing... Installing Oracle Database 11g Starting Oracle Universal Installer... Checking Temp space: must be greater than 120 MB. Actual 47303 MB Passed Checking swap space: must be greater than 150 MB. Actual 1023 MB Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2019-04-17_08-14-23AM. Please wait ... You can find the log of this install session at: /opt/oracle/oraInventory/logs/installActions2019-04-17_08-14-23AM.log ……
這個安裝過程會很漫長,日誌也不少,這裏只提供部分。注意到日誌裏有 100% complete
打印,表明oracle安裝成功
再次查看運行狀態,oracle已經啓動完成
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7f53f07c93e5 jaspeen/oracle-11g "/assets/entrypoint.…" About an hour ago Up About an hour 0.0.0.0:1521->1521/tcp, 8080/tcp oracle11g
查看docker的狀態
docker ps -a
Error response from daemon: An invalid argument was supplied.
若是出現如上提示,表示docker已經死掉,咱們只須要從新執行安裝步驟,讓oracle安裝完成
ps:根據個人猜想,我給docker分配的資源不夠致使的,我從新把docker的內存和cpu調高一點後oracle順利安裝完成。
docker rm oracle11g docker run --privileged --name oracle11g -p 1521:1521 -v oracleinstall:/install jaspeen/oracle-11g
默認scott用戶是被鎖定的,咱們須要解鎖,經過數據庫工具便可成功鏈接到oracle
docker exec -it oracle11g /bin/bash
[root@7f53f07c93e5 /]# su - oracle Last login: Wed Apr 17 08:29:31 UTC 2019 [oracle@7f53f07c93e5 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 17 09:29:49 2019 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL>
SQL> alter user scott account unlock; User altered. SQL> commit; Commit complete. SQL> conn scott/tiger ERROR: ORA-28001: the password has expired Changing password for scott New password: Retype new password: Password changed Connected. SQL>
編輯本機oracle客戶端或者服務端tnsnames.ora文件,增長以下配置
ACCT_LOCAL_DCOKER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.11)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
打開PL/SQL Developer選擇ACCT_LOCAL_DCOKER,輸入帳號、密碼便可
3.5使用DBeaver鏈接Oracle