更新apt來源,安裝CA證書,指令如下:
sudo apt-get update sudo apt-get install apt-transport-https ca-certificates
新增GPG金鑰:
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
開啟/etc/apt/sources.list.d/docker.list檔案(沒有就建一個)
加入來源deb https://apt.dockerproject.org/repo ubuntu-xenial main然後儲存
根據系統版本選擇不同的來源:
On Ubuntu Precise 12.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-precise main On Ubuntu Trusty 14.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-trusty main Ubuntu Wily 15.10 deb https://apt.dockerproject.org/repo ubuntu-wily main Ubuntu Xenial 16.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-xenial main
這裡選Ubuntu Xenial 16.04 (LTS)
更新apt,並確定Docker 的來源正確
sudo apt-get update apt-cache policy docker-engine
安裝:
sudo apt-get install docker-engine
支援一般使用者使用docker
ppa安裝docker群組已經被建立了,不然sudo groupadd docker建一下
sudo gpasswd -a ${USER} docker sudo service docker restart sudo chmod a+rw /var/run/docker.sock
docker search : 從Docker Hub找找oracle鏡
$ docker search oracle NAME DESCRIPTION STARS OFFICIAL AUTOMATED oraclelinux Oracle Linux is an open-source operating s... 398 [OK] frolvlad/alpine-oraclejdk8 The smallest Docker image with OracleJDK 8... 269 [OK] alexeiled/docker-oracle-xe-11g This is a working (hopefully) Oracle XE 11... 221 [OK] sath89/oracle-12c Oracle Standard Edition 12c Release 1 with... 214 [OK] sath89/oracle-xe-11g Oracle xe 11g with database files mount su... 133 [OK] isuper/java-oracle This repository contains all java releases... 55 [OK] jaspeen/oracle-11g Docker image for Oracle 11g database 54 [OK] oracle/glassfish GlassFish Java EE Application Server on Or... 30 [OK] oracle/openjdk Docker images containing OpenJDK Oracle Linux 25 [OK] airdock/oracle-jdk Docker Image for Oracle Java SDK (8 and 7)... 23 [OK] ingensi/oracle-jdk Official Oracle JDK installed on centos. 21 [OK] cogniteev/oracle-java Oracle JDK 6, 7, 8, and 9 based on Ubuntu ... 20 [OK] wnameless/oracle-xe-11g Dockerfile of Oracle Database Express Edit... 16 [OK] n3ziniuka5/ubuntu-oracle-jdk Ubuntu with Oracle JDK. Check tags for ver... 14 [OK] oracle/nosql Oracle NoSQL on a Docker Image with Oracle... 13 [OK] collinestes/docker-node-oracle A container with Node.js/Oracle instant cl... 9 [OK] andreptb/oracle-java Debian Jessie based image with Oracle JDK ... 7 [OK] sgrio/java-oracle Docker images of Java 7/8 provided by Orac... 7 [OK] openweb/oracle-tomcat A fork off of Official tomcat image with O... 7 [OK] flurdy/oracle-java7 Base image containing Oracle's Java 7 JDK 5 [OK] davidcaste/debian-oracle-java Oracle Java 8 (and 7) over Debian Jessie 3 [OK] teradatalabs/centos6-java8-oracle Docker image of CentOS 6 with Oracle JDK 8... 3 spansari/nodejs-oracledb nodejs with oracledb installed globally on... 1 publicisworldwide/oracle-core This is the core image based on Oracle Lin... 1 [OK] sigma/nimbus-lock-oracle 0 [OK]
docker pull sath89/oracle-xe-11g
pull後顯示:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 8 days ago 1.85kB sath89/oracle-xe-11g latest 04851454491b 3 months ago 792MB
建立並啟動oracle實例:
docker run -d -p 9090:8080 -p 1521:1521 -v /home/${USER}/oracle/data:/u01/app/oracle sath89/oracle-xe-11g
其中 -p 9090:8080是docker映像中Oracle Application Express web management埠8080對應到本機9090埠:
http://localhost:9090/apex workspace: INTERNAL user: ADMIN password: oracle
-p 1521:1521是oracle服務端口,如果本地端口不想用1521可以修改第一個1521。
具體參考以前的一個博文打造ubuntu下精簡版的oracle客戶端及pro*c編譯環境
11g的instantclient軟體oracle官網上找不到我把它放到天翼雲上了(訪問碼:6540)
本地設定oracle的SID:
在/opt/oracle/product/network/admin/tnsnames.ora(和instantclient路徑有關)追加:
XE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = xe) ) )
不配置也可以直接:
sqlplus sys/oracle@127.0.0.1:1521/xe as sysdba sqlplus system/oracle@//localhost:1521/xe
配置好了就可以這樣存取
sqlplus sys/oracle@xe as sysdba sqlplus system/oracle@xe
其中sys和system是預設的兩個用戶,一個是sysdba權限一個是system權限。初始密碼都為oracle
建議安裝成功後立刻修改sys密碼
sqlplus sys/oracle@xe as sysdba SQL>alter user sys identified by your-passwd
創建表空間
SQL> create tablespace myts datafile '/u01/app/oracle/oradata/XE/myts.dbf' size 100M autoextend on next 5M maxsize 400M;
修改系統預設表空間
SQL> alter database default tablespace MYTS; SQL> select a.property_name, a.property_value from database_properties a where a.property_name like '%DEFAULT%'; PROPERTY_NAME -------------------------------------------------------------------------------- PROPERTY_VALUE -------------------------------------------------------------------------------- DEFAULT_TEMP_TABLESPACE TEMP DEFAULT_PERMANENT_TABLESPACE MYTS DEFAULT_EDITION ORA$BASE .......
建立使用者、授權並製定表空間
SQL> create user scott identified by tiger; SQL> grant connect, resource to scott; SQL> alter user scott default tablespace myts;
建表腳本 myscott.sql :
-------------------------------------------------------- -- File created - 星期六-六月-14-2014 -------------------------------------------------------- -------------------------------------------------------- -- DDL for Table BONUS -------------------------------------------------------- CREATE TABLE "BONUS" ( "ENAME" VARCHAR2(10), "JOB" VARCHAR2(9), "SAL" NUMBER, "COMM" NUMBER ) ; -------------------------------------------------------- -- DDL for Table DEPT -------------------------------------------------------- CREATE TABLE "DEPT" ( "DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14), "LOC" VARCHAR2(13) ) ; -------------------------------------------------------- -- DDL for Table EMP -------------------------------------------------------- CREATE TABLE "EMP" ( "EMPNO" NUMBER(4,0), "ENAME" VARCHAR2(10), "JOB" VARCHAR2(9), "MGR" NUMBER(4,0), "HIREDATE" DATE, "SAL" NUMBER(7,2), "COMM" NUMBER(7,2), "DEPTNO" NUMBER(2,0) ) ; -------------------------------------------------------- -- DDL for Table SALGRADE -------------------------------------------------------- CREATE TABLE "SALGRADE" ( "GRADE" NUMBER, "LOSAL" NUMBER, "HISAL" NUMBER ) ; --------------------------------------------------- -- DATA FOR TABLE BONUS -- FILTER = none used --------------------------------------------------- REM INSERTING into BONUS --------------------------------------------------- -- END DATA FOR TABLE BONUS --------------------------------------------------- --------------------------------------------------- -- DATA FOR TABLE DEPT -- FILTER = none used --------------------------------------------------- REM INSERTING into DEPT Insert into DEPT (DEPTNO,DNAME,LOC) values (10,'ACCOUNTING','NEW YORK'); Insert into DEPT (DEPTNO,DNAME,LOC) values (20,'RESEARCH','DALLAS'); Insert into DEPT (DEPTNO,DNAME,LOC) values (30,'SALES','CHICAGO'); Insert into DEPT (DEPTNO,DNAME,LOC) values (40,'OPERATIONS','BOSTON'); --------------------------------------------------- -- END DATA FOR TABLE DEPT --------------------------------------------------- --------------------------------------------------- -- DATA FOR TABLE EMP -- FILTER = none used --------------------------------------------------- REM INSERTING into EMP Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7369,'SMITH','CLERK',7902,to_timestamp('17-12月-80 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),800,null,20); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7499,'ALLEN','SALESMAN',7698,to_timestamp('20-2月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1600,300,30); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7521,'WARD','SALESMAN',7698,to_timestamp('22-2月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1250,500,30); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7566,'JONES','MANAGER',7839,to_timestamp('02-4月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2975,null,20); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7654,'MARTIN','SALESMAN',7698,to_timestamp('28-9月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1250,1400,30); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7698,'BLAKE','MANAGER',7839,to_timestamp('01-5月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2850,null,30); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7782,'CLARK','MANAGER',7839,to_timestamp('09-6月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),2450,null,10); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7788,'SCOTT','ANALYST',7566,to_timestamp('19-4月 -87 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),3000,null,20); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7839,'KING','PRESIDENT',null,to_timestamp('17-11月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),5000,null,10); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7844,'TURNER','SALESMAN',7698,to_timestamp('08-9月 -81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1500,0,30); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7876,'ADAMS','CLERK',7788,to_timestamp('23-5月 -87 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1100,null,20); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7900,'JAMES','CLERK',7698,to_timestamp('03-12月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),950,null,30); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7902,'FORD','ANALYST',7566,to_timestamp('03-12月-81 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),3000,null,20); Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7934,'MILLER','CLERK',7782,to_timestamp('23-1月 -82 12.00.00.000000000 上午','DD-MON-RR HH.MI.SS.FF AM'),1300,null,10); --------------------------------------------------- -- END DATA FOR TABLE EMP --------------------------------------------------- --------------------------------------------------- -- DATA FOR TABLE SALGRADE -- FILTER = none used --------------------------------------------------- REM INSERTING into SALGRADE Insert into SALGRADE (GRADE,LOSAL,HISAL) values (1,700,1200); Insert into SALGRADE (GRADE,LOSAL,HISAL) values (2,1201,1400); Insert into SALGRADE (GRADE,LOSAL,HISAL) values (3,1401,2000); Insert into SALGRADE (GRADE,LOSAL,HISAL) values (4,2001,3000); Insert into SALGRADE (GRADE,LOSAL,HISAL) values (5,3001,9999); --------------------------------------------------- -- END DATA FOR TABLE SALGRADE --------------------------------------------------- -------------------------------------------------------- -- DDL for Index PK_EMP -------------------------------------------------------- CREATE UNIQUE INDEX "PK_EMP" ON "EMP" ("EMPNO") ; -------------------------------------------------------- -- DDL for Index PK_DEPT -------------------------------------------------------- CREATE UNIQUE INDEX "PK_DEPT" ON "DEPT" ("DEPTNO") ; -------------------------------------------------------- -- Constraints for Table EMP -------------------------------------------------------- ALTER TABLE "EMP" ADD CONSTRAINT "PK_EMP" PRIMARY KEY ("EMPNO") ENABLE; -------------------------------------------------------- -- Constraints for Table DEPT -------------------------------------------------------- ALTER TABLE "DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") ENABLE; -------------------------------------------------------- -- Ref Constraints for Table EMP -------------------------------------------------------- ALTER TABLE "EMP" ADD CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO") REFERENCES "DEPT" ("DEPTNO") ENABLE;
執行腳本、查詢:
SQL> @myscott.sql SQL> select * from EMP;
$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3c6a2c2761fb sath89/oracle-xe-11g "/entrypoint.sh " 2 minutes ago Up About a minute 0.0.0.0:1521->1521/tcp, 0.0.0.0:9090->8080/tcp dreamy_pasteur $ docker exec -it 3c6a2c2761fb /bin/bash root@3c6a2c2761fb:/# su oracle oracle@3c6a2c2761fb:/$ $ORACLE_HOME/bin/sqlplus / as sysdba SQL*Plus: Release 11.2.0.2.0 Production on Wed Nov 29 13:40:15 2017 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL> quit Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production oracle@8e1a86793036:/$ $ORACLE_HOME/bin/sqlplus scott/tiger SQL*Plus: Release 11.2.0.2.0 Production on Wed Nov 29 13:40:24 2017 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM ---------- ---------- --------- ---------- --------- ---------- ---------- DEPTNO ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 ......
$ docker stop 3c6a2c2761fb $ docker start 3c6a2c2761fb
為方便後續的管理可在.bashrc中追加alias
alias orastartdock='docker start 3c6a2c2761fb' alias orastopdock='docker stop 3c6a2c2761fb'
也可以在
docker run -d --name=oracle1 -p 9090:8080 -p 1521:1521 -v /home/${USER}/oracle/data:/u01/app/oracle sath89/oracle-xe-11g
指定容器名oracle1,這樣用來以下方式來停止和啟動實例:
$ docker stop oracle1 $ docker start oracle1
而不必使用前面由docker隨機產生的CONTAINER ID
可用~$ docker rename oracle1 ora1來重新命名docker容器名,用~$docker rm 容器名or容器ID來刪除,也可用下面的指令全部刪除
docker rm $(docker ps -aq)
當然啟動狀態下是不能刪的。
只要改變連接埠和資料存放路徑,一個鏡像可以建立多個oracle實例,如:
docker run -d --name=oracle2 -p 9092:8080 -p 1522:1521 -v /home/${USER}/oracle/data2:/u01/app/oracle sath89/oracle-xe-11g docker run -d --name=ora3 -p 9093:8080 -p 1523:1521 -v /home/${USER}/oracle/data3:/u01/app/oracle sath89/oracle-12c
這樣你可以很容易建立多個oracle環境。
$docker pull mysql:5.7.20 $docker run -p 3307:3306 --name mysql5.7.20 -v /home/${USER}/mysqldata/mysql5.7.20/conf:/etc/mysql/conf.d -v /home/${USER}/mysqldata/mysql5.7.20/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.20 $ docker exec -it mysql5.7.20 bash # mysql -p123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye root@657aaa1203f4:/# exit exit ~$ mysql -h 127.0.0.1 -P3307 -u root -123456 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 17 Server version: 5.7.20 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement mysql> quit
這裡必須加上-h 127.0.0.1,不然哪怕指定了端口-P3307還是連到宿主機的mysql而不是docker容器的那個,這是因為宿主機上在.my.cf指定了3306端口。
以上是大神解說在unbuntu下Docker安裝oracle和mysql的詳細內容。更多資訊請關注PHP中文網其他相關文章!