使用 docker 安装 Oracle

docker 安装

[root@localhost ~]# yum install docker
[root@localhost ~]# docker version
[root@localhost ~]# service docker start
Redirecting to /bin/systemctl start docker.service
[root@localhost ~]# chkconfig docker on
Note: Forwarding request to 'systemctl enable docker.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# systemctl enable docker.service

选择 oracle 镜像

[root@laptop-6cfrmtbs ~]# docker search Oracle
INDEX       NAME                                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/oraclelinux                       Official Docker builds of Oracle Linux.         954       [OK]
docker.io   docker.io/oracleinanutshell/oracle-xe-11g                                                   247
docker.io   docker.io/gvenzl/oracle-xe                  Oracle Database XE (21c, 18c, 11g) for eve...   140
docker.io   docker.io/wnameless/oracle-xe-11g-r2        Oracle Express Edition 11g Release 2 on Ub...   91
docker.io   docker.io/truevoly/oracle-12c               Copy of sath89/oracle-12c image (https://g...   48
docker.io   docker.io/quillbuilduser/oracle-18-xe       Oracle 18c XE Image for Quill Testing Purp...   27
docker.io   docker.io/oracledb19c/oracle.19.3.0-ee                                                      20
docker.io   docker.io/iamseth/oracledb_exporter         A Prometheus exporter for Oracle modeled a...   5
docker.io   docker.io/oraclecoherence/coherence-ce      Coherence Community Edition                     5
docker.io   docker.io/18fgsa/oracle-client              Hosted version of the Oracle Container Ima...   2
docker.io   docker.io/kasmweb/oracle-8-desktop          Oracle Linux 8 desktop for Kasm Workspaces      2
docker.io   docker.io/dokken/oraclelinux-7              Oracle Linux 7 image for kitchen-dokken         1

拉取 oracle 镜像

[root@laptop-6cfrmtbs ~]# docker pull truevoly/oracle-12c
[root@laptop-6cfrmtbs ~]# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
docker.io/truevoly/oracle-12c   latest              21789d4d876f        3 years ago         5.7 GB

创建数据目录

[root@laptop-6cfrmtbs ~]# mkdir -p /data/oracle/data_temp && chmod 777 /data/oracle/data_temp

启动镜像

[root@laptop-6cfrmtbs ~]# docker run --restart always -d -p 8080:8080 -p 1521:1521 -v /data/oracle/data_temp:/home/oracle/data_temp -v /etc/localtime:/etc/localtime:ro --name orcl truevoly/oracle-12c
f3c47f17c05bd340f72b3f6f0b997c22bff13128fa33522e445c84012c617469
[root@laptop-6cfrmtbs ~]# docker logs -f f3c47f17c05bd340f72b3f6f0b997c22bff13128fa33522e445c84012c617469
Database not initialized. Initializing database.
Starting tnslsnr
Copying database files
1% complete
3% complete
11% complete
[root@laptop-6cfrmtbs ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                                            NAMES
f3c47f17c05b        truevoly/oracle-12c   "/entrypoint.sh "   6 minutes ago       Up 6 minutes        0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp   orcl

在容器中修改数据

[root@laptop-6cfrmtbs ~]# docker exec -it f3c47f17c05b sh

# sqlplus system/oracle@//localhost:1521/xe

SQL*Plus: Release 12.1.0.2.0 Production on Fri Dec 23 20:55:45 2022

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

Connected to:
Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
SQL> alter user SYSTEM identified by 123456;

User altered.

重启后启动容器

[root@192 ~]# docker ps -a
CONTAINER ID        IMAGE                 COMMAND             CREATED             STATUS              PORTS                                            NAMES
f3c47f17c05b        truevoly/oracle-12c   "/entrypoint.sh "   26 minutes ago      Up 8 minutes        0.0.0.0:1521->1521/tcp, 0.0.0.0:8080->8080/tcp   orcl
[root@192 ~]# docker start f3c47f17c05b
f3c47f17c05b

连接数据库

图片.png