1.下載并安裝Docker
第一步:下載docker(500M左右)
下載連接:https://download.docker.com/mac/stable/Docker.dmg第二步:點擊Docker.dmg安裝即可
第三步:打開終端,輸入命令
docker version
查看docker版本七问,看是否安裝成功:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:39 2019
OS/Arch: darwin/amd64
Experimental: false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
能得到上面的信息茫舶,證明docker已經(jīng)安裝就緒!
-
第四步:在Launchpad找到Docker圖標讥耗,點擊并啟動
2.下載并安裝Oracle 11g
第一步:使用docker search docker-oracle-xe-11g
命令沙绝,搜索docker遠程倉庫的鏡像:
終端輸出結(jié)果:
AME DESCRIPTION STARS OFFICIAL AUTOMATED
docker Docker in Docker! 1024 [OK]
oraclelinux Official Docker builds of Oracle Linux. 572 [OK]
jaspeen/oracle-11g Docker image for Oracle 11g database 98 [OK]
carloscastillo/rgt-oracle-xe-11g This is a simple image based on sath89/oracl… 10 [OK]
deepdiver/docker-oracle-xe-11g 8 [OK]
pengbai/docker-oracle-xe-11g-r2 oracle xe 11g r2 with sql initdb and web con… 6 [OK]
arahman/docker-oracle-xe-11g phusion/baseimage based spin off of alexei-l… 5 [OK]
oracleinanutshell/oracle-xe-11g 5
ukhomeofficedigital/oracle-xe-11g Oracle Database Express Edition 11g Container 4 [OK]
rafaelri/docker-oracle-xe-11g Fork from wnameless/docker-oracle-xe-11g 3 [OK]
ignatov/docker-oracle-xe-11g Dockerfile of Oracle Database Express Editio… 2 [OK]
christophesurmont/oracle-xe-11g Clone of the wnameless/oracle-xe-11g. 1
epiclabs/docker-oracle-xe-11g Customized Oracle XE 11g build for CI and de… 1 [OK]
rdehuyss/docker-oracle-xe-11g Oracle Express 11g R2 on Ubuntu 14.04.2 LTS 0 [OK]
kikicarbonell/docker-oracle-xe-11g Docker image of Oracle Database Express Edit… 0 [OK]
zigac/docker-oracle-xe-11g Oracle xe 11g 0 [OK]
deradam/docker-oracle-xe-11g Oracle Express Edition 11g Release 2 on Ubun… 0
jeromefromcn/docker-oracle-xe-11g docker-oracle-xe-11g 0 [OK]
webdizz/oracle-xe-11g-sa This is a simple image based on sath89/oracl… 0 [OK]
gswteam/docker-oracle-xe-11g Oracle XE 11g 0 [OK]
ambientdocker/docker-oracle-xe-11g oracle-xe-11g image 0 [OK]
deadok22/docker-oracle-xe-11g docker-oracle-xe-11g 0
konnecteam/docker-oracle-xe-11g Fork of https://github.com/wnameless/docker-… 0 [OK]
lynxsolutions/docker-oracle-xe-11g docker-oracle-xe-11g 0 [OK]
nguoianphu/docker-oracle-xe-11g Oracle Express Edition 11g Release 2 on Ubun… 0 [OK]
第二步:下載oracle 11g 輸入如下命令:(筆者電腦只有128G涧偷,所以此處愕掏,我使用的是閹割版的docker-oracle-xe-11g趋急,大家可根據(jù)自己的口味選取)
docker pull alexeiled/docker-oracle-xe-11g
命令解釋:
pull
是Docker 容器的拉取命令
alexeiled/docker-oracle-xe-11g
為鏡像的完整名字
終端消息:顯示下載的狀態(tài)
Using default tag: latest
latest: Pulling from alexeiled/docker-oracle-xe-11g
759d6771041e: Pulling fs layer
8836b825667b: Pulling fs layer
c2f5e51744e6: Pulling fs layer
a3ed95caeb02: Pull complete
787648ea7b44: Pull complete
46f20000ce59: Pull complete
2a190e47ca3f: Pull complete
f8043f470a85: Pull complete
0f6111a00dd6: Pull complete
deacbfda2b11: Pull complete
6eb979936fa3: Pull complete
5194f2505f56: Pull complete
a63e30990791: Pull complete
994cf2ce199e: Pull complete
5eba4c64e295: Pull complete
01227e9ca0a6: Pull complete
076b6fa27478: Pull complete
d6407a7221b5: Pull complete
bbc5a28168da: Pull complete
dd783b45fa26: Pull complete
0a686089bc7e: Pull complete
73fac5e681c5: Pull complete
afaede9e60b1: Pull complete
a5d9cef8ef2a: Pull complete
32bcfcf46e45: Pull complete
aa896f927427: Pull complete
f99ab5aba6e5: Pull complete
Digest: sha256:35448e199115012a742ff9098da3287c666ce52d18efcf4658e0437892ed3ee6
Status: Downloaded newer image for alexeiled/docker-oracle-xe-11g:latest
下載完成后,啟動鏡像為容器:
aiuiot:~ root# docker run -h "oracle" --name "oracle" -d -p 49160:22 -p 49161:1521 -p 49162:8080 alexeiled/docker-oracle-xe-11g
3谣蠢、進入容器并啟動Oracle
第一步:在終端中執(zhí)行命令進入容器:
aiuiot:~ root# docker exec -it 0677fc709d77 /bin/bash
其中0677fc709d77
是容器id查近,可使用docker ps
命令獲得:
aiuiot:~ root# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0677fc709d77 alexeiled/docker-oracle-xe-11g "/bin/sh -c /start.sh" 5 minutes ago Up 5 minutes 0.0.0.0:49160->22/tcp, 0.0.0.0:49161->1521/tcp, 0.0.0.0:49162->8080/tcp oracle
aiuiot:~ root# docker exec -it 0677fc709d77 /bin/bash
進入容器后,輸入sqlplus system/oracle
命令登錄:
root@oracle:/# sqlplus system/oracle
SQL*Plus: Release 11.2.0.2.0 Production on Tue Jan 8 08:46:58 2019
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-28002: the password will expire within 7 days
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
4.創(chuàng)建用戶并分配權(quán)限
查看用戶:
SQL> select username,password from dba_users;
USERNAME PASSWORD
------------------------------ ------------------------------
SYS
ANONYMOUS
SYSTEM
APEX_PUBLIC_USER
APEX_040000
XS$NULL
OUTLN
FLOWS_FILES
MDSYS
CTXSYS
XDB
USERNAME PASSWORD
------------------------------ ------------------------------
HR
12 rows selected.
創(chuàng)建新用戶:用戶名為 deque
密碼 123
SQL> create user deque identified by 123;
User created.
輸入命令select * from all_users;
查看是否有用戶deque
:
SQL> select * from all_users;
USERNAME USER_ID CREATED
------------------------------ ---------- ---------
XS$NULL 2147483638 28-AUG-11
DEQUE 48 08-JAN-19
APEX_040000 47 28-AUG-11
APEX_PUBLIC_USER 45 28-AUG-11
FLOWS_FILES 44 28-AUG-11
HR 43 28-AUG-11
MDSYS 42 28-AUG-11
ANONYMOUS 35 28-AUG-11
XDB 34 28-AUG-11
CTXSYS 32 28-AUG-11
OUTLN 9 28-AUG-11
USERNAME USER_ID CREATED
------------------------------ ---------- ---------
SYSTEM 5 28-AUG-11
SYS 0 28-AUG-11
13 rows selected.
4.1 給新創(chuàng)建的用戶授權(quán)
給用戶deque
賦予connect
,resource
角色谈喳,這倆角色含有許多權(quán)限.
connect
:是保證該用戶能連接數(shù)據(jù)庫;
resource
:是該用戶可以使用數(shù)據(jù)庫資源婿禽。
輸入命令grant connect,resource to deque;
SQL> grant connect,resource to deque;
Grant succeeded.
連接到
5.刪除用戶
因為oracle數(shù)據(jù)庫是基于用戶去創(chuàng)建表大猛,如果想刪除自己創(chuàng)建的用戶,可用命令是:drop user deque挽绩;
注意:分號不可少,且當前連接數(shù)據(jù)庫的用戶必須具有刪除用戶權(quán)限(如sys)模聋。
6.在Docker 停止或啟動服務(wù)
-
docker stop oracle
停止oracle
停止oracle操作 -
docker start oracle
啟動oracle
啟動oracle操作
7唠亚、常用命令
-
docker ps
查看正在運行的容器
常見問題:
1、Docker未正常啟動
命令行提示信息:
Cannot connect to the Docker daemon at unix:
///var/run/docker.sock. Is the docker daemon running?
解決:啟動你的Docker
2侄柔、未正常拉取鏡像占调,倉庫不存在或者需要登錄
Using default tag:
latest Error response from daemon:
pull access denied for alexeiled/docker-oracle-xe-11g,
repository does not exist or may require 'docker login'
錯誤提示:使用默認標記:
來自守護程序的最新錯誤響應(yīng):
拒絕對 alexeled/docker-oracle-xe-11g 的拉入訪問移剪,
存儲庫不存在,或者可能需要“Docker登錄”
解決方案:
① 在終端輸入登錄命令docker login
登錄docker賬號
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: aiuiot
Password:
Login Succeeded
② 使用搜索命令docker search docker-oracle-xe-11g
搜索倉庫有用的鏡像剿涮,并拉取
補充內(nèi)容:
如何與SQL管理工具鏈接
查看端口
使用docker container ls
命令,查看端口情況:
可以看到49160端口被映射到容器的22端口取试,49161被映射帶容器的1521端口,49162端口被映射到8080端口初婆。我們訪問本機的49161端口即可在SQL管理工具訪問猿棉。