获取并解压 oracle docker-images
下载地址:https://github.com/oracle/docker-images
yum install -y git
git clone https://github.com/oracle/docker-images.git
获取 Oracle 19C 的安装包
下载地址:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html#19c
# 将下载的 LINUX.X64_193000_db_home.zip 安装包放到以下对应版本的目录下面
# pwd
/root/docker-images-main/OracleDatabase/SingleInstance/dockerfiles
# ll
total 28
drwxr-xr-x. 2 root root 126 Apr 11 07:00 11.2.0.2
drwxr-xr-x. 2 root root 4096 Apr 11 07:00 12.1.0.2
drwxr-xr-x. 2 root root 4096 Apr 11 07:00 12.2.0.1
drwxr-xr-x. 2 root root 4096 Apr 11 07:00 18.3.0
drwxr-xr-x. 2 root root 140 Apr 11 07:00 18.4.0
drwxr-xr-x. 2 root root 4096 Apr 11 07:00 19.3.0 #<<<<<<<<<<<<<<<<<<<<<
drwxr-xr-x. 2 root root 4096 Apr 11 07:00 21.3.0
-rwxr-xr-x. 1 root root 7091 Apr 11 07:00 buildContainerImage.sh
# mv /opt/LINUX.X64_193000_db_home.zip /root/docker-images-main/OracleDatabase/SingleInstance/dockerfiles/19.3.0
buildContainerImage 构造镜像,也就是安装软件
- buildContainerImage.sh 脚本的帮助信息
- 参考文档:https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md
[root@docker dockerfiles]# ./buildContainerImage.sh --help
./buildContainerImage.sh: illegal option -- -
Usage: buildContainerImage.sh -v [version] -t [image_name:tag] [-e | -s | -x] [-i] [-o] [container build option]
Builds a container image for Oracle Database.
Parameters:
-v: version to build
Choose one of: 11.2.0.2 12.1.0.2 12.2.0.1 18.3.0 18.4.0 19.3.0 21.3.0
-t: image_name:tag for the generated docker image
-e: creates image based on 'Enterprise Edition'
-s: creates image based on 'Standard Edition 2'
-x: creates image based on 'Express Edition'
-i: ignores the MD5 checksums
-o: passes on container build option
* select one edition only: -e, -s, or -x
LICENSE UPL 1.0
Copyright (c) 2014,2021 Oracle and/or its affiliates.
- 构造示例
# ./buildContainerImage.sh -v 19.3.0 -e -i
... ...
Successfully built 0f5efdb488d8
Successfully tagged oracle/database:19.3.0-ee
Oracle Database container image for 'ee' version 19.3.0 is ready to be extended:
--> oracle/database:19.3.0-ee
Build completed in 951 seconds.
- 查看
# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
oracle/database 19.3.0-ee 0f5efdb488d8 5 minutes ago 6.54GB
docker run 安装数据库
- docker run 的参考文档:https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md
- 创建一个持久化数据的目录
mkdir -p /docker_data/oracle chmod -R a+rwx /docker_data/oracle/
- docker run 的格式
docker run --name <container name> \
-p <host port>:1521 -p <host port>:5500 \
-e ORACLE_SID=<your SID> \
-e ORACLE_PDB=<your PDB name> \
-e ORACLE_PWD=<your database passwords> \
-e INIT_SGA_SIZE=<your database SGA memory in MB> \
-e INIT_PGA_SIZE=<your database PGA memory in MB> \
-e ORACLE_EDITION=<your database edition> \
-e ORACLE_CHARACTERSET=<your character set> \ # AL32UTF8 or ZHS16GBK
-e ENABLE_ARCHIVELOG=true \
-v [<host mount point>:]/opt/oracle/oradata \
-v [<host mount point>:]/opt/oracle/scripts/startup \
-v [<host mount point>:]/opt/oracle/scripts/setup
oracle/database:19.3.0-ee
- docker run 的示例
docker run --name ora19c \
-p 1521:1521 \
-e ORACLE_SID=orcl \
-e ORACLE_PDB=pdbtt \
-e ORACLE_PWD=oracle \
-e INIT_SGA_SIZE=512 \
-e INIT_PGA_SIZE=128 \
-e ORACLE_EDITION=enterprise \
-e ORACLE_CHARACTERSET=ZHS16GBK \
-e ENABLE_ARCHIVELOG=true \
-v /docker_data/oracle:/opt/oracle/oradata \
oracle/database:19.3.0-ee
- 查看
# docker ps
# docker exec -it ora19c bash
[oracle@c763a21ec3ec ~]$ lsnrctl status
[oracle@c763a21ec3ec ~]$ export ORACLE_SID=ORCL
[oracle@c763a21ec3ec ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Apr 16 13:22:51 2022 Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> show pdbs;
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDBTT READ WRITE NO
SQL> create table tt (id int);
SQL> insert into tt values (11);
SQL> commit;
管理 Oracle 容器
- 关闭容器
[root@docker ~]# docker stop ora19c
- 启动容器
[root@docker ~]# docker start ora19c
# 数据持久化
SQL> select * from tt;
ID
----------
11
- docker 宿主机安装 Oracle 客户端
客户端下载地址:https://www.oracle.com/cn/database/technologies/instant-client/linux-x86-64-downloads.html
rpm -ivh oracle-instantclient19.12-basic-19.12.0.0.0-1.x86_64.rpm rpm -ivh oracle-instantclient19.12-devel-19.12.0.0.0-1.x86_64.rpm rpm -ivh oracle-instantclient19.12-jdbc-19.12.0.0.0-1.x86_64.rpm rpm -ivh oracle-instantclient19.12-sqlplus-19.12.0.0.0-1.x86_64.rpm
- 配置客户端的环境变量
# vi /etc/profile
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export TNS_ADMIN=/usr/lib/oracle/19.12/client64/network/admin
export ORACLE_HOME=/usr/lib/oracle/19.12/client64
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
# source /etc/profile
- 客户端连接 Oracle PDB
[oracle@ora11g ~]$ sqlplus sys/oracle@192.168.0.40:1521/pdbtt as sysdba
- 在 PDB 中创建 SCOTT 测试环境,为后续做实验做准备
[oracle@ora11g ~]$ sqlplus sys/oracle@192.168.0.40:1521/pdbtt as sysdba
SQL> create user scott identified by scott DEFAULT TABLESPACE USERS;
SQL> grant connect,resource,create view to scott;
SQL> GRANT UNLIMITED TABLESPACE TO scott;
[oracle@ora11g ~]$ sqlplus scott/scott@192.168.0.40:1521/pdbtt
SQL> @scott.sql
SQL> set line 100 pages 100
SQL> select * from scott.emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
查看 docker run 的运行参数配置
[root@docker ~]# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike ora19c
docker run --name=ora19c --hostname=c763a21ec3ec --user=oracle --mac-address=02:42:ac:11:00:03 --env=ORACLE_EDITION=enterprise --env=ORACLE_CHARACTERSET=ZHS16GBK ... ...
# 加到别名里,方便以后使用
alias runlike="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike"
docker ps
runlike ora19c
最后修改时间:2022-04-16 22:35:40
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。