Permalink
Browse files

Install software only on image build, create database on first startu…

…p of container (#147)

* Container starting successfully

* Oracle DB EE working

* Including build scrip

buildDockerImage.sh can now be used to drive a Docker build. It also
includes checksum verification of the downloaded files.

* Enable PDB OPEN at startup

* Fixed LISTENER unknown service

* Fixed LISTENER unknown service

* Readme.md

* Renaming of folder for consistency

* Changes in README.md

* Fixed broken link

* Cleanup install binaries right after install

* Removed yum upgrade

* Provide admin account pwd, rename image

It is now possible to provide a password for the admin accounts for the
Database (SYS, SYSTEM, PDBAMIN). In case that no password has been
specified the build script will generate one.

The image has been renamed to oracle/database:<version>-<edition>

* Update README.md with running instructions

* Fixed typo

* Include doc and steps on how to connect

* Include OEM URL

* Update README.md

* Update buildDockerImage.sh

* Update Dockerfile.ee

* Decrease layers in docker file

* Missing colon in option string

* Always print password after build

* Including XE build

* Update README.md with XE instructions

* Fixed #123 - Checking and reinstalling Perl binary

* Compatibility: Remove comments in Checksum files

* Added starter set example

* Fixed run file env variable for CMD

* Replace hard coded run file name with variable

* Remove edit in .bashrc and just use ENV instruction

* Fixed minor typo

* Added sample for custom database

* Adding missing --build-arg flag in comment section

* EE only: create container on startup

* Run DB creation on container startup

* Create DB at container startup

* Startup DB on container restart

* Minor fixes on log output and build files

* Typo

* Create database only at startup

* Updated README.md

* Update README.md

* Change customdb example to reflect new build files

* Fixed broken link

* Fixed broken highlighting
  • Loading branch information...
gvenzl authored and brunoborges committed Aug 23, 2016
1 parent bff0dc2 commit 8d07e454b9c54825dc9084d68b78210c66753240
View
@@ -8,7 +8,7 @@ This project offers sample Dockerfiles for both Oracle Database 12c (12.1.0.2) E
The `buildDockerImage.sh` script is just a utility shell script that performs MD5 checks and is an easy way for beginners to get started. Expert users are welcome to directly call `docker build` with their prefered set of parameters.
### Building Oracle Database Docker Install Images
**IMPORTANT:** You will have to provide the installation binaries of Oracle Database and put them into the `dockerfiles/<version>` folder. You only need to provide the binaries for the edition you are going to install.
**IMPORTANT:** You will have to provide the installation binaries of Oracle Database and put them into the `dockerfiles/<version>` folder. You only need to provide the binaries for the edition you are going to install. You also have to make sure to have internet connectivity for yum.
Before you build the image make sure that you have provided the installation binaries and put them into the right folder. Once you have chosen which edition and version you want to build an image of, go into the **dockerfiles** folder and run the **buildDockerImage.sh** script as root or with `sudo` privileges:
@@ -32,58 +32,79 @@ Before you build the image make sure that you have provided the installation bin
Copyright (c) 2014-2016 Oracle and/or its affiliates. All rights reserved.
**IMPORTANT:** The resulting images will be an newly installed Oracle Database. You may extend the image with your own Dockerfile and create the users and tablespaces that you may need.
**IMPORTANT:** The resulting images will be an image with the Oracle binaries installed. On first startup of the container a new database will be created, the following lines highlight when the database is ready to be used:
### Running Oracle Database in a Docker container
#########################
DATABASE IS READY TO USE!
#########################
#### Running Oracle Database Enterprise and Standard Edition in a Docker container
To run your Oracle Database Docker image just use the **docker run** command as follows:
You may extend the image with your own Dockerfile and create the users and tablespaces that you may need.
docker run -p 1521:1521 -p 5500:5500 oracle/database:12.1.0.2-ee
### Running Oracle Database in a Docker container
There are two ports that are exposed in this image:
* 1521 which is the port to connect to the Oracle Database.
* 5500 which is the port of Oracle Enterprise Manager Express.
#### Running Oracle Database Enterprise and Standard Edition in a Docker container
To run your Oracle Database Docker image use the **docker run** command as follows:
The admin accounts created are:
* sys (SYSDBA for ORCLCDB and ORCLPDB1)
* system (DBA for ORCLCDB and ORCLPDB1)
* pdbadmin (DBA for ORCLPDB1)
docker run --name oracle -p 1521:1521 -p 5500:5500 -e ORACLE_SID=<your SID> -e ORACLE_PDB=<your PDB name> oracle/database:12.1.0.2-ee
Parameters:
--name: The name of the container itself
-p: The port mapping of the host port to the container port. Two ports are exposed: 1521 (Oracle Listener), 5500 (OEM Express)
-e ORACLE_SID: The Oracle Database SID that should be used (default: ORCLCDB)
-e ORACLE_PDB: The Oracle Database PDB name that should be used (default: ORCLPDB1)
Once the container has been started you can connect to it just like to any other database:
Once the container has been started and the database created you can connect to it just like to any other database:
sqlplus system/<your password>@//localhost:1521/ORCLCDB
sqlplus pdbadmin/<your password>@//localhost:1521/ORCLPDB1
sqlplus sys/<your password>@//localhost:1521/<your SID> as sysdba
sqlplus system/<your password>@//localhost:1521/<your SID>
sqlplus pdbadmin/<your password>@//localhost:1521/<Your PDB name>
The Oracle Database inside the container also has Oracle Enterprise Manager Express configured. To access OEM Express, start your browser and follow the URL:
https://localhost:5500/em/
#### Changing the admin accounts passwords
On the first startup of the container a random password will be generated for the database. You can find this password in the output line:
ORACLE AUTO GENERATED PASSWORD FOR SYS, SYSTEM AND PDBAMIN:
The password for those accounts can be changed via the **docker exec** command. **Note**, the container has to be running:
docker exec oracle ./setPassword.sh <your password>
#### Running Oracle Database Express Edition in a Docker container
To run your Oracle Database Express Edition Docker image just use the **docker run** command as follows:
To run your Oracle Database Express Edition Docker image use the **docker run** command as follows:
docker run --shm-size=1g -p 1521:1521 -p 8080:8080 oracle/database:11.2.0.2-xe
docker run --name oraclexe --shm-size=1g -p 1521:1521 -p 8080:8080 oracle/database:11.2.0.2-xe
Parameters:
--name: The name of the container itself
--shm-size: Amount of Linux shared memory
-p: The port mapping of the host port to the container port. Two ports are exposed: 1521 (Oracle Listener), 5500 (OEM Express)
There are two ports that are exposed in this image:
* 1521 which is the port to connect to the Oracle Database.
* 8080 which is the port of Oracle Application Express (APEX).
The admin accounts created are:
* sys (SYSDBA)
* system (DBA)
On the first startup of the container a random password will be generated for the database. You can find this password in the output line:
ORACLE AUTO GENERATED PASSWORD FOR SYS AND SYSTEM:
The password for those accounts can be changed via the **docker exec** command. **Note**, the container has to be running:
docker exec oraclexe /u01/app/oracle/setPassword.sh <your password>
Once the container has been started you can connect to it just like to any other database:
sqlplus sys/<your password>@//localhost:1521/XE as sysdba
sqlplus system/<your password>@//localhost:1521/XE
### Running SQL*Plus in a Docker container
You may use the same Docker image you used to start the database, to run `sqlplus` to connect to it, for example:
docker run --rm -ti oracle/database:12.1.0.2-ee sqlplus pdbadmin/<yourpassword>@//<db-container-ip>:1521/ORCLPDB1
docker run --rm -ti oracle/database:12.1.0.2-ee sqlplus pdbadmin/<yourpassword>@//<db-container-ip>:1521/ORCLPDB1
Another option is to use `docker exec` and run `sqlplus` from within the same container already running the database:
docker exec -ti <container-id> sqlplus pdbadmin@ORCLPDB1
docker exec -ti <container-id> sqlplus pdbadmin@ORCLPDB1
## Support
Currently Oracle Database on Docker is **NOT** supported by Oracle. Use these files at your own discretion.
@@ -35,59 +35,39 @@ MAINTAINER Gerald Venzl <gerald.venzl@oracle.com>
# Environment variables required for this build (do NOT change)
# -------------------------------------------------------------
ENV ORACLE_BASE=/u01/app/oracle \
ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe/ \
ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe \
ORACLE_SID=XE \
INSTALL_FILE_1="oracle-xe-11.2.0-1.0.x86_64.rpm.zip" \
INSTALL_DIR="$HOME/install" \
CONFIG_RSP="xe.rsp" \
RUN_FILE="runOracle.sh"
RUN_FILE="runOracle.sh" \
PWD_FILE="setPassword.sh"
# Use second ENV so that variable get substituted
ENV PATH=$ORACLE_HOME/bin:$PATH
# Oracle password
ARG ORACLE_PWD
# Copy binaries
# -------------
COPY $INSTALL_FILE_1 $CONFIG_RSP $RUN_FILE $INSTALL_DIR/
# Update yum
# ----------
RUN yum -y install unzip libaio bc initscripts net-tools && \
yum clean all
WORKDIR $INSTALL_DIR
COPY $INSTALL_FILE_1 $CONFIG_RSP $RUN_FILE $PWD_FILE $INSTALL_DIR/
# Install Oracle Express Edition
# ------------------------------
RUN unzip $INSTALL_FILE_1 && \
RUN yum -y install unzip libaio bc initscripts net-tools openssl && \
yum clean all && \
cd $INSTALL_DIR && \
unzip $INSTALL_FILE_1 && \
rm $INSTALL_FILE_1 && \
rpm -i Disk1/*.rpm && \
sed -i -e "s|###ORACLE_PWD###|$ORACLE_PWD|g" $INSTALL_DIR/$CONFIG_RSP && \
/etc/init.d/oracle-xe configure responseFile=$CONFIG_RSP && \
chown -R oracle:dba $ORACLE_BASE && \
mv $INSTALL_DIR/$CONFIG_RSP $ORACLE_BASE/ && \
mv $INSTALL_DIR/$RUN_FILE $ORACLE_BASE/ && \
mv $INSTALL_DIR/$PWD_FILE $ORACLE_BASE/ && \
cd $HOME && \
rm -rf $INSTALL_DIR && \
chown -R oracle:dba $ORACLE_BASE && \
chmod u+x $ORACLE_BASE/$RUN_FILE
chmod u+x $ORACLE_BASE/$RUN_FILE && \
chmod u+x $ORACLE_BASE/$PWD_FILE
USER oracle
# Listener
RUN echo "LISTENER = \
(DESCRIPTION_LIST = \
(DESCRIPTION = \
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE)) \
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) \
) \
) \
\
" > $ORACLE_HOME/network/admin/listener.ora
RUN echo "DEDICATED_THROUGH_BROKER_LISTENER=ON" >> $ORACLE_HOME/network/admin/listener.ora && \
echo "DEFAULT_SERVICE_LISTENER = ($ORACLE_SID)" >> $ORACLE_HOME/network/admin/listener.ora && \
echo "DIAG_ADR_ENABLED = off" >> $ORACLE_HOME/network/admin/listener.ora;
EXPOSE 1521 8080
CMD $ORACLE_BASE/$RUN_FILE
@@ -1,9 +1,42 @@
#!/bin/bash
lsnrctl start
sqlplus / as sysdba <<EOF
startup;
EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
EOF
############# Create DB ################
function createDB {
# Auto generate ORACLE PWD
ORACLE_PWD=`openssl rand -hex 8`
echo "ORACLE AUTO GENERATED PASSWORD FOR SYS AND SYSTEM: $ORACLE_PWD";
sed -i -e "s|###ORACLE_PWD###|$ORACLE_PWD|g" $ORACLE_BASE/$CONFIG_RSP && \
/etc/init.d/oracle-xe configure responseFile=$ORACLE_BASE/$CONFIG_RSP
# Listener
echo "LISTENER = \
(DESCRIPTION_LIST = \
(DESCRIPTION = \
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE)) \
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) \
) \
) \
\
" > $ORACLE_HOME/network/admin/listener.ora
echo "DEDICATED_THROUGH_BROKER_LISTENER=ON" >> $ORACLE_HOME/network/admin/listener.ora && \
echo "DIAG_ADR_ENABLED = off" >> $ORACLE_HOME/network/admin/listener.ora;
su -p oracle -c "sqlplus / as sysdba <<EOF
EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
EOF"
}
############# MAIN ################
/etc/init.d/oracle-xe start | grep -qc "Oracle Database 11g Express Edition is not configured"
if [ "$?" == "0" ]; then
createDB;
fi;
echo "#########################"
echo "DATABASE IS READY TO USE!"
echo "#########################"
tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log
@@ -0,0 +1,8 @@
#!/bin/bash
ORACLE_PWD=$1
su -p oracle -c "sqlplus / as sysdba << EOF
ALTER USER SYS IDENTIFIED BY "$ORACLE_PWD";
ALTER USER SYSTEM IDENTIFIED BY "$ORACLE_PWD";
EOF"
@@ -31,18 +31,14 @@ MAINTAINER Gerald Venzl <gerald.venzl@oracle.com>
# -------------------------------------------------------------
ENV ORACLE_BASE=/opt/oracle \
ORACLE_HOME=/opt/oracle/product/12.1.0.2/dbhome_1 \
ORACLE_SID=ORCLCDB \
ORACLE_PDB=ORCLPDB1 \
INSTALL_FILE_1="linuxamd64_12102_database_1of2.zip" \
INSTALL_FILE_2="linuxamd64_12102_database_2of2.zip" \
INSTALL_RSP="db_inst.rsp" \
CONFIG_RSP="dbca.rsp" \
CONFIG_RSP="dbca.rsp.tmpl" \
PWD_FILE="setPassword.sh" \
PERL_INSTALL_FILE="installPerl.sh" \
RUN_FILE="runOracle.sh"
# Oracle password
ARG ORACLE_PWD
# Use second ENV so that variable get substituted
ENV INSTALL_DIR=$ORACLE_BASE/install \
PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch/:/usr/sbin:$PATH \
@@ -51,42 +47,42 @@ ENV INSTALL_DIR=$ORACLE_BASE/install \
# Copy binaries
# -------------
COPY $INSTALL_FILE_1 $INSTALL_FILE_2 $INSTALL_RSP $CONFIG_RSP $PERL_INSTALL_FILE $INSTALL_DIR/
COPY $RUN_FILE $ORACLE_BASE/
COPY $INSTALL_FILE_1 $INSTALL_FILE_2 $INSTALL_RSP $PERL_INSTALL_FILE $INSTALL_DIR/
COPY $RUN_FILE $CONFIG_RSP $PWD_FILE $ORACLE_BASE/
# Setup filesystem and oracle user
# Adjust file permissions, go to /opt/oracle as user 'oracle' to proceed with Oracle installation
# ------------------------------------------------------------
RUN mkdir -p $ORACLE_BASE && \
RUN mkdir -p $ORACLE_BASE/oradata && \
chmod ug+x $ORACLE_BASE/$PWD_FILE && \
groupadd -g 500 dba && \
groupadd -g 501 oinstall && \
useradd -d /home/oracle -g dba -G oinstall,dba -m -s /bin/bash oracle && \
echo oracle:oracle | chpasswd && \
yum -y install oracle-rdbms-server-12cR1-preinstall unzip wget tar && \
yum -y install oracle-rdbms-server-12cR1-preinstall unzip wget tar openssl && \
yum clean all && \
chown -R oracle:dba $ORACLE_BASE
WORKDIR $INSTALL_DIR
# Replace place holders
# ---------------------
RUN sed -i -e "s|###ORACLE_EDITION###|EE|g" $INSTALL_DIR/$INSTALL_RSP && \
sed -i -e "s|###ORACLE_BASE###|$ORACLE_BASE|g" $INSTALL_DIR/$INSTALL_RSP && \
sed -i -e "s|###ORACLE_HOME###|$ORACLE_HOME|g" $INSTALL_DIR/$INSTALL_RSP && \
sed -i -e "s|###ORACLE_SID###|$ORACLE_SID|g" $INSTALL_DIR/$CONFIG_RSP && \
sed -i -e "s|###ORACLE_PDB###|$ORACLE_PDB|g" $INSTALL_DIR/$CONFIG_RSP && \
sed -i -e "s|###ORACLE_PWD###|$ORACLE_PWD|g" $INSTALL_DIR/$CONFIG_RSP
sed -i -e "s|###ORACLE_HOME###|$ORACLE_HOME|g" $INSTALL_DIR/$INSTALL_RSP
# Start installation
# -------------------
USER oracle
RUN unzip $INSTALL_FILE_1 && \
rm $INSTALL_FILE_1 && \
RUN cd $INSTALL_DIR && \
unzip $INSTALL_FILE_1 && \
rm $INSTALL_FILE_1 && \
unzip $INSTALL_FILE_2 && \
rm $INSTALL_FILE_2 && \
rm $INSTALL_FILE_2 && \
$INSTALL_DIR/database/runInstaller -silent -force -waitforcompletion -responsefile $INSTALL_DIR/$INSTALL_RSP -ignoresysprereqs -ignoreprereq && \
rm -rf $INSTALL_DIR/database
rm -rf $INSTALL_DIR/database && \
ln -s $ORACLE_BASE/$PWD_FILE $HOME/ && \
echo "DEDICATED_THROUGH_BROKER_LISTENER=ON" >> $ORACLE_HOME/network/admin/listener.ora && \
echo "DIAG_ADR_ENABLED = off" >> $ORACLE_HOME/network/admin/listener.ora;
# Check whether Perl is working
RUN chmod u+x $INSTALL_DIR/installPerl.sh && \
@@ -95,49 +91,12 @@ RUN chmod u+x $INSTALL_DIR/installPerl.sh && \
USER root
RUN $ORACLE_BASE/oraInventory/orainstRoot.sh && \
$ORACLE_HOME/root.sh
$ORACLE_HOME/root.sh && \
rm -rf $INSTALL_DIR
USER oracle
WORKDIR /home/oracle
RUN mkdir -p $ORACLE_HOME/network/admin && \
echo "NAME.DIRECTORY_PATH= {TNSNAMES, EZCONNECT, HOSTNAME}" > $ORACLE_HOME/network/admin/sqlnet.ora
# Listener.ora
RUN echo "LISTENER = \
(DESCRIPTION_LIST = \
(DESCRIPTION = \
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) \
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) \
) \
) \
\
" > $ORACLE_HOME/network/admin/listener.ora
RUN echo "DEDICATED_THROUGH_BROKER_LISTENER=ON" >> $ORACLE_HOME/network/admin/listener.ora && \
echo "DEFAULT_SERVICE_LISTENER = ($ORACLE_SID)" >> $ORACLE_HOME/network/admin/listener.ora && \
echo "DIAG_ADR_ENABLED = off" >> $ORACLE_HOME/network/admin/listener.ora;
# Start LISTENER and run DBCA
RUN bash -lc "lsnrctl start" && \
dbca -silent -responseFile $INSTALL_DIR/$CONFIG_RSP || \
cat /opt/oracle/cfgtoollogs/dbca/$ORACLE_SID/$ORACLE_SID.log
RUN echo "$ORACLE_SID=localhost:1521/$ORACLE_SID" >> $ORACLE_HOME/network/admin/tnsnames.ora && \
echo "$ORACLE_PDB= \
(DESCRIPTION = \
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521)) \
(CONNECT_DATA = \
(SERVER = DEDICATED) \
(SERVICE_NAME = $ORACLE_PDB) \
) \
)" >> /$ORACLE_HOME/network/admin/tnsnames.ora
RUN echo "startup;" | sqlplus / as sysdba && \
echo "ALTER PLUGGABLE DATABASE $ORACLE_PDB OPEN;" | sqlplus / as sysdba && \
echo "ALTER PLUGGABLE DATABASE $ORACLE_PDB SAVE STATE;" | sqlplus / as sysdba
RUN rm -rf $INSTALL_DIR
EXPOSE 1521 5500
# Define default command to start Oracle Database.
Oops, something went wrong.

0 comments on commit 8d07e45

Please sign in to comment.