一步步教你如何在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 lvm2Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.comResolving 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_8Dependency 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.el7Updated:device-mapper-persistent-data.x86_64 0:0.8.5-3.el7_9.2 lvm2.x86_64 7:2.02.187-6.el7_9.5Dependency 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.5device-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.5Complete![root@localhost ~]#
2 添加阿里镜像源
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repoLoaded plugins: fastestmirroradding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repograbbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to etc/yum.repos.d/docker-ce.reporepo saved to etc/yum.repos.d/docker-ce.repo[root@localhost ~]#
3 安装docker-ce
[root@localhost ~]# yum -y install docker-ceLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.comdocker-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:00Resolving 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/22Verifying : libcgroup-0.41-21.el7.x86_64 19/22Verifying : audit-2.8.4-4.el7.x86_64 20/22Verifying : policycoreutils-2.5-29.el7.x86_64 21/22Verifying : audit-libs-2.8.4-4.el7.x86_64 22/22Installed:docker-ce.x86_64 3:20.10.8-3.el7Dependency 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.el7docker-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_8fuse3-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.el7python-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_8Dependency 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.el7Complete![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 infoClient:Context: defaultDebug Mode: falsePlugins: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: 0Running: 0Paused: 0Stopped: 0Images: 0Server Version: 20.10.8Storage Driver: overlay2Backing Filesystem: xfsSupports d_type: trueNative Overlay Diff: trueuserxattr: falseLogging Driver: json-fileCgroup Driver: cgroupfsCgroup Version: 1Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslogSwarm: inactiveRuntimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2Default Runtime: runcInit Binary: docker-initcontainerd version: e25210fe30a0a703442421b0f60afac609f950a3runc version: v1.0.1-0-g4144b63init version: de40ad0Security Options:seccompProfile: defaultKernel Version: 3.10.0-957.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 4Total Memory: 1.934GiBName: localhost.localdomainID: 3FDJ:AF6Z:4GCF:YK4E:NGXG:7EDN:JEDK:MWFK:6YNZ:BR77:KVLF:XNPADocker Root Dir: var/lib/dockerDebug Mode: falseRegistry: https://index.docker.io/v1/Labels:Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false[root@localhost ~]#
三、镜像操作
1 查找镜像 docker search oracle_11g
[root@localhost ~]# docker search oracle_11gNAME DESCRIPTION STARS OFFICIAL AUTOMATEDiatebes/oracle_11g Docker image for Oracle Database 11g 11lhrbest/oracle_11g_ee_lhr_11.2.0.3 Oracle 11g 企业版, 11.2.0.3 ,QQ:646634621… 3lhrbest/oracle_11g_ee_lhr_11.2.0.4 Oracle 11g 企业版, 11.2.0.4 ,QQ:646634621… 2jiangbodocker/oracle_11g_r2_logminer 开启了logminer的oracle数据库 1pan2056/oracle_11g 0aswuhuaqiang/oracle_11g oracle_11g 0cetrdpd/oracle_11g 0jingmei2/oracle_11g 0helpuser/oracle_11g 0hogwartsrow/oracle_11g 0oussemos/oracle_11g 0411646865/oracle_11gr2 0akaiot/oracle_11g oracle镜像来自registry.cn-hangzhou.aliyuncs.… 0jeffpear/oracle_11g 0dalibeans/oracle_11g 0itheshe/oracle_11g 0heyulong/oracle_11g 0vinay404219/oracle_11g 0848672861/oracle_11g 0wushipeng/oracle_11g 0kbm0417/oracle_11g 0q543738006/oracle_11g 072machi/oracle_11g 오라클 11g 0faustobuscema/oracle_11g_r2_ee Oracle 11g R2 Enterprise Edition x64 Linux 0liuguipeng/oracle_11g oracle11g 0[root@localhost ~]#
2 拉取镜像 docker pull iatebes/oracle_11g
[root@localhost ~]# docker pull iatebes/oracle_11gUsing default tag: latestlatest: Pulling from iatebes/oracle_11g8c3d77a518cb: Pull complete15e5453594e1: Pull complete686bc2cca543: Pull complete34b7824dbc5e: Pull completebf6403b14c96: Pull completeDigest: sha256:73c7f39e1e69dce1599c2f2f82819a02e51ccc6172697e8ea856f78260f2b9c8Status: Downloaded newer image for iatebes/oracle_11g:latestdocker.io/iatebes/oracle_11g:latest[root@localhost ~]#
3 查看镜像 docker images ls
[root@localhost docker]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEiatebes/oracle_11g latest ce0858c76c8b 5 years ago 5.97GB
4 启动容器
[root@localhost docker]# docker run -itd -p 1521:1521 --name oracle11g iatebes/oracle_11g8ae5b2c187db45fd154ba80471ea11f4561fadc72fd6bcb1c0016373f5b7d9b9[root@localhost docker]#[root@localhost docker]# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8ae5b2c187db 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 - oracleLast login: Sat Sep 4 13:53:20 UTC 2021 on pts/0[oracle@8ae5b2c187db ~]$ sqlplus as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Sat Sep 4 13:57:22 2021Copyright (c) 1982, 2009, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP, Data Mining,Oracle Database Vault and Real Application Testing optionsSQL> select status from v$instance;STATUS------------OPENSQL>
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 carlSQL>
五、镜像的保存与导入
1 提交镜像
[root@localhost ~]# docker ps -qa8ae5b2c187db[root@localhost ~]# docker commit 8ae5b2c187db oracle/carlsha256:a125ce4fdaec9ab354e3e80a2b99f5b671583ffc334b6749d1623937e7da2fc1[root@localhost ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEoracle/carl latest a125ce4fdaec About a minute ago 7.65GBiatebes/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 -lrttotal 7511568-rw-------. 1 root root 7691844096 Sep 4 10:20 oracle_11g_20210904.tar[root@localhost ~]#
3 删除之前拉取镜像与提交镜像
[root@localhost ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEoracle/carl latest a125ce4fdaec 13 minutes ago 7.65GBiatebes/oracle_11g latest ce0858c76c8b 5 years ago 5.97GB[root@localhost ~]# docker rmi a125ce4fdaec ce0858c76c8bUntagged: iatebes/oracle_11g:latestUntagged: iatebes/oracle_11g@sha256:73c7f39e1e69dce1599c2f2f82819a02e51ccc6172697e8ea856f78260f2b9c8Deleted: sha256:ce0858c76c8b6f563b8b24cdb8bf436185c3b0256e6b4d77c49a14988f261b57Deleted: sha256:742679cd72080fdc4b0ef9db8b2cfa8435744cbfba8d44bdf09c4c06833a17e5Deleted: sha256:674a7e69e2de6acf0381d33a2a7552b58c234336adabc5222503a790a9c3054aDeleted: sha256:80c00999d70d57a27df83aaaf22f76b7ac4188d2e41a49308834a3f7e3f8fdb4Deleted: sha256:0d1283f04c2787ebdd1f02dbb724c2f9c66d805589c4344fc51f65aebb185c28Deleted: sha256:0fe55794a0f72aaff0eb77d3f88315fb5fe9a114c4395887f26d39139508ef26[root@localhost ~]
4 导入镜像
[root@localhost ~]# docker load -i ./oracle_11g_20210904.tar0fe55794a0f7: Loading layer [==================================================>] 204.3MB/204.3MBf6a0170d328c: Loading layer [==================================================>] 119.8kB/119.8kBafe0e25521f4: Loading layer [==================================================>] 119.8kB/119.8kB4b23a6d29fb8: Loading layer [==================================================>] 112.1MB/112.1MBa41279604774: Loading layer [==================================================>] 5.688GB/5.688GBc28cc77e2537: Loading layer [==================================================>] 1.687GB/1.687GBLoaded image: oracle/carl:latest[root@localhost ~]# docker image lsREPOSITORY TAG IMAGE ID CREATED SIZEoracle/carl latest a125ce4fdaec 21 minutes ago 7.65GB[root@localhost ~]#
六、创建容器并验证数据库
[root@localhost ~]# docker run -itd -p 1521:1521 --name ora_carl oracle/carl15a46618a0f4007540bdd41cb5e41c6fe69f071d04cf26b272dfa1a72f314cc9[root@localhost ~]# docker exec -it ora_carl bash[root@15a46618a0f4 /]# su - oracleLast 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_orcloracle 40 1 0 14:34 ? 00:00:00 ora_vktm_orcloracle 44 1 0 14:34 ? 00:00:00 ora_gen0_orcloracle 46 1 0 14:34 ? 00:00:00 ora_diag_orcloracle 48 1 0 14:34 ? 00:00:00 ora_dbrm_orcloracle 50 1 0 14:34 ? 00:00:00 ora_psp0_orcloracle 52 1 0 14:34 ? 00:00:00 ora_dia0_orcloracle 54 1 0 14:34 ? 00:00:00 ora_mman_orcloracle 56 1 8 14:34 ? 00:00:03 ora_dbw0_orcloracle 58 1 0 14:34 ? 00:00:00 ora_lgwr_orcloracle 60 1 0 14:34 ? 00:00:00 ora_ckpt_orcloracle 62 1 0 14:34 ? 00:00:00 ora_smon_orcloracle 64 1 0 14:34 ? 00:00:00 ora_reco_orcloracle 66 1 0 14:34 ? 00:00:00 ora_mmon_orcloracle 68 1 0 14:34 ? 00:00:00 ora_mmnl_orcloracle 70 1 0 14:34 ? 00:00:00 ora_d000_orcloracle 72 1 0 14:34 ? 00:00:00 ora_s000_orcloracle 113 1 9 14:34 ? 00:00:00 ora_p000_orcloracle 115 1 1 14:34 ? 00:00:00 ora_p001_orcloracle 117 1 14 14:34 ? 00:00:00 ora_p002_orcloracle 119 95 0 14:34 pts/1 00:00:00 grep --color=auto ora_[oracle@15a46618a0f4 ~]$ sqlplus as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Sat Sep 4 14:35:03 2021Copyright (c) 1982, 2009, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP, Data Mining,Oracle Database Vault and Real Application Testing optionsSQL> conn carl/oracleConnected.SQL> select * From cat;TABLE_NAME TABLE_TYPE------------------------------ -----------T_CARL_TEST TABLESQL> select * From T_CARL_TEST;ID NAME---------- --------------------1 carlSQL> exitDisconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, Oracle Label Security, OLAP, Data Mining,Oracle Database Vault and Real Application Testing options[oracle@15a46618a0f4 ~]$ exitlogout[root@15a46618a0f4 /]# exitexit[root@localhost ~]#