Skip to content

Instantly share code, notes, and snippets.

@ttekun
Last active November 26, 2016 18:56
Show Gist options
  • Save ttekun/c42c0703cb3512994ee1b6335c8afa2d to your computer and use it in GitHub Desktop.
Save ttekun/c42c0703cb3512994ee1b6335c8afa2d to your computer and use it in GitHub Desktop.
Create Oracle XE(CentOS) docker image within 10 minutes

Create Oracle XE(CentOS) docker image within 10 minutes

  1. vagrant up (coreos-vagrant)
$ git clone https://github.com/coreos/coreos-vagrant.git
$ cd coreos-vagrant
$ vagrant up
$ vagrant ssh

If you are currently in Linux environment, pass this step.

  1. Please set base centos image
$ base_docker_image=ttekun/centos:6-oraclexerpm

Other base centos image ttekun/centos:5-oraclexerpm ttekun/centos:7-oraclexerpm

  1. Please enter your email address
$ email_address=tacksangkim@gmail.com
  1. Remove all containers
$ docker rm $(docker ps -aq)
  1. build
$ git clone https://gist.github.com/c42c0703cb3512994ee1b6335c8afa2d.git
$ cd c42c0703cb3512994ee1b6335c8afa2d
$ chmod 755 *.sh
$ ./build.sh MemTotal ${base_docker_image} ${email_address}
  1. oraclexe11g install
[root@oraclexe11g tmp]# ./oraclexe11g-install.sh
  1. oracle-xe configure
[root@oraclexe11g tmp]# /etc/init.d/oracle-xe configure

🚨 1️⃣ Please input oracle

initial configuration:
Confirm the password:

🚨 2️⃣ Please input n

Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:n
  1. oracle-xe stop
[root@oraclexe11g tmp]# /etc/init.d/oracle-xe stop
  1. exit
[root@oraclexe11g tmp]# exit
  1. docker commit -> docker build

  2. docker run

$ docker run -itd --name db -h oraclexe11g -p 8089:8080 -p 1521:1521 [DOCKER IMAGE]
port: 1521
sid: XE
username: system
password: oracle
#!/bin/bash
# customized from https://github.com/madhead/docker-oracle-xe/blob/master/build-wrapper.sh
#
# Copyright (c) 2015 Uli Fuchs <ufuchs@gmx.com>
# Released under the terms of the MIT License
#
# Gets the value of a given key in '/proc/meminfo'
# @param1 string - key name, e.g. 'MemTotal'
# @param2 string - base docker image, e.g. 'centos:6'
# @param3 string - your email address, e.g. 'tacksangkim@gmail.com'
# @return integer - value in MB
function getMemInfo() {
local mem=$(cat /proc/meminfo | grep "$1" | awk '{print $2}')
echo $(expr $mem / 1024)
}
# Checks if the system provides 2048MB _free_ swap space.
# This will be tested by Oracle before the rpm installer runs.
# @return integer - 1 if less than 2048 swap space available otherwise 0
function needExtraSwapSpace() {
local swapFree=$(getMemInfo "SwapFree")
[ $swapFree -lt 2048 ] && echo 1 || echo 0
}
NEED_EXTRASWAP=$(needExtraSwapSpace)
SWAPFILE=/root/swapfile
[ $NEED_EXTRASWAP -eq 1 ] && {
echo
echo ===================================================================================
echo "There are only $(getMemInfo "SwapFree")MB free swap space available but it needs 2048MB."
echo "Creating extra swap space of 2048MB. This takes some seconds..."
sudo dd if=/dev/zero of=$SWAPFILE count=1024 bs=2097152 &> /dev/null
sudo mkswap -c $SWAPFILE
sudo swapon $SWAPFILE
echo
swapon -s
echo ===================================================================================
echo
}
#wget https://gist.gihub.com/ttekun/c42c0703cb3512994ee1b6335c8afa2d/raw/oraclexe11g-install.sh
#wget https://gist.gihub.com/ttekun/c42c0703cb3512994ee1b6335c8afa2d/raw/oracle.sh
#wget https://gist.gihub.com/ttekun/c42c0703cb3512994ee1b6335c8afa2d/raw/oracle-xe-startup.sh
chmod 755 *
docker run --privileged -it -h oraclexe11g -v `pwd`:/tmp -w /tmp "$2" bash
[ $NEED_EXTRASWAP -eq 1 ] && {
echo
echo ===================================================================================
echo "Removing the extra swap space"
sudo swapoff $SWAPFILE
sudo rm -f $SWAPFILE
echo
swapon -s
echo
echo ===================================================================================
sudo rm -fr Disk1
container_id=`docker ps -a | grep $2 | awk '{ if( NR==1 ){ print $1 } }'`
echo "Please execute the following command"
echo
echo "docker commit ${container_id} $2-oraclexe11g"
echo "FROM $2-oraclexe11g" >> Dockerfile
echo "MAINTAINER $3" >> Dockerfile
echo "" >> Dockerfile
echo "CMD /etc/init.d/oracle-xe start && /bin/bash" >> Dockerfile
echo "docker build -t $2-oraclexe11g ."
echo ===================================================================================
echo
}
##############################################################################
# Copyright (c) 1991, 2011, Oracle and/or its affiliates. All rights reserved.
##############################################################################
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_name=XE
###########################################
# File Configuration
###########################################
control_files=("/u01/app/oracle/oradata/XE/control.dbf")
DB_RECOVERY_FILE_DEST=/u01/app/oracle/fast_recovery_area
DB_RECOVERY_FILE_DEST_SIZE=10G
###########################################
# Job Queues
###########################################
job_queue_processes=4
###########################################
# Miscellaneous
###########################################
compatible=11.2.0.0.0
diagnostic_dest=/u01/app/oracle
# memory_target=%memory_target%
###########################################
# Sessions
###########################################
sessions=20
###########################################
# Security and Auditing
###########################################
audit_file_dest=/u01/app/oracle/admin/XE/adump
remote_login_passwordfile=EXCLUSIVE
###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=XEXDB)"
shared_servers=4
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS1
##############################################################################
# Copyright (c) 1991, 2011, Oracle and/or its affiliates. All rights reserved.
##############################################################################
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_name=XE
###########################################
# File Configuration
###########################################
control_files=("/u01/app/oracle/oradata/XE/control.dbf")
DB_RECOVERY_FILE_DEST_SIZE=10G
DB_RECOVERY_FILE_DEST=/u01/app/oracle/fast_recovery_area
###########################################
# Job Queues
###########################################
###########################################
# Miscellaneous
###########################################
compatible=11.2.0.0.0
diagnostic_dest=/u01/app/oracle
# memory_target=%memory_target%
###########################################
# Sessions
###########################################
sessions=20
###########################################
# Security and Auditing
###########################################
audit_file_dest=/u01/app/oracle/admin/XE/adump
remote_login_passwordfile=EXCLUSIVE
###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=XEXDB)"
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS1
_no_recovery_through_resetlogs=true
#!/bin/bash
LISTENERS_ORA=/u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
cp "${LISTENERS_ORA}.tmpl" "$LISTENERS_ORA" &&
sed -i "s/%hostname%/$HOSTNAME/g" "${LISTENERS_ORA}" &&
sed -i "s/%port%/1521/g" "${LISTENERS_ORA}" &&
service oracle-xe start
#!/bin/sh
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=XE
#!/bin/bash
# Pre-requirements
mkdir -p /run/lock/subsys
yum install -y libaio bc initscripts net-tools wget zip unzip && yum clean all
unzip ~/oracle-xe-11.2.0-1.0.x86_64.rpm.zip && rm -fr ~/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
rpm -ivh /tmp/Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm
#wget -q https://gist.gihub.com/ttekun/c42c0703cb3512994ee1b6335c8afa2d/raw/init.ora -O /u01/app/oracle/product/11.2.0/xe/config/scripts/init.ora && \
# wget -q https://gist.gihub.com/ttekun/c42c0703cb3512994ee1b6335c8afa2d/raw/initXETemp.ora -O /u01/app/oracle/product/11.2.0/xe/config/scripts/initXETemp.ora
yes | cp /tmp/init.ora /u01/app/oracle/product/11.2.0/xe/config/scripts/init.ora
yes | cp /tmp/initXETemp.ora /u01/app/oracle/product/11.2.0/xe/config/scripts/initXETemp.ora
chown oracle:dba /u01/app/oracle/product/11.2.0/xe/config/scripts/*.ora
chmod 755 /u01/app/oracle/product/11.2.0/xe/config/scripts/*.ora
mv oracle.sh /etc/profile.d/.
mv oracle-xe-startup.sh /usr/sbin/.
echo
echo ===================================================================================
echo "Please execute the following command"
echo
echo "/etc/init.d/oracle-xe configure"
echo "/etc/init.d/oracle-xe stop"
echo ===================================================================================
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment