环境

CentOS 7.5

Docker 20.10.2

Oracle_11g

安装Oracle数据库

1.搜索oracle镜像

docker search oracle

[root@localhost ~]# docker search oracle
NAME                                  DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
oraclelinux                           Official Docker builds of Oracle Linux.         731       [OK]
jaspeen/oracle-11g                    Docker image for Oracle 11g database            169                  [OK]
oracleinanutshell/oracle-xe-11g                                                       138
wnameless/oracle-xe-11g-r2            Oracle Express Edition 11g Release 2 on Ubun…   58
absolutapps/oracle-12c-ee             Oracle 12c EE image with web management cons…   46
araczkowski/oracle-apex-ords          Oracle Express Edition 11g Release 2 on Ubun…   30                   [OK]
truevoly/oracle-12c                   Copy of sath89/oracle-12c image (https://git…   27
bofm/oracle12c                        Docker image for Oracle Database                24                   [OK]
datagrip/oracle                       Oracle 11.2 & 12.1.0.2-se2 & 11.2.0.2-xe        20                   [OK]
quillbuilduser/oracle-18-xe           Oracle 18c XE Image for Quill Testing Purpos…   20
openweb/oracle-tomcat                 A fork off of Official tomcat image with Ora…   8                    [OK]
binarybabel/oracle-jdk                Oracle JDKs (Alpine, CentOS, Debian) rebuilt…   5                    [OK]
iamseth/oracledb_exporter             A Prometheus exporter for Oracle modeled aft…   3
18fgsa/oracle-client                  Hosted version of the Oracle Container Image…   2
paulosalgado/oracle-java8-ubuntu-16   Oracle Java 8 on Ubuntu 16.04 LTS.              2                    [OK]
softwareplant/oracle                  oracle db                                       2                    [OK]
arm64v8/oraclelinux                   Official Docker builds of Oracle Linux.         1
roboxes/oracle7                       A generic Oracle Linux 7 base image.            1
publicisworldwide/oracle-core         This is the core image based on Oracle Linux…   1                    [OK]
amd64/oraclelinux                     Official Docker builds of Oracle Linux.         1
toolsmiths/oracle7-test                                                               0
bitnami/oraclelinux-extras            Oracle Linux base images                        0                    [OK]
bitnami/oraclelinux-runtimes          Oracle Linux runtime-optimized images           0                    [OK]
pivotaldata/oracle7-test              Oracle Enterprise Linux (OEL) image for GPDB…   0
gizmotronic/oracle-java               Ubuntu 16.04 image with Oracle Java             0                    [OK]

2.拉取阿里云oracle镜像

docker pull registry.aliyuncs.com/helowin/oracle_11g
或者 docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g

[root@localhost ~]# docker pull registry.aliyuncs.com/helowin/oracle_11g
Using default tag: latest
latest: Pulling from helowin/oracle_11g
ed5542b8e0e1: Already exists
a3ed95caeb02: Already exists
1e8f80d0799e: Already exists
Digest: sha256:4c12b98372dfcbaafcd9564a37c8d91456090a5c6fb07a4ec18270c9d9ef9726
Status: Image is up to date for registry.aliyuncs.com/helowin/oracle_11g:latest
registry.aliyuncs.com/helowin/oracle_11g:latest

3.查看镜像拉取情况

docker iamges

[root@localhost ~]# docker images
REPOSITORY                                             TAG          IMAGE ID       CREATED       SIZE
...
registry.aliyuncs.com/helowin/oracle_11g               latest       3fa112fd3642   5 years ago   6.85GB

4.创建并启动oracle容器

默认启动方式:

[root@localhost ~]# docker run -itd -p 1521:1521 --name oracle_11g --restart=always registry.aliyuncs.com/helowin/oracle_11g
持久化启动方式:

docker run  -itd -p 1521:1521 --name oracle --restart=always --mount source=oracle_vol,target=/home/oracle/app/oracle/oradata registry.aliyuncs.com/helowin/oracle_11g

5.查看进程与启动状态

[root@localhost ~]# netstat -antulp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:1521            0.0.0.0:*               LISTEN      35497/docker-proxy
......

[root@localhost ~]# ss -antulp | grep :1521
tcp    LISTEN     0      128       *:1521                  *:*                   users:(("docker-proxy",pid=35497,fd=4))

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                                      COMMAND                  CREATED        STATUS        PORTS                    NAMES
3edfba76f476   registry.aliyuncs.com/helowin/oracle_11g   "/bin/sh -c '/home/o…"   42 hours ago   Up 42 hours   0.0.0.0:1521->1521/tcp   oracle_11g

6.以退出不中断容器的方式进入容器

[root@localhost ~]# docker exec -it oracle_11g bash
[oracle@3edfba76f476 /]$

7.配置容器内环境变量

[root@localhost ~]# docker exec -it oracle_11g bash

1.切换为root用户
      # 密码默认为 helowin
[oracle@3edfba76f476 /]$ su root         
Password:                                

2.添加环境变量
[root@3edfba76f476 /]# vi /etc/profile      
...
     61 export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_2
     63 export ORACLE_SID=helowin
     65 export PATH=$ORACLE_HOME/bin:$PATH
...

3.使配置生效
[root@3edfba76f476 /]# source  /etc/profile

4.创建软链接
[root@3edfba76f476 /]# ln -s $ORACLE_HOME/bin/sqlplus /usr/bin

8.操作oracle

1.切换回oracle用户
[root@3edfba76f476 /]# su - oracle

2.登录sqlplus
[oracle@3edfba76f476 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Sat Jan 30 16:32:18 2021

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

SQL> conn /as sysdba;
Connected.

3.修改sys、system用户密码
SQL> alter user system identified by 123456;

SQL> alter user sys identified by 123456;

SQL> alter profile default limit PASSWORD_LIFE_TIME UNLIMITED;

4.创建用户
SQL> create user root identified by 123456;

SQL> grant connect,resource,dba to root;

SQL> show user;      # 查看当前用户
USER is "SYS"

注意

外部工具连接数据库时,需要配置开放防火墙相应端口。若是阿里云,则需要开放安全组。**

来源;https://www.modb.pro/db/113366

最后修改:2021 年 10 月 01 日
如果觉得我的文章对你有用,请随意赞赏