要给开发人员搭建 Oracle 测试环境,准备基于 Docker 构建,同时建立一个 Docker 私有仓库,谁需要就让他装一个 Docker,才从这私有仓库 pull 镜像即可。
环境如下:
CentOS 7
docker-ce-18.03.1.ce-1.el7.centos.x86_64
Oracle 12c
安装Docker
# step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo
# Step 3: 更新并安装Docker-CE
yum makecache && yum -y install docker-ce
# Step 4: 开启Docker服务
systemctl start docker
搜索并下载Oracle镜像
列出收藏数大于100的镜像
[root@Docker ~]# docker search -s 100 oracle
Flag --stars has been deprecated, use --filter=stars=3 instead
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
oraclelinux Official Docker builds of Oracle Linux. 451 [OK]
frolvlad/alpine-oraclejdk8 The smallest Docker image with OracleJDK 8 (… 303 [OK]
sath89/oracle-12c Oracle Standard Edition 12c Release 1 with d… 296 [OK]
alexeiled/docker-oracle-xe-11g This is a working (hopefully) Oracle XE 11.2… 252 [OK]
sath89/oracle-xe-11g Oracle xe 11g with database files mount supp… 185 [OK]
# pull第三个镜像
# docker pull sath89/oracle-12c
运行镜像
#-P, 在容器中任何需要的网络端口都映射到主机。即将Docker镜像中的Oracle 1521端口映射到宿主机。
#-v 把docker 容器中某目录的数据 加载到 宿主机的某个目录。即将docker Oracle镜像的数据存储到/data/db 下
docker run -d -p 8080:8080 -p 1521:1521 -v /data/db/:/u01/app/oracle sath89/oracle-12c
启动速度较慢,我们可以去查看日志
# docker logs -f 032d6b2097e8cf3d4dfc3bf173a229bda0a5c8a8a51434299274c652698964a7
Database not initialized. Initializing database.
Starting tnslsnr
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/xe.log" for further details.
Configuring Apex console
Database initialized. Please visit #containeer:8080/em #containeer:8080/apex for extra configuration if needed
Starting web management console
PL/SQL procedure successfully completed.
Starting import from '/docker-entrypoint-initdb.d':
found file /docker-entrypoint-initdb.d//docker-entrypoint-initdb.d/*
[IMPORT] /entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
Import finished
Database ready to use. Enjoy! ;)
查看进程
[root@Docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3ceb1ae8637e sath89/oracle-12c "/entrypoint.sh " 10 seconds ago Up 4 seconds 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp unruffled_kare
配置Oracle