Docker快速安装Oracle 12c
Posted 石头wang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker快速安装Oracle 12c相关的知识,希望对你有一定的参考价值。
【Oracle系列3】Docker快速安装Oracle 12c
背景
现在还很多企业用12c,以这个版本为例,介绍docker快速启动Oracle并做实验
步骤
1、docker环境的安装(略)
2、查询镜像,挑选镜像
docker search oracle
结果
StoneMakPro2019:~ stonewang$ docker search oracle
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
oraclelinux Official Docker builds of Oracle Linux. 951 [OK]
oracleinanutshell/oracle-xe-11g 242
gvenzl/oracle-xe Oracle Database XE (21c, 18c, 11g) for every… 132
wnameless/oracle-xe-11g-r2 Oracle Express Edition 11g Release 2 on Ubun… 90
truevoly/oracle-12c Copy of sath89/oracle-12c image (https://git… 47
quillbuilduser/oracle-18-xe Oracle 18c XE Image for Quill Testing Purpos… 28
oracledb19c/oracle.19.3.0-ee 19
iamseth/oracledb_exporter A Prometheus exporter for Oracle modeled aft… 5
oraclecoherence/coherence-ce Coherence Community Edition 5
18fgsa/oracle-client Hosted version of the Oracle Container Image… 2
kasmweb/oracle-8-desktop Oracle Linux 8 desktop for Kasm Workspaces 2
kasmweb/core-oracle-8 Oracle Linux 8 base image for Kasm Workspace… 1
kasmweb/core-oracle-7 Oracle Linux 7 base image for Kasm Workspace… 1
dokken/oraclelinux-7 Oracle Linux 7 image for kitchen-dokken 1
dokken/oraclelinux-8 1
kasmweb/oracle-7-desktop Oracle Linux 7 desktop for Kasm Workspaces 1
redislabs/redis-connect-oracle Redis Connect Oracle Connector for Continuou… 1
oracledemo1/hello-world Test docker build from github 0 [OK]
bitnami/oraclelinux-runtimes Oracle Linux runtime-optimized images 0 [OK]
dokken/oraclelinux-9 0
oraclejmx/docker_jmx 0
bitnami/oraclelinux-extras Oracle Linux base images 0 [OK]
oraclejp/weather-collector 0
dokken/oraclelinux-6 Oracle Linux 6 image for kitchen-dokken 0
bitnami/oraclelinux-extras-base 0
StoneMakPro2019:~ stonewang$
选择truevoly/oracle-12c这个镜像,我们不用官方那个,即上面第一个,因为官方没有想要的版本
另外,其实可以到 hub.docker.com 中搜索,跟命令行搜出来是差不多的
也有这个
3、下载镜像
StoneMakPro2019:~ stonewang$ docker pull docker.io/truevoly/oracle-12c
下载好后使用 docker images
确认一下,可以看到镜像5.7G挺大的
StoneMakPro2019:~ stonewang$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest c2342258f8ca 4 weeks ago 117MB
truevoly/oracle-12c latest 21789d4d876f 3 years ago 5.7GB
StoneMakPro2019:~ stonewang$
4、创建数据备份的目录
在宿主机创建这样的目录,我是mac,win的话应该是差不都吧?
mkdir /Users/stonewang/dev/thirdparty/oracle_data && chmod 777 /Users/stonewang/dev/thirdparty/oracle_data
5、启动
以image为模板启动
docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /Users/stonewang/dev/thirdparty/oracle_data:/home/oracle/data_temp -v /etc/localtime:/etc/localtime:ro --name oracle truevoly/oracle-12c
执行之后会返回容器的id (要改的话改前面的路径即可,比如改/Users/stonewang/dev/thirdparty/oracle_data
, --name oracle
是容器名可以改可以不改,其他可以保持不变即可)
StoneMakPro2019:~ stonewang$ docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /Users/stonewang/dev/thirdparty/oracle_data:/home/oracle/data_temp -v /etc/localtime:/etc/localtime:ro --name oracle truevoly/oracle-12c
90128ded2a6b96e57d8696acf06f7b0ac31ca160919accf6bdd6c3f43593d1b9
在用容器id查进度
StoneMakPro2019:~ stonewang$ docker logs -f 90128ded2a6b96e57d8696acf06f7b0ac31ca160919accf6bdd6c3f43593d1b9
Database not initialized. Initializing database.
Starting tnslsnr
Copying database files
1% complete
3% complete
11% complete
等到100%之后再继续提示如下,按下ctrl+c退出
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/xe.log" for further details.
Configuring Apex console
Database initialized. Please visit http://#containeer:8080/em http://#containeer:8080/apex for extra configuration if needed
Starting web management console
PL/SQL procedure successfully completed.
Starting import from '/docker-entrypoint-initdb.d':
ls: cannot access /docker-entrypoint-initdb.d/*: No such file or directory
Import finished
Database ready to use. Enjoy! ;)
其实不用等到100%也可以登录上去,但是呢,再执行其他命令会有点异常,所以还是等到100%之后再说,需要几分钟时间。
6、查看运行中的容器,并进入容器
查看运行中的容器有没有叫
docker ps
结果
StoneMakPro2019:~ stonewang$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90128ded2a6b truevoly/oracle-12c "/entrypoint.sh " 8 minutes ago Up 8 minutes 0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp oracle
StoneMakPro2019:~ stonewang$
进入容器(要带有/bin/bash)
docker exec -it 90128ded2a6b /bin/bash
结果
StoneMakPro2019:~ stonewang$ docker exec -it 90128ded2a6b /bin/bash
root@90128ded2a6b:/#
7、验证
在上述的结果输入 sqlplus
后回车
StoneMakPro2019:~ stonewang$ docker exec -it 90128ded2a6b /bin/bash
root@90128ded2a6b:/# sqlplus
SQL*Plus: Release 12.1.0.2.0 Production on Sun Nov 27 19:56:03 2022
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Enter user-name: system
Enter password:
Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
SQL> show user
USER is "SYSTEM"
SQL>
内置的账号有:
system,密码oracle
sys as sysdba,密码oracle(sys账号要用 as sysdba)
Enter user-name: sys as sysdba
Enter password:
Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
SQL> show user
USER is "SYS"
SQL>
show user 显示当前登录的账号。
7、也可以使用Navicat之类的连接
更加直观,system账号登录,按图填写,如Basic,1521,xe,选Service Name,Role为Default
sys账号登录
后续
如何关闭?
# 查看正在运行的容器,查看哪个是oracle的
docker ps
# 停止容器(后接容器ID)
docker stop 90128ded2a6b
如下次还需要用则启动一下即可
# 查看所有容器(因为docker ps只查运行中的容器,现在要启动,自然要能查看到已经停止的Oracle容器ID)
docker ps -a
# 启动容器(后接容器ID)
docker start 90128ded2a6b
以上是关于Docker快速安装Oracle 12c的主要内容,如果未能解决你的问题,请参考以下文章