一步步教你如何在CENTOS的Docker中安装oracle11g
一、软件版本
CentOS Linux release 7.6.1810 (Core)
Docker version 20.10.8
二、基础环境准备
1 安装依赖包
[root@localhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package device-mapper-persistent-data.x86_64 0:0.7.3-3.el7 will be updated
...
...
Installed:
yum-utils.noarch 0:1.1.31-54.el7_8
Dependency Installed:
libxml2-python.x86_64 0:2.9.1-6.el7.5 python-chardet.noarch 0:2.2.1-3.el7 python-kitchen.noarch 0:1.1.1-5.el7
Updated:
device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 lvm2.x86_64 7:2.02.187-6.el7_9.5
Dependency Updated:
device-mapper.x86_64 7:1.02.170-6.el7_9.5 device-mapper-event.x86_64 7:1.02.170-6.el7_9.5 device-mapper-event-libs.x86_64 7:1.02.170-6.el7_9.5
device-mapper-libs.x86_64 7:1.02.170-6.el7_9.5 libxml2.x86_64 0:2.9.1-6.el7.5 lvm2-libs.x86_64 7:2.02.187-6.el7_9.5
Complete!
[root@localhost ~]#
2 添加阿里镜像源
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to etc/yum.repos.d/docker-ce.repo
repo saved to etc/yum.repos.d/docker-ce.repo
[root@localhost ~]#
3 安装docker-ce
[root@localhost ~]# yum -y install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
docker-ce-stable | 3.5 kB 00:00:00
(1/2): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
(2/2): docker-ce-stable/7/x86_64/primary_db | 63 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:20.10.8-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-20.10.8-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.4.1 for package: 3:docker-ce-20.10.8-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-20.10.8-3.el7.x86_64
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.8-3.el7.x86_64
--> Processing Dependency: libcgroup for package: 3:docker-ce-20.10.8-3.el7.x86_64
...
..
18/22
Verifying : libcgroup-0.41-21.el7.x86_64 19/22
Verifying : audit-2.8.4-4.el7.x86_64 20/22
Verifying : policycoreutils-2.5-29.el7.x86_64 21/22
Verifying : audit-libs-2.8.4-4.el7.x86_64 22/22
Installed:
docker-ce.x86_64 3:20.10.8-3.el7
Dependency Installed:
audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 containerd.io.x86_64 0:1.4.9-3.1.el7
docker-ce-cli.x86_64 1:20.10.8-3.el7 docker-ce-rootless-extras.x86_64 0:20.10.8-3.el7 docker-scan-plugin.x86_64 0:0.8.0-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
fuse3-libs.x86_64 0:3.6.1-4.el7 libcgroup.x86_64 0:0.41-21.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7
python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7 slirp4netns.x86_64 0:0.4.3-4.el7_8
Dependency Updated:
audit.x86_64 0:2.8.5-4.el7 audit-libs.x86_64 0:2.8.5-4.el7 policycoreutils.x86_64 0:2.5-34.el7
Complete!
[root@localhost ~]#
4 添加阿里云镜像加速
注册阿里云并登录,搜索容器镜像服务 ACR ,进入控制台
mkdir -p etc/docker
tee etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://lg0xzd73.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
5启动并查看 docker info
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
scan: Docker Scan (Docker Inc., v0.8.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.8
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
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: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: e25210fe30a0a703442421b0f60afac609f950a3
runc version: v1.0.1-0-g4144b63
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-957.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.934GiB
Name: localhost.localdomain
ID: 3FDJ:AF6Z:4GCF:YK4E:NGXG:7EDN:JEDK:MWFK:6YNZ:BR77:KVLF:XNPA
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
[root@localhost ~]#
三、镜像操作
1 查找镜像 docker search oracle_11g
[root@localhost ~]# docker search oracle_11g
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
iatebes/oracle_11g Docker image for Oracle Database 11g 11
lhrbest/oracle_11g_ee_lhr_11.2.0.3 Oracle 11g 企业版, 11.2.0.3 ,QQ:646634621… 3
lhrbest/oracle_11g_ee_lhr_11.2.0.4 Oracle 11g 企业版, 11.2.0.4 ,QQ:646634621… 2
jiangbodocker/oracle_11g_r2_logminer 开启了logminer的oracle数据库 1
pan2056/oracle_11g 0
aswuhuaqiang/oracle_11g oracle_11g 0
cetrdpd/oracle_11g 0
jingmei2/oracle_11g 0
helpuser/oracle_11g 0
hogwartsrow/oracle_11g 0
oussemos/oracle_11g 0
411646865/oracle_11gr2 0
akaiot/oracle_11g oracle镜像来自registry.cn-hangzhou.aliyuncs.… 0
jeffpear/oracle_11g 0
dalibeans/oracle_11g 0
itheshe/oracle_11g 0
heyulong/oracle_11g 0
vinay404219/oracle_11g 0
848672861/oracle_11g 0
wushipeng/oracle_11g 0
kbm0417/oracle_11g 0
q543738006/oracle_11g 0
72machi/oracle_11g 오라클 11g 0
faustobuscema/oracle_11g_r2_ee Oracle 11g R2 Enterprise Edition x64 Linux 0
liuguipeng/oracle_11g oracle11g 0
[root@localhost ~]#
2 拉取镜像 docker pull iatebes/oracle_11g
[root@localhost ~]# docker pull iatebes/oracle_11g
Using default tag: latest
latest: Pulling from iatebes/oracle_11g
8c3d77a518cb: Pull complete
15e5453594e1: Pull complete
686bc2cca543: Pull complete
34b7824dbc5e: Pull complete
bf6403b14c96: Pull complete
Digest: sha256:73c7f39e1e69dce1599c2f2f82819a02e51ccc6172697e8ea856f78260f2b9c8
Status: Downloaded newer image for iatebes/oracle_11g:latest
docker.io/iatebes/oracle_11g:latest
[root@localhost ~]#
3 查看镜像 docker images ls
[root@localhost docker]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
iatebes/oracle_11g latest ce0858c76c8b 5 years ago 5.97GB
4 启动容器
[root@localhost docker]# docker run -itd -p 1521:1521 --name oracle11g iatebes/oracle_11g
8ae5b2c187db45fd154ba80471ea11f4561fadc72fd6bcb1c0016373f5b7d9b9
[root@localhost docker]#
[root@localhost docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ae5b2c187db iatebes/oracle_11g "/assets/entrypoint.…" 18 seconds ago Up 14 seconds 0.0.0.0:1521->1521/tcp, :::1521->1521/tcp, 8080/tcp oracle11g
[root@localhost docker]#
5 进入容器 docker exec -it oracle11g bash
[root@localhost docker]# docker exec -it oracle11g bash
[root@8ae5b2c187db ]#
四、数据库相关操作
1 进入数据库查看状态
[root@8ae5b2c187db ]# su - oracle
Last login: Sat Sep 4 13:53:20 UTC 2021 on pts/0
[oracle@8ae5b2c187db ~]$ sqlplus as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Sep 4 13:57:22 2021
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, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> select status from v$instance;
STATUS
------------
OPEN
SQL>
2 创建用户、表空间、赋权
SQL> create tablespace carl datafile '/opt/oracle/app/oradata/orcl/carl.dbf' size 100m autoextend on next 100m;
Tablespace created.
SQL> create temporary tablespace carl_temp tempfile '/opt/oracle/app/oradata/orcl/carl_temp.dbf' size 100m autoextend on next 100m;
Tablespace created.
SQL> create user carl identified by oracle default tablespace carl temporary tablespace carl_temp;
User created.
SQL> grant connect,resource,dba to carl;
Grant succeeded.
SQL>
3 使用carl用户登录创建按测试表
SQL> create table t_carl_test(id int,name varchar2(20));
Table created.
SQL> insert into t_carl_test values (1,'carl');
1 row created.
SQL>
SQL> commit;
Commit complete.
SQL> select * From t_carl_test;
ID NAME
---------- --------------------
1 carl
SQL>
五、镜像的保存与导入
1 提交镜像
[root@localhost ~]# docker ps -qa
8ae5b2c187db
[root@localhost ~]# docker commit 8ae5b2c187db oracle/carl
sha256:a125ce4fdaec9ab354e3e80a2b99f5b671583ffc334b6749d1623937e7da2fc1
[root@localhost ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/carl latest a125ce4fdaec About a minute ago 7.65GB
iatebes/oracle_11g latest ce0858c76c8b 5 years ago 5.97GB
[root@localhost ~]#
2 保存镜像
[root@localhost ~]# docker save -o oracle_11g_20210904.tar oracle/carl:latest
[root@localhost ~]#
[root@localhost ~]# ls -lrt
total 7511568
-rw-------. 1 root root 7691844096 Sep 4 10:20 oracle_11g_20210904.tar
[root@localhost ~]#
3 删除之前拉取镜像与提交镜像
[root@localhost ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/carl latest a125ce4fdaec 13 minutes ago 7.65GB
iatebes/oracle_11g latest ce0858c76c8b 5 years ago 5.97GB
[root@localhost ~]# docker rmi a125ce4fdaec ce0858c76c8b
Untagged: iatebes/oracle_11g:latest
Untagged: iatebes/oracle_11g@sha256:73c7f39e1e69dce1599c2f2f82819a02e51ccc6172697e8ea856f78260f2b9c8
Deleted: sha256:ce0858c76c8b6f563b8b24cdb8bf436185c3b0256e6b4d77c49a14988f261b57
Deleted: sha256:742679cd72080fdc4b0ef9db8b2cfa8435744cbfba8d44bdf09c4c06833a17e5
Deleted: sha256:674a7e69e2de6acf0381d33a2a7552b58c234336adabc5222503a790a9c3054a
Deleted: sha256:80c00999d70d57a27df83aaaf22f76b7ac4188d2e41a49308834a3f7e3f8fdb4
Deleted: sha256:0d1283f04c2787ebdd1f02dbb724c2f9c66d805589c4344fc51f65aebb185c28
Deleted: sha256:0fe55794a0f72aaff0eb77d3f88315fb5fe9a114c4395887f26d39139508ef26
[root@localhost ~]
4 导入镜像
[root@localhost ~]# docker load -i ./oracle_11g_20210904.tar
0fe55794a0f7: Loading layer [==================================================>] 204.3MB/204.3MB
f6a0170d328c: Loading layer [==================================================>] 119.8kB/119.8kB
afe0e25521f4: Loading layer [==================================================>] 119.8kB/119.8kB
4b23a6d29fb8: Loading layer [==================================================>] 112.1MB/112.1MB
a41279604774: Loading layer [==================================================>] 5.688GB/5.688GB
c28cc77e2537: Loading layer [==================================================>] 1.687GB/1.687GB
Loaded image: oracle/carl:latest
[root@localhost ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/carl latest a125ce4fdaec 21 minutes ago 7.65GB
[root@localhost ~]#
六、创建容器并验证数据库
[root@localhost ~]# docker run -itd -p 1521:1521 --name ora_carl oracle/carl
15a46618a0f4007540bdd41cb5e41c6fe69f071d04cf26b272dfa1a72f314cc9
[root@localhost ~]# docker exec -it ora_carl bash
[root@15a46618a0f4 /]# su - oracle
Last login: Sat Sep 4 14:34:18 UTC 2021 on pts/0
[oracle@15a46618a0f4 ~]$ ps -ef| grep ora_
oracle 38 1 0 14:34 ? 00:00:00 ora_pmon_orcl
oracle 40 1 0 14:34 ? 00:00:00 ora_vktm_orcl
oracle 44 1 0 14:34 ? 00:00:00 ora_gen0_orcl
oracle 46 1 0 14:34 ? 00:00:00 ora_diag_orcl
oracle 48 1 0 14:34 ? 00:00:00 ora_dbrm_orcl
oracle 50 1 0 14:34 ? 00:00:00 ora_psp0_orcl
oracle 52 1 0 14:34 ? 00:00:00 ora_dia0_orcl
oracle 54 1 0 14:34 ? 00:00:00 ora_mman_orcl
oracle 56 1 8 14:34 ? 00:00:03 ora_dbw0_orcl
oracle 58 1 0 14:34 ? 00:00:00 ora_lgwr_orcl
oracle 60 1 0 14:34 ? 00:00:00 ora_ckpt_orcl
oracle 62 1 0 14:34 ? 00:00:00 ora_smon_orcl
oracle 64 1 0 14:34 ? 00:00:00 ora_reco_orcl
oracle 66 1 0 14:34 ? 00:00:00 ora_mmon_orcl
oracle 68 1 0 14:34 ? 00:00:00 ora_mmnl_orcl
oracle 70 1 0 14:34 ? 00:00:00 ora_d000_orcl
oracle 72 1 0 14:34 ? 00:00:00 ora_s000_orcl
oracle 113 1 9 14:34 ? 00:00:00 ora_p000_orcl
oracle 115 1 1 14:34 ? 00:00:00 ora_p001_orcl
oracle 117 1 14 14:34 ? 00:00:00 ora_p002_orcl
oracle 119 95 0 14:34 pts/1 00:00:00 grep --color=auto ora_
[oracle@15a46618a0f4 ~]$ sqlplus as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Sat Sep 4 14:35:03 2021
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, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
SQL> conn carl/oracle
Connected.
SQL> select * From cat;
TABLE_NAME TABLE_TYPE
------------------------------ -----------
T_CARL_TEST TABLE
SQL> select * From T_CARL_TEST;
ID NAME
---------- --------------------
1 carl
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
[oracle@15a46618a0f4 ~]$ exit
logout
[root@15a46618a0f4 /]# exit
exit
[root@localhost ~]#