1,下载Oracle镜像
docker pull registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
2,启动容器
docker run -d -p 1521:1521 --name oracle registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g
3,查看所有的容器
sudo docker ps
4,启动已经停止的容器
sudo docker start [container id]
5,进入容器
sudo docker exec -it oracle /bin/bash
6,退出容器
sudo exit
7,修改Oracle用户信息
[root@e2ab0x9jme3furrd ~]# docker exec -it oracle01 /bin/bash [oracle@a49ca77e4a58 /]$ cd /home/oracle [oracle@a49ca77e4a58 ~]$ source .bash_profile [oracle@a49ca77e4a58 ~]$ sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 3 15:10:28 2021 Copyright (c) 1982, 2009, Oracle. All rights reserved. SQL> conn /as sysdba Connected. SQL> alter user system identified by system; User altered. SQL> alter user sys identified by system; User altered. SQL> create user mike identified by mikeops; User created. SQL> grant connect, resource, dba to mike; Grant succeeded. SQL> alter profile default limit password_life_time unlimited; Profile altered. SQL> alter system set processes=2000 scope=spfile; System altered. SQL> select * from dba_users t where t.username='MIKE'; USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- MIKE 91 USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- OPEN USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- USERS TEMP 03-DEC-21 USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- DEFAULT DEFAULT_CONSUMER_GROUP USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- 10G 11G N PASSWORD USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- SQL>
8,重启Oracle
sudo docker restart oracle9,设置开机启动Oracle
sudo docker update oracle --restart=always10,使用 Navicat 连接
连接类型: Basic 主机:你的ip 端口: 1521 服务名: helowin SID 用户名:mike 密码:mikeops 查看容器日志 [root@Mike-node1 oracle]# docker logs -f oracle /home/oracle/app/oracle/product/11.2.0/dbhome_2 Processing Database instance "helowin": log file /home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log Redo Buffers 7360512 bytes ORA-00214: control file '/home/oracle/app/oracle/oradata/helowin/control01.ctl' version 851 inconsistent with file '/home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl' version 841 SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options /home/oracle/app/oracle/product/11.2.0/dbhome_2/bin/dbstart: Database instance "helowin" warm started. tail: unrecognized file system type 0x794c7630 for `/home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log'. Reverting to polling. 发现有错误我们进入容器内部解决一下 [root@Mike-node1 oracle]# docker exec -it oracle bash [oracle@1de544fa2642 /]$ cd /home/oracle/ [oracle@1de544fa2642 ~]$ source .bash_profile [oracle@1de544fa2642 ~]$ rm -rf /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl [oracle@1de544fa2642 ~]$ [oracle@1de544fa2642 ~]$ cp /home/oracle/app/oracle/oradata/helowin/control01.ctl /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl [oracle@1de544fa2642 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 18 13:36:42 2020 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> shutdown immediate ORA-01507: database not mounted ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 1603411968 bytes Fixed Size 2213776 bytes Variable Size 402655344 bytes Database Buffers 1191182336 bytes Redo Buffers 7360512 bytes Database mounted. Database opened.
11,第二种方式(持久化)
使用docker-compose安装: 创建docker-compose文件 [root@Mike-node1 ~]# mkdir -p /data/oracle [root@Mike-node1 ~]# cd /data/oracle [root@Mike-node1 oracle]# vim docker-compose.yml version: '3.1' services: master: image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g container_name: oracle privileged: true ports: - 1521:1521 [root@Mike-node1 oracle]# 启动容器进去修改配置: [root@Mike-node1 oracle]# docker-compose up -d Creating network "oracle_default" with the default driver Creating oracle ... done [root@Mike-node1 oracle]# docker exec -it oracle bash [oracle@7b3e628db32d /]$ cd /home/oracle/ [oracle@7b3e628db32d ~]$ source .bash_profile [oracle@7b3e628db32d ~]$ 在容器里配置数据库用户: [oracle@7b3e628db32d ~]$ sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 18 13:14:15 2020 Copyright (c) 1982, 2009, Oracle. All rights reserved. SQL> conn /as sysdba Connected. SQL> alter user system identified by system; User altered. SQL> alter user sys identified by system; User altered. SQL> create user mike identified by yca1cahk; User created. SQL> grant connect,resource,dba to mike; Grant succeeded. SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED; Profile altered. SQL> alter system set processes=2000 scope=spfile; System altered. SQL> select * from dba_users t where t.username = 'MIKE'; USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- MIKE 91 USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- OPEN USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- USERS TEMP 18-NOV-20 USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- DEFAULT DEFAULT_CONSUMER_GROUP USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- 10G 11G N PASSWORD USERNAME USER_ID PASSWORD ------------------------------ ---------- ------------------------------ ACCOUNT_STATUS LOCK_DATE EXPIRY_DA -------------------------------- --------- --------- DEFAULT_TABLESPACE TEMPORARY_TABLESPACE CREATED ------------------------------ ------------------------------ --------- PROFILE INITIAL_RSRC_CONSUMER_GROUP ------------------------------ ------------------------------ EXTERNAL_NAME -------------------------------------------------------------------------------- PASSWORD E AUTHENTI -------- - -------- SQL> 配置用户 mike 密码为 yca1cahk 使用 Navicat 连接是否可以登录(Navicat)教程上面有 持久化操作,在宿主机上使用命令 [root@Mike-node1 ~]# docker cp oracle:/home/oracle/app/oracle/oradata/helowin/ /data/oracle/ [root@Mike-node1 ~]# cd /data/oracle/ [root@Mike-node1 oracle]# ll -h total 8.0K -rw-r--r-- 1 root root 176 Nov 18 13:07 docker-compose.yml drwxr-x--- 2 root root 4.0K Nov 18 13:10 helowin [root@Mike-node1 oracle]# [root@Mike-node1 oracle]# chown -R 500.500 helowin/ [root@Mike-node1 oracle]# ll total 8 -rw-r--r-- 1 root root 176 Nov 18 13:07 docker-compose.yml drwxr-x--- 2 500 500 4096 Nov 18 13:10 helowin [root@Mike-node1 oracle]# cd helowin/ [root@Mike-node1 helowin]# ll total 1626084 -rw-r----- 1 500 500 10076160 Nov 18 13:21 control01.ctl -rw-r----- 1 500 500 9748480 Jan 4 2016 control01.ctl.bak -rw-r----- 1 500 500 104865792 Nov 18 13:10 example01.dbf -rw-r----- 1 500 500 52429312 Nov 18 13:21 redo01.log -rw-r----- 1 500 500 52429312 Nov 18 13:10 redo02.log -rw-r----- 1 500 500 52429312 Nov 18 13:10 redo03.log -rw-r----- 1 500 500 534781952 Nov 18 13:21 sysaux01.dbf -rw-r----- 1 500 500 713039872 Nov 18 13:21 system01.dbf -rw-r----- 1 500 500 30416896 Jan 4 2016 temp01.dbf -rw-r----- 1 500 500 99622912 Nov 18 13:21 undotbs01.dbf -rw-r----- 1 500 500 5251072 Nov 18 13:10 users01.dbf [root@Mike-node1 helowin]# 并且把 helowin 目录所有者赋予 500,因为500是容器内 oracle 组合用户的 id 关闭容器并且添加配置 [root@Mike-node1 oracle]# docker-compose down Stopping oracle ... done Removing oracle ... done Removing network oracle_default [root@Mike-node1 oracle]# vim docker-compose.yml version: '3.1' services: master: image: registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g container_name: oracle privileged: true ports: - 1521:1521 volumes: - ./helowin/:/home/oracle/app/oracle/oradata/helowin/ [root@Mike-node1 oracle]# [root@Mike-node1 oracle]# docker-compose up -d Creating network "oracle_default" with the default driver Creating oracle ... done [root@Mike-node1 oracle]# 查看容器日志 [root@Mike-node1 oracle]# docker logs -f oracle /home/oracle/app/oracle/product/11.2.0/dbhome_2 Processing Database instance "helowin": log file /home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log Redo Buffers 7360512 bytes ORA-00214: control file '/home/oracle/app/oracle/oradata/helowin/control01.ctl' version 851 inconsistent with file '/home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl' version 841 SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options /home/oracle/app/oracle/product/11.2.0/dbhome_2/bin/dbstart: Database instance "helowin" warm started. tail: unrecognized file system type 0x794c7630 for `/home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log'. Reverting to polling. 发现有错误我们进入容器内部解决一下 [root@Mike-node1 oracle]# docker exec -it oracle bash [oracle@1de544fa2642 /]$ cd /home/oracle/ [oracle@1de544fa2642 ~]$ source .bash_profile [oracle@1de544fa2642 ~]$ rm -rf /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl [oracle@1de544fa2642 ~]$ [oracle@1de544fa2642 ~]$ cp /home/oracle/app/oracle/oradata/helowin/control01.ctl /home/oracle/app/oracle/flash_recovery_area/helowin/control02.ctl [oracle@1de544fa2642 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Wed Nov 18 13:36:42 2020 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> shutdown immediate ORA-01507: database not mounted ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 1603411968 bytes Fixed Size 2213776 bytes Variable Size 402655344 bytes Database Buffers 1191182336 bytes Redo Buffers 7360512 bytes Database mounted. Database opened. SQL> 里面的操作是删除新生成的版本控制文件,将数据卷中的版本控制文件复制为新生成的版本控制文件 然后关闭数据库实例,再启动数据库实例 再次使用 Navicat 连接 Oracle,使用刚刚的用户看是否可以连接 检查发现可以正常连接之后,我们身边在数据库创建几张表或者用户 然后我们做一波骚操作,重启一下 oracle 容器看是否可以保存数据不丢失!!! [root@Mike-node1 oracle]# ll total 8 -rw-r--r-- 1 root root 249 Nov 18 13:30 docker-compose.yml drwxr-x--- 2 500 500 4096 Nov 18 13:10 helowin [root@Mike-node1 oracle]# docker-compose stop Stopping oracle ... done [root@Mike-node1 oracle]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@Mike-node1 oracle]# [root@Mike-node1 oracle]# docker-compose start Starting master ... done [root@Mike-node1 oracle]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1de544fa2642 registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g "/bin/sh -c '/home/o…" 16 minutes ago Up 2 seconds 0.0.0.0:1521->1521/tcp oracle [root@Mike-node1 oracle]# [root@Mike-node1 oracle]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 [::]:1521 [::]:* LISTEN 0 100 [::1]:25 [::]:* [root@Mike-node1 oracle]#
然后可以发现数据库里面的用户和表都还在,持久化顺利完成后期还是建议使用持久化来搭建 oracle,因为不做持久化重启的话数据会丢失哦~ 标签:Dockers,11g,------------------------------,---------,Mike,oracle,Oracle,node1,ro From: https://www.cnblogs.com/zengwb/p/16601061.html