请先安装Docker
version: '2'
services:
oracle11g:
image: filemon/oracle_11g
environment:
DBCA_TOTAL_MEMORY: 16192
ports:
- "3022:22"
- "31521:1521"
restart:
always
networks:
oracle11gnetwork:
driver: 'local'
将以上文件保存为docker-compose.yml文件
docker-compose up
启动docker-compose(后台模式-不打印日志)
docker-compose up -d
/home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log
Starting oracle11g1521_oracle_1 ... done
Attaching to oracle11g1521_oracle_1
oracle_1 | /home/oracle/app/oracle/product/11.2.0/dbhome_2
oracle_1 | Processing Database instance "orcl": log file /home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log
oracle_1 | tail: unrecognized file system type 0x794c7630 for `/home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log'. Reverting to polling.
oracle_1 | Fixed Size 2213776 bytes
oracle_1 | Variable Size 402655344 bytes
oracle_1 | Database Buffers 1191182336 bytes
oracle_1 | Redo Buffers 7360512 bytes
oracle_1 | Database mounted.
oracle_1 | Database opened.
oracle_1 | SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
oracle_1 | With the Partitioning, OLAP, Data Mining and Real Application Testing options
oracle_1 |
oracle_1 | /home/oracle/app/oracle/product/11.2.0/dbhome_2/bin/dbstart: Database instance "orcl" warm started.
使用命令查看日志 docker logs [containerID]
[root@linux yunwisdom]# docker logs c640
/home/oracle/app/oracle/product/11.2.0/dbhome_2
Processing Database instance "orcl": log file /home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log
tail: unrecognized file system type 0x794c7630 for `/home/oracle/app/oracle/product/11.2.0/dbhome_2/startup.log'. Reverting to polling.
Fixed Size 2213776 bytes
Variable Size 402655344 bytes
Database Buffers 1191182336 bytes
Redo Buffers 7360512 bytes
Database mounted.
Database opened.
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 "orcl" warm started.
[root@brc-linux-01 yunwisdom]#
Orale服务器连接参数:
hostname: localhost
port: 31521
sid: orcl
service name: orcl
username: system
password: admin
宿主机上,使用如下命令连接sqlplus:
# sqlplus system/admin@//localhost:31521/orcl
##没有配置环境变量
# $ORACLE_HOME/bin/sqlplus system/[email protected]:1521/orcl
连接示例:
[root@linux yunwisdom]# docker exec -it --user root c640 bash
[root@c640bccb9359 /]# sqlplus system/[email protected]/orcl
bash: sqlplus: command not found
[root@c640bccb9359 /]# $ORACLE_HOME/bin/sqlplus system/[email protected]/orcl
SQL*Plus: Release 11.2.0.1.0 Production on Thu Jun 20 07:52:20 2019
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-28002: the password will expire within 7 days
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>
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
Password for SYSTEM:
admin
宿主机上,可以使用下面命令进入oracle数据库,无需安装sqlplus
docker run -e URL=system/password@//10.24.12.132:1521/orcl -ti sflyr/sqlplus
docker run --rm -it loivis/sqlplus system/admin@//127.0.0.1:31521/orcl