1. 在Mac上安装docker,并启动docker
2. 部署oracle docker的build file,并创建image
3. 部署oracle软件在docker中
4. 安装oracle实例在docker中
5. 启动,停止docker以及如何连接数据库
一。在Mac上安装docker。
到docker store下载即可。下载地址是:https://store.docker.com/editions/community/docker-ce-desktop-mac。
其实我们还可以看到别的操作系统的版本,如centos版本,aws版本,Ubuntu版本等等,在centos上,可以用wget命令进行下载。在这里我们用到的是mac版本。
下载完成后,我们得到116M左右的Docker.dmg文件,点击拖动到application文件夹进行安装。
安装完成后,你就可以在launchpad中看到docker图标,点击打开:
适当调整一下cpu内存分配,如给一半资源,4个CPU,16G内存。注意这里也可以看到了你的container image的位置在哪里,点击move可以挪到别的位置去。
启动之后,你就可以在终端敲docker info检查了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
LoveHousedeiMac
:
Oracle
12c
on
docker
lovehouse
$
docker
info
Containers
:
0
Running
:
0
Paused
:
0
Stopped
:
0
Images
:
0
Server
Version
:
17.03.1
-
ce
Storage
Driver
:
overlay2
Backing
Filesystem
:
extfs
Supports
d_type
:
true
Native
Overlay
Diff
:
true
Logging
Driver
:
json
-
file
Cgroup
Driver
:
cgroupfs
Plugins
:
Volume
:
local
Network
:
bridge
host
ipvlan
macvlan
null
overlay
Swarm
:
inactive
Runtimes
:
runc
Default
Runtime
:
runc
Init
Binary
:
docker
-
init
containerd
version
:
4ab9917febca54791c5f071a9d1f404867857fcc
runc
version
:
54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init
version
:
949e6fa
Security
Options
:
seccomp
Profile
:
default
Kernel
Version
:
4.9.27
-
moby
Operating
System
:
Alpine
Linux
v3
.
5
OSType
:
linux
Architecture
:
x86_64
CPUs
:
4
Total
Memory
:
15.65
GiB
Name
:
moby
ID
:
CINI
:
FSC5
:
XEQX
:
BERH
:
YCH5
:
7BGY
:
D4WD
:
NKME
:
MVGR
:
VYFL
:
JONR
:
DQ7D
Docker
Root
Dir
:
/
var
/
lib
/
docker
Debug
Mode
(
client
)
:
false
Debug
Mode
(
server
)
:
true
File
Descriptors
:
19
Goroutines
:
36
System
Time
:
2017
-
05
-
20T13
:
54
:
44.607290579Z
EventsListeners
:
1
Registry
:
https
:
//index.docker.io/v1/
Experimental
:
true
Insecure
Registries
:
127.0.0.0
/
8
Live
Restore
Enabled
:
false
LoveHousedeiMac
:
Oracle
12c
on
docker
lovehouse
$
|
其实安装完docker之后,你可以在docker store中直接pull oracle database 12c(12.1.0.2版本)
但是一方面这个版本是oracle 12.1版本,不是最新的12.2版本,另一方面数据库是包含在container中,如果删除container,就也一并删除了database,这不是我们所想要的。我们选择将container和database的数据文件分开。
二、部署oracle docker的build file,并创建image
到github下载oracle的build file:docker-images-master.zip,地址是https://github.com/oracle/docker-images,是一个约5M的文件。
下载完成后,找个目录解压。如我是放在/Users/[username]/iDocker 下。
然后到otn下载oracle 12.2的安装介质linuxx64_12201_database.zip。下载地址是:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html,是一个3.2G的文件。
下载完成后,将安装介质放在docker-images-master解压之后的目录下:/Users/[username]/idocker/docker-images-master/OracleDatabase/dockerfiles/12.2.0.1,即:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
/
Users
/
lovehouse
/
idocker
/
docker
-
images
-
master
/
OracleDatabase
/
dockerfiles
/
12.2.0.1
LoveHousedeiMac
:
12.2.0.1
lovehouse
$
ls
-
l
total
6745656
-
rw
-
r
--
r
--
@
1
lovehouse
staff
62
May
20
20
:
04
Checksum
.
ee
-
rw
-
r
--
r
--
@
1
lovehouse
staff
62
May
20
20
:
04
Checksum
.
se2
-
rw
-
r
--
r
--
@
1
lovehouse
staff
2547
May
20
20
:
04
Dockerfile
.
ee
-
rw
-
r
--
r
--
@
1
lovehouse
staff
2549
May
20
20
:
04
Dockerfile
.
se2
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
1259
May
20
20
:
04
checkDBStatus
.
sh
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
839
May
20
20
:
04
checkSpace
.
sh
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
2898
May
20
20
:
04
createDB
.
sh
-
rw
-
r
--
r
--
@
1
lovehouse
staff
6878
May
20
20
:
04
db_inst
.
rsp
-
rw
-
r
--
r
--
@
1
lovehouse
staff
9264
May
20
20
:
04
dbca
.
rsp
.
tmpl
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
2057
May
20
20
:
04
installDBBinaries
.
sh
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
1065
May
20
20
:
04
installPerl
.
sh
-
rwxrwxrwx
@
1
lovehouse
staff
3453696911
Mar
12
19
:
02
linuxx64_12201_database
.
zip
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
5332
May
20
20
:
04
runOracle
.
sh
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
769
May
20
20
:
04
setPassword
.
sh
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
876
May
20
20
:
04
setupLinuxEnv
.
sh
-
rwxr
-
xr
-
x
@
1
lovehouse
staff
689
May
20
20
:
04
startDB
.
sh
LoveHousedeiMac
:
12.2.0.1
lovehouse
$
|
三、部署oracle软件在docker中
很简单,就一条命令:
1
|
.
/
buildDockerImage
.
sh
-
v
12.2.0.1
-
e
|
1
2
3
4
5
6
7
|
其中
Parameters
:
-
v
:
version
to
build
Choose
one
of
:
11.2.0.2
12.1.0.2
12.2.0.1
-
e
:
creates
image
based
on
'Enterprise Edition'
-
s
:
creates
image
based
on
'Standard Edition 2'
-
x
:
creates
image
based
on
'Express Edition'
-
i
:
ignores
the
MD5
checksums
|
需要注意的时候,在安装过程中需要联网,因为他会下载oraclelinux:7-slim和yum install pre-install的包。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
LoveHousedeiMac
:
dockerfiles
lovehouse
$
.
/
buildDockerImage
.
sh
-
v
12.2.0.1
-
e
Ignored
MD5
sum
,
'md5sum'
command
not
available
.
===
===
===
===
===
===
===
===
==
DOCKER
info
:
Containers
:
0
Running
:
0
Paused
:
0
Stopped
:
0
Images
:
0
Server
Version
:
17.03.1
-
ce
Storage
Driver
:
overlay2
Backing
Filesystem
:
extfs
……
Step
16
/
16
:
CMD
exec
$
ORACLE_BASE
/
$
RUN_FILE
--
->
Running
in
14330d207a42
--
->
4f9df5f46a19
Removing
intermediate
container
14330d207a42
Successfully
built
4f9df5f46a19
Oracle
Database
Docker
Image
for
'ee'
version
12.2.0.1
is
ready
to
be
extended
:
--
>
oracle
/
database
:
12.2.0.1
-
ee
Build
completed
in
931
seconds
.
LoveHousedeiMac
:
dockerfiles
lovehouse
$
|
附件是完整的log:build.log
安装完成这一步后,我们就可以用docker images命令看我们的安装情况了:
可以看到oracle linux和oracle database软件已经被装好。
1
2
3
4
5
|
LoveHousedeiMac
:
Data
lovehouse
$
docker
images
REPOSITORY
TAG
IMAGE
ID
CREATED
SIZE
oracle
/
database
12.2.0.1
-
ee
4f9df5f46a19
2
hours
ago
14.8
GB
oraclelinux
7
-
slim
442ebf722584
4
weeks
ago
114
MB
LoveHousedeiMac
:
Data
lovehouse
$
|
四、安装oracle实例在docker中
安装数据库实例,也只需要一条命令:
docker run --name oracle -p 1521:1521 -p 5500:5500 -v /Users/andy/idocker/oradata:/opt/oracle/oradata oracle/database:12.2.0.1-ee
1
|
docker
run
--
name
oracle
-
p
1521
:
1521
-
p
5500
:
5500
-
v
/
Users
/
[
username
]
/
oradata
:
/
opt
/
oracle
/
oradata
oracle
/
database
:
12.2.0.1
-
ee
|
1
2
3
4
5
6
7
8
9
10
11
12
|
其中
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
PDB_ADMIN
password
(
default
:
auto
generated
)
-
e
ORACLE_CHARACTERSET
:
The
character
set
to
use
when
creating
the
database
(
default
:
AL32UTF8
)
-
v
The
data
volume
to
use
for
the
database
.
Has
to
be
owned
by
the
Unix
user
"oracle"
or
set
appropriately
.
If
omitted
the
database
will
not
be
persisted
over
container
recreation
.
|
注意数据文件已经map到/Users/[username]/oradata下。此时就算你删除了container,这些数据文件还是会被保留的。
对应的log如下,注意到了最后,会停在那里,估计run命令最后调用类似docker logs -f oracle这样的命令,会tail -f类似的输出,所以我们可以直接在别的窗口docker stop oracle再docker start oracle。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
LoveHousedeiMac
:
dockerfiles
lovehouse
$
docker
run
--
name
oracle
-
p
1521
:
1521
-
p
5500
:
5500
-
v
/
Users
/
lovehouse
/
oradata
:
/
opt
/
oracle
/
oradata
oracle
/
database
:
12.2.0.1
-
ee
ORACLE
PASSWORD
FOR
SYS
,
SYSTEM
AND
PDBADMIN
:
scXX7Cj
+
1m0
=
1
LSNRCTL
for
Linux
:
Version
12.2.0.1.0
-
Production
on
20
-
MAY
-
2017
14
:
25
:
30
Copyright
(
c
)
1991
,
2016
,
Oracle
.
All
rights
reserved
.
Starting
/
opt
/
oracle
/
product
/
12.2.0.1
/
dbhome_1
/
bin
/
tnslsnr
:
please
wait
.
.
.
TNSLSNR
for
Linux
:
Version
12.2.0.1.0
-
Production
System
parameter
file
is
/
opt
/
oracle
/
product
/
12.2.0.1
/
dbhome_1
/
network
/
admin
/
listener
.
ora
Log
messages
written
to
/
opt
/
oracle
/
diag
/
tnslsnr
/
c9f09116cc83
/
listener
/
alert
/
log
.
xml
Listening
on
:
(
DESCRIPTION
=
(
ADDRESS
=
(
PROTOCOL
=
ipc
)
(
KEY
=
EXTPROC1
)
)
)
Listening
on
:
(
DESCRIPTION
=
(
ADDRESS
=
(
PROTOCOL
=
tcp
)
(
HOST
=
0.0.0.0
)
(
PORT
=
1521
)
)
)
……
SQL
>
Disconnected
from
Oracle
Database
12c
Enterprise
Edition
Release
12.2.0.1.0
-
64bit
Production
#########################
DATABASE
IS
READY
TO
USE
!
#########################
The
following
output
is
now
a
tail
of
the
alert
.
log
:
Completed
:
alter
pluggable
database
ORCLPDB1
open
2017
-
05
-
20T14
:
31
:
25.862061
+
00
:
00
ORCLPDB1
(
3
)
:
CREATE
SMALLFILE
TABLESPACE
"USERS"
LOGGING
DATAFILE
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf'
SIZE
5M
REUSE
AUTOEXTEND
ON
NEXT
1280K
MAXSIZE
UNLIMITED
EXTENT
MANAGEMENT
LOCAL
SEGMENT
SPACE
MANAGEMENT
AUTO
ORCLPDB1
(
3
)
:
Completed
:
CREATE
SMALLFILE
TABLESPACE
"USERS"
LOGGING
DATAFILE
'/opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf'
SIZE
5M
REUSE
AUTOEXTEND
ON
NEXT
1280K
MAXSIZE
UNLIMITED
EXTENT
MANAGEMENT
LOCAL
SEGMENT
SPACE
MANAGEMENT
AUTO
ORCLPDB1
(
3
)
:
ALTER
DATABASE
DEFAULT
TABLESPACE
"USERS"
ORCLPDB1
(
3
)
:
Completed
:
ALTER
DATABASE
DEFAULT
TABLESPACE
"USERS"
2017
-
05
-
20T14
:
31
:
26.657295
+
00
:
00
ALTER
SYSTEM
SET
control_files
=
'/opt/oracle/oradata/ORCLCDB/control01.ctl'
SCOPE
=
SPFILE
;
ALTER
PLUGGABLE
DATABASE
ORCLPDB1
SAVE
STATE
Completed
:
ALTER
PLUGGABLE
DATABASE
ORCLPDB1
SAVE
STATE
2017
-
05
-
20T14
:
41
:
16.140414
+
00
:
00
ORCLPDB1
(
3
)
:
Resize
operation
completed
for
file
# 10, old size 337920K, new size 358400K
|
完整的log:run.log
如果“DATABASE IS READY TO USE!”字样已经出现,且后面的log一直停着不动,可以在别的窗口重启container:
1
2
3
4
5
6
7
|
LoveHousedeiMac
:
~
lovehouse
$
docker
stop
oracle
oracle
LoveHousedeiMac
:
~
lovehouse
$
LoveHousedeiMac
:
~
lovehouse
$
LoveHousedeiMac
:
~
lovehouse
$
docker
start
oracle
oracle
LoveHousedeiMac
:
~
lovehouse
$
|
五、启动,停止docker以及如何连接数据库
到了最关心的部分,如何docker和连接数据库。
启停docker其实我们在上一步已经操作过,即:
1
2
|
docker
stop
oracle
docker
start
oracle
|
如果要看alertlog,可以:
1
2
|
docker
logs
oracle
docker
logs
-
f
oracle
|
后者是以tail -f的方式查看的。
连接数据库,注意我们一开始创建的数据库,密码是:
我们可以通过如下命令来修改密码:
1
|
docker
exec
oracle
.
/
setPassword
.
sh
XXXXXX
|
然后我们可以用Navicat这个Mac上最流行的客户端,连接oracle数据库。
另外,如果你想进入container,以传统的方式管理数据库,你可以这样:
先用docker ps -a查询出container的container id,再用docker exec -it [container id] /bin/bash 连接:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
LoveHousedeiMac
:
12.2.0.1
lovehouse
$
docker
ps
-
a
CONTAINER
ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
c9f09116cc83
oracle
/
database
:
12.2.0.1
-
ee
"/bin/sh -c 'exec ..."
2
hours
ago
Up
About
an
hour
0.0.0.0
:
1521
->
1521
/
tcp
,
0.0.0.0
:
5500
->
5500
/
tcp
oracle
LoveHousedeiMac
:
12.2.0.1
lovehouse
$
LoveHousedeiMac
:
12.2.0.1
lovehouse
$
LoveHousedeiMac
:
12.2.0.1
lovehouse
$
LoveHousedeiMac
:
12.2.0.1
lovehouse
$
docker
exec
-
it
c9f09116cc83
/
bin
/
bash
[
oracle
@
c9f09116cc83
~
]
$
ps
-
ef
|
grep
ora_
oracle
21
1
0
15
:
00
?
00
:
00
:
00
ora_pmon_ORCLCDB
oracle
23
1
0
15
:
00
?
00
:
00
:
00
ora_clmn_ORCLCDB
oracle
25
1
0
15
:
00
?
00
:
00
:
01
ora_psp0
_ORCLCDB
……
oracle
360
1
0
15
:
00
?
00
:
00
:
00
ora_q004_ORCLCDB
oracle
1017
1
0
16
:
04
?
00
:
00
:
00
ora_w007_ORCLCDB
oracle
1031
1
0
16
:
05
?
00
:
00
:
00
ora_w003_ORCLCDB
oracle
1081
1
0
16
:
12
?
00
:
00
:
00
ora_w000_ORCLCDB
oracle
1496
1476
0
16
:
58
?
00
:
00
:
00
grep
--
color
=
auto
ora
_
[
oracle
@
c9f09116cc83
~
]
$
|
参考:
https://sqlmaria.com/2017/04/27/oracle-database-12c-now-available-on-docker/
http://www.eygle.com/archives/2017/05/mac_docker_oracle_122.html