[TOC]
*****
# **安装 Docker**
<br >
## **安装 Docker**
1. 在 Linux 机器上打开一个新的 Shell。
2. 使用 wget 从 [https://get.docker.com](https://get.docker.com) 获取并运行 Docker 安装脚本,然后采用 Shell 中管道(pipe)的方式来执行这个脚本。
```shell
# wget -qO- https://get.docker.com/ | sh
```
3. 启动 Docker 并将其设置为开机启动。
```
# systemctl start docker
# systemctl enable docker
```
3. 最好通过非 root 用户来使用 Docker。这时需要添加非 root 用户到本地 Docker Unix 组当中。下面的命令展示了如何把名为 lemon 的用户添加盗 Docker 组中,以及如何确认操作是否执行成功。请读者自行使用系统中的有效用户。
```shell
# sudo usermod -aG docker lemon
# cat /etc/group | grep docker
```
> 如果读者当前登录用户就是要添加到 Docker 组中的用户的话,则需要重新登录,组权限设置才会生效。
4. 恭喜!Docker 已经在读者的 Linux 机器上安装成功。运行下面命令来确认安装结果。
```shell
$ docker --version
Docker version 19.03.5, build 633a0ea
$ docker system info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.5
Storage Driver: overlay2
Backing Filesystem: xfs
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
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-1062.9.1.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.84GiB
Name: vmsrv
ID: EORB:X7ZF:HFAH:76I4:MHT5:NCLY:4GCL:67GB:VBKI:ERPB:7NTA:5AIS
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
```
<br >
## **配置 Docker**
1. 配置国内镜像:
```
# cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://mirror.ccs.tencentyun.com",
"https://tzddjd6l.mirror.aliyuncs.com"
],
"insecure-registries": [],
"debug": true,
"experimental": false
}
EOF
```
2. 重启 Docker:
```
# systemctl restart docker
```
<br >
## **Docker 实例**
<br >
### **Oracle Database 11g XE**
1. 拉取镜像。
```
$ docker pull oracleinanutshell/oracle-xe-11g
```
2. 创建并运行容器。
```
$ docker run --name oracle11g -d -p 1521:1521 -p 8080:8080 -e ORACLE_ALLOW_REMOTE=true oracleinanutshell/oracle-xe-11g
```
* \-d:已守护进程的方式在后台运行容器。
3. 修改 SYSTEM 密码,初始密码:`oracle`。
```
$ docker exec -it oracle11g bash
$ sqlplus
Enter user-name: system
Enter password: oracle
SQL> alter user system identified by admin123;
SQL> exit;
$ exit
```
<br >
### **Oracle Database 12c**
1. 在 Docker Hub 中查看 Oracle Database 的安装说明。
2. 登录 Docker Hub,搜索到 Oracle Database 镜像,并点击 Proceed to Checkout。
![](https://img.kancloud.cn/4d/24/4d244501c276ca50e8769325811768c7_1313x787.png)
3. 填写联系信息,并同意协议,点击 Get Content。
![](https://img.kancloud.cn/f2/f6/f2f603ccf1e00638d51b12c92718b83b_1313x761.png)
4. 系统返回 Setup Instructions。
5. 拉取镜像。
```
$ docker login
$ docker pull store/oracle/database-enterprise:12.2.0.1
```
6. 创建并运行容器。
```
$ docker run -d -it --name oracle12c -p 1521:1521 -p 5500:5500 -e DB_SID=ORCLCDB -e DB_MEMORY=2G store/oracle/database-enterprise:12.2.0.1
```
7. 注意:启动较慢,请耐心等待。使用`docker ps`命令查看容器状态,状态变成 healthy 即代表启动完成。
```
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11a27f8db0e9 store/oracle/database-enterprise:12.2.0.1 "/bin/sh -c '/bin/ba…" 9 minutes ago Up 9 minutes (healthy) 0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp oracle12c
```
8. 修改 SYS 密码。
```
$ docker exec -it oracle12c bash
[oracle@11a27f8db0e9 /]$ sqlplus /nolog
SQL> conn / as sysdba
SQL> alter user sys identified by admin123;
SQL> exit;
$ exit
```
9. 使用 Oracle SQL Developer 创建连接,验证安装是否成功。
![](https://img.kancloud.cn/54/25/54259d155ca3eca8370d422507770287_769x415.png)
10. 启动数据库的归档模式。
```
$ sqlplus / as sysdba
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 671088640 bytes
Fixed Size 8796384 bytes
Variable Size 213911328 bytes
Database Buffers 440401920 bytes
Redo Buffers 7979008 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> exit;
```
11. 启用补充日志。
```
$ sqlplus / as sysdba
SQL> alter database add supplemental log data (all) columns;
Database altered.
SQL> exit;
```
12. 创建 Oracle 用户。
```
create role logmnr_role;
grant create session to logmnr_role;
grant execute_catalog_role,select any transaction ,select any dictionary to logmnr_role;
create user kminer identified by kminerpass;
grant logmnr_role to kminer;
alter user kminer quota unlimited on users;
create role c##logmnr_role;
grant create session to c##logmnr_role;
grant execute_catalog_role,select any transaction ,select any dictionary,logmining to c##logmnr_role;
create user c##kminer identified by kminerpass;
grant c##logmnr_role to c##kminer;
alter user c##kminer quota unlimited on users set container_data = all container = current;
```