上周上完rhce linux课程,张sir讲了 docker黑科技,心里不免有点冲动,能否在docker上使用oracle呢.我们下面来测试一下:
1.安装docker
yum install docker
申明一下,我是使用的centos 7.0.
2.启动docker
systemctl enable docker
systemctl start docker
3.搜索网上哪里有我们要得image
docker search oracle,发现还有现成的oracle12c 的版本
[root@zabsvr ~]# docker search oracle
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/wnameless/oracle-xe-11g Oracle Express 11g R2 on Ubuntu 16.04 LTS 493 [OK]
docker.io docker.io/oraclelinux Oracle Linux is an open-source operating s... 369 [OK]
docker.io docker.io/frolvlad/alpine-oraclejdk8 The smallest Docker image with OracleJDK 8... 250 [OK]
docker.io docker.io/alexeiled/docker-oracle-xe-11g This is a working (hopefully) Oracle XE 11... 209 [OK]
docker.io docker.io/sath89/oracle-12c Oracle Standard Edition 12c Release 1 with... 163 [OK]
docker.io docker.io/sath89/oracle-xe-11g Oracle xe 11g with database files mount su... 111 [OK]
docker.io docker.io/isuper/java-oracle This repository contains all java releases... 56 [OK]
docker.io docker.io/jaspeen/oracle-11g Docker image for Oracle 11g database 45 [OK]
docker.io docker.io/oracle/openjdk Docker images containing OpenJDK Oracle Linux 22 [OK]
docker.io docker.io/ingensi/oracle-jdk Official Oracle JDK installed on centos. 21 [OK]
docker.io docker.io/oracle/glassfish GlassFish Java EE Application Server on Or... 21 [OK]
docker.io docker.io/airdock/oracle-jdk Docker Image for Oracle Java SDK (8 and 7)... 20 [OK]
docker.io docker.io/cogniteev/oracle-java Oracle JDK 6, 7, 8, and 9 based on Ubuntu ... 19 [OK]
docker.io docker.io/n3ziniuka5/ubuntu-oracle-jdk Ubuntu with Oracle JDK. Check tags for ver... 13 [OK]
docker.io docker.io/oracle/nosql Oracle NoSQL on a Docker Image with Oracle... 12 [OK]
docker.io docker.io/bofm/oracle12c Docker image for Oracle Database 11 [OK]
docker.io docker.io/andreptb/oracle-java Debian Jessie based image with Oracle JDK ... 8 [OK]
docker.io docker.io/openweb/oracle-tomcat A fork off of Official tomcat image with O... 6 [OK]
docker.io docker.io/flurdy/oracle-java7 Base image containing Oracle's Java 7 JDK 4 [OK]
docker.io docker.io/davidcaste/debian-oracle-java Oracle Java 8 (and 7) over Debian Jessie 3 [OK]
docker.io docker.io/teradatalabs/centos6-java8-oracle Docker image of CentOS 6 with Oracle JDK 8... 2
docker.io docker.io/publicisworldwide/oracle-core This is the core image based on Oracle Lin... 1 [OK]
docker.io docker.io/sigma/nimbus-lock-oracle 0 [OK]
docker.io docker.io/spansari/nodejs-oracledb nodejs with oracledb installed globally on... 0
docker.io docker.io/trollin/oraclelinux 0
[root@zabsvr ~]#
4.拉一个现成的image下来
使用 docker pull去拉
[root@zabsvr ~]# docker pull docker.io/sath89/oracle-12c
Using default tag: latest
Trying to pull repository docker.io/sath89/oracle-12c ...
latest: Pulling from docker.io/sath89/oracle-12c
863735b9fd15: Pull complete
4fbaa2f403df: Pull complete
44be94a95984: Pull complete
a3ed95caeb02: Pull complete
b8bc6e8767ee: Pull complete
c918da326197: Pull complete
448e1619a038: Pull complete
faadd00cf98e: Pull complete
f99e52a9ce2b: Pull complete
af77b5b09fc9: Pull complete
Digest: sha256:6e9de6f1e5927e6012f1d824f998a20b7cb53f3042231869d5d6826fddb66282
5.查看image情况
[root@zabsvr ~]# docker images docker.io/sath89/oracle-12c
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/sath89/oracle-12c latest b93c23bfc173 6 weeks ago 5.703 GB
6.启动docker
后面就可以用docker了
[root@zabsvr ~]# docker run -i -t docker.io/sath89/oracle-12c /bin/bash
Database is not configured. Please run '/entrypoint.sh' if needed.
root@d4874f62c99e:/# /entrypoint.sh
Database not initialized. Initializing database.
Starting tnslsnr
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/xe.log" for further details.
Configuring Apex console
Database initialized. Please visit http://#containeer:8080/em http://#containeer:8080/apex for extra configuration if needed
Starting web management console
PL/SQL procedure successfully completed.
Starting import from '/docker-entrypoint-initdb.d':
found file /docker-entrypoint-initdb.d//docker-entrypoint-initdb.d/*
[IMPORT] /entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
Import finished
Database ready to use. Enjoy! ;)
^C
Session terminated, terminating shell...ORA-01013: user requested cancel of current operation
...terminated.
这里按ctrl +c
root@d4874f62c99e:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
6: eth0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:2/64 scope link
valid_lft forever preferred_lft forever
地址是 172.17.0.2
和公网的ip是不一样,
如果想进去,是否要用到防火墙的功能,地址伪装.这里先不管它了,如果想知道如何操作,搜一下摆渡吧.
先感受一下数据库吧.
通过ps -ef|grep ora,是不是看到了数据库,
root@d4874f62c99e:/# ps -ef|grep ora
oracle 217 1 0 02:59 ? 00:00:00 /u01/app/oracle/product/12.1.0/xe/bin/tnslsnr
oracle 888 1 0 03:07 ? 00:00:00 ora_pmon_xe
oracle 890 1 0 03:07 ? 00:00:00 ora_psp0_xe
oracle 892 1 0 03:07 ? 00:00:00 ora_vktm_xe
...
oracle 918 1 0 03:07 ? 00:00:00 ora_smon_xe
root 2270 1 0 03:30 ? 00:00:00 grep --color=auto ora
root@d4874f62c99e:/# su - oracle
oracle@d4874f62c99e:~$ sqlplus /nolog
-su: sqlplus: command not found
看来没有设置环境变量
oracle@d4874f62c99e:~$ cd /u01/app/oracle/product/12.1.0/xe/bin
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ ./sqlplus /nolog
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
看来没有设置oracle_home环境变量
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ export ORACLE_HOME=/u01/app/oracle/product/12.1.0/xe/
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ ./sqlplus /nolog
SQL*Plus: Release 12.1.0.2.0 Production on Wed Aug 30 03:32:37 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
SQL> conn / as sysdba
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
没有设置oracle_sid
SQL> exit
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ echo $ORACLE_SID
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ ps -ef|grep ora_smon
oracle 918 1 0 03:07 ? 00:00:00 ora_smon_xe
oracle 2288 2272 0 03:33 ? 00:00:00 grep --color=auto ora_smon
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ export ORACLE_SID=xe
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ ./sqlplus /nolog
SQL*Plus: Release 12.1.0.2.0 Production on Wed Aug 30 03:33:14 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup nomount;
ORA-01012: not logged on
Process ID: 0
Session ID: 0 Serial number: 0
SQL> conn sys/oracle as sysdba
Connected to an idle instance.
SQL> startup
ORA-01012: not logged on
Process ID: 0
Session ID: 0 Serial number: 0
SQL> exit
Disconnected
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ free
total used free shared buffers cached
Mem: 2915852 2636356 279496 501608 0 1407536
-/+ buffers/cache: 1228820 1687032
Swap: 2098172 685360 1412812
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ ipcs -m
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 19595264 oracle 640 2928640 58
0x00000000 19628033 oracle 640 566231040 29
0x00000000 19660802 oracle 640 5459968 29
0xd3c7c9d4 19693571 oracle 640 12288 29
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ free
total used free shared buffers cached
Mem: 2915852 2636356 279496 501608 0 1407536
-/+ buffers/cache: 1228820 1687032
Swap: 2098172 685360 1412812
--先杀掉
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ ps -ef|grep ora_smon
oracle 918 1 0 03:07 ? 00:00:00 ora_smon_xe
oracle 2298 2272 0 03:34 ? 00:00:00 grep --color=auto ora_smon
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ kill -9 918
重新再来
oracle@d4874f62c99e:/u01/app/oracle/product/12.1.0/xe/bin$ ./sqlplus /nolog
SQL*Plus: Release 12.1.0.2.0 Production on Wed Aug 30 03:35:17 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 574619648 bytes
Fixed Size 2926904 bytes
Variable Size 276825800 bytes
Database Buffers 289406976 bytes
Redo Buffers 5459968 bytes
SQL> alter database mount;
Database altered.
SQL> alter database open;
Database altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/xe/system01.dbf
/u01/app/oracle/oradata/xe/sysaux01.dbf
/u01/app/oracle/oradata/xe/undotbs01.dbf
/u01/app/oracle/oradata/xe/users01.dbf
是不是已经看到了,如果你想试一下,心动不如行动.来吧,一起docker.
最后,如果你没有开终端,也可以进入容器:
[root@zabsvr ~]# docker attach d4874f62c99e7e51d5df336fcabbba69fdd93b0f4414b367896bea21e6b55c69
|