Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for mounting a volume in /u0/app/oracle #144

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ FROM ubuntu:18.04
COPY assets /assets
RUN /assets/setup.sh

EXPOSE 22
EXPOSE 1521
EXPOSE 8080

CMD /usr/sbin/startup.sh && tail -f /dev/null
ENTRYPOINT ["/usr/sbin/startup.sh"]
78 changes: 43 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,42 @@ docker-oracle-xe-11g

Oracle Express Edition 11g Release 2 on Ubuntu 18.04 LTS

<del>This **Dockerfile** is a [trusted build](https://registry.hub.docker.com/u/wnameless/oracle-xe-11g/) of [Docker Registry](https://registry.hub.docker.com/).</del>

<del>Since 2019-Feb-13(the Valentine's day eve) this docker image has been removed by DockerHub due to the Docker DMCA Takedown Notice from the Copyright owner which is the Oracle.</del>

<del>Happy Valentine's day!</del>

```diff
+ The new DockerHub [wnameless/oracle-xe-11g-r2] has been released, because
+ the old [wnameless/oracle-xe-11g] is banned by DockerHub and I cannot restore it.
+ Thanks for the help from the staff in Oracle with my DMCA Takedown issue, however this problem
+ is totally ignored by the DockerHub and I barely can't do anything but to open a new repo.
+ Sep 29 2019
## Installation
```

## Installation(Local)
```
git clone https://github.com/wnameless/docker-oracle-xe-11g.git
git clone https://github.com/interob/docker-oracle-xe-11g.git
cd docker-oracle-xe-11g
docker build -t wnameless/oracle-xe-11g .
docker build -t interob/oracle-xe-11g .
```

## Installation(DockerHub)
```
docker pull wnameless/oracle-xe-11g-r2
Volume support:

```bash
$ docker run -d -v /var/yourdata:/u01/app/oracle -p 1521:1521 epiclabs/docker-oracle-xe-11g
```
SSH server has been removed since 18.04, please use "docker exec"

## Quick Start
`/var/yourdata` is an empty directory which will be initialized as soon as the image runs for the first time. If the directory already contains data produced by a previous instance of this image, then the data is preserved. With this, the container can be thrown away every time.

Run with 1521 port opened:
```
docker run -d -p 49161:1521 wnameless/oracle-xe-11g-r2
```

Run this, if you want the database to be connected remotely:
```
docker run -d -p 49161:1521 -e ORACLE_ALLOW_REMOTE=true wnameless/oracle-xe-11g-r2
Run like this, if you want the database to be connected remotely:

```bash
$ docker run -d -p 49161:1521 -e ORACLE_ALLOW_REMOTE=true epiclabs/docker-oracle-xe-11g
```

For performance concern, you may want to disable the disk asynch IO:
```
docker run -d -p 49161:1521 -e ORACLE_DISABLE_ASYNCH_IO=true wnameless/oracle-xe-11g-r2
docker run -d -p 49161:1521 -e ORACLE_DISABLE_ASYNCH_IO=true interob/oracle-xe-11g-r2
```

Enable XDB user with default password: xdb, run this:
```
docker run -d -p 49161:1521 -e ORACLE_ENABLE_XDB=true wnameless/oracle-xe-11g-r2
docker run -d -p 49161:1521 -e ORACLE_ENABLE_XDB=true interob/oracle-xe-11g-r2
```

For APEX user:
```
docker run -d -p 49161:1521 -p 8080:8080 wnameless/oracle-xe-11g-r2
docker run -d -p 49161:1521 -p 8080:8080 interob/oracle-xe-11g-r2
```

```
Expand All @@ -63,9 +47,9 @@ username: ADMIN
password: admin
```

For latest APEX(18.1) user, please pull wnameless/oracle-xe-11g-r2:18.04-apex first:
For latest APEX(18.1) user, please pull interob/oracle-xe-11g-r2:18.04-apex first:
```
docker run -d -p 49161:1521 -p 8080:8080 wnameless/oracle-xe-11g-r2:18.04-apex
docker run -d -p 49161:1521 -p 8080:8080 interob/oracle-xe-11g-r2:18.04-apex
```

```
Expand All @@ -84,17 +68,41 @@ username: system
password: oracle
```

Password for SYS & SYSTEM
Default password for SYS & SYSTEM
```
oracle
```

Support custom DB Initialization and running shell scripts
```
# Dockerfile
FROM wnameless/oracle-xe-11g-r2
FROM interob/oracle-xe-11g

ADD init.sql /docker-entrypoint-initdb.d/
ADD script.sh /docker-entrypoint-initdb.d/
```
Running order is alphabetically.

### Environment variables

* `ORACLE_PASSWORD` : Changes SYS and SYSTEM password to this value
* `RELAX_SECURITY` : If set to 1, a relaxed password policy profile will be put in place with this parameters for `SYS` and `SYSTEM` :

```
CREATE PROFILE NOEXPIRY LIMIT
COMPOSITE_LIMIT UNLIMITED
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL
PASSWORD_LOCK_TIME UNLIMITED
PASSWORD_GRACE_TIME UNLIMITED
FAILED_LOGIN_ATTEMPTS UNLIMITED;
```

Example:

```bash
$ docker run -d -p 1521:1521 -e ORACLE_ALLOW_REMOTE=true -e ORACLE_PASSWORD=testpassword -e RELAX_SECURITY=1 interob/docker-oracle-xe-11g
```

20 changes: 18 additions & 2 deletions assets/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
# avoid dpkg frontend dialog / frontend warnings
export DEBIAN_FRONTEND=noninteractive

cat /assets/oracle-xe_11.2.0-1.0_amd64.deba* > /assets/oracle-xe_11.2.0-1.0_amd64.deb

apt-get update

# Prepare to install Oracle
apt-get update &&
apt-get install -y libaio1 net-tools bc &&
ln -s /usr/bin/awk /bin/awk &&
mkdir /var/lock/subsys &&
mkdir -p /var/lock/subsys &&
mv /assets/chkconfig /sbin/chkconfig &&
chmod 755 /sbin/chkconfig &&

Expand Down Expand Up @@ -48,4 +51,17 @@ cat /assets/apex-default-pwd.sql | sqlplus -s SYSTEM/oracle
# Remove installation files
rm -r /assets/

mv /u01/app/oracle/product /u01/app/oracle-product
pushd /u01/app/oracle-product/11.2.0/xe/
tar zcvf /u01/app/default-dbs.tar.gz dbs
rm -rf dbs/
popd

tar zcvf /u01/app/default-admin.tar.gz /u01/app/oracle/admin && rm -rf /u01/app/oracle/admin
tar zcvf /u01/app/default-oradata.tar.gz /u01/app/oracle/oradata && rm -rf /u01/app/oracle/oradata
tar zcvf /u01/app/default-fast_recovery_area.tar.gz /u01/app/oracle/fast_recovery_area && rm -rf /u01/app/oracle/fast_recovery_area

# Install startup script for container


exit $?
115 changes: 111 additions & 4 deletions assets/startup.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#!/bin/bash
LISTENER_ORA=/u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
TNSNAMES_ORA=/u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora

echo ""
echo "Oracle XE 11g CI/Development image"
echo "By Epic Labs, 2017 - http://www.epiclabs.io"
echo ""
echo "https://github.com/epiclabs-io/docker-oracle-xe-11g"
echo "forked from wnameless/docker-oracle-xe-11g"
echo ""
echo ""



LISTENER_ORA=/u01/app/oracle-product/11.2.0/xe/network/admin/listener.ora
TNSNAMES_ORA=/u01/app/oracle-product/11.2.0/xe/network/admin/tnsnames.ora

cp "${LISTENER_ORA}.tmpl" "$LISTENER_ORA" &&
sed -i "s/%hostname%/$HOSTNAME/g" "${LISTENER_ORA}" &&
Expand All @@ -9,31 +21,116 @@ cp "${TNSNAMES_ORA}.tmpl" "$TNSNAMES_ORA" &&
sed -i "s/%hostname%/$HOSTNAME/g" "${TNSNAMES_ORA}" &&
sed -i "s/%port%/1521/g" "${TNSNAMES_ORA}" &&


rm -rf /u01/app/oracle/product

ln -s /u01/app/oracle-product /u01/app/oracle/product #Mount database installation to the Expanded VOLUME of container

if [ ! -d /u01/app/oracle/dbs ] ; then
echo "using default configuration"
tar xf /u01/app/default-dbs.tar.gz -C /u01/app/oracle/
fi

if [ ! -d /u01/app/oracle/oradata ] ; then
echo "using default data directory"
tar xf /u01/app/default-oradata.tar.gz
fi

if [ ! -d /u01/app/oracle/admin ] ; then
echo "using default admin directory"
tar xf /u01/app/default-admin.tar.gz
fi

if [ ! -d /u01/app/oracle/fast_recovery_area ] ; then
echo "using default fast_recovery_area directory"
tar xf /u01/app/default-fast_recovery_area.tar.gz
fi

ln -s /u01/app/oracle/dbs /u01/app/oracle-product/11.2.0/xe/dbs #Link db configuration to the installation path form extended volume with DB data

chown -R oracle:dba /u01/app/oracle

service oracle-xe start

export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=XE
export ORACLE_DATA=/u01/app/oracle/oradata/$ORACLE_SID


if [ ! -e "/u01/app/oracle/initialized.id" ] ; then

echo "Performing initial database setup ..."

if [ ! -z "$RELAX_SECURITY" ] ; then
echo "WARNING: Relaxing profile security with no password reuse limits, etc. Use with caution ..."
echo "CREATE PROFILE NOEXPIRY LIMIT
COMPOSITE_LIMIT UNLIMITED
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL
PASSWORD_LOCK_TIME UNLIMITED
PASSWORD_GRACE_TIME UNLIMITED
FAILED_LOGIN_ATTEMPTS UNLIMITED;" | sqlplus -s SYSTEM/oracle

echo "ALTER USER SYSTEM PROFILE NOEXPIRY;" | sqlplus -s SYSTEM/oracle
echo "ALTER USER SYS PROFILE NOEXPIRY;" | sqlplus -s SYSTEM/oracle
echo "Security relaxed."

fi

echo "Setting db_create_file_dest param..."
if ! echo "ALTER SYSTEM SET db_create_file_dest = '$ORACLE_DATA';" | sqlplus -s SYSTEM/oracle; then
echo "error setting db_create_file_dest param"
exit 1
fi

if [ -z "$ORACLE_PASSWORD" ] ; then
echo "Warning: using default password!!. Set ORACLE_PASSWORD environment variable to change it"
export ORACLE_PASSWORD="oracle";
else

echo "Setting SYS password... "
if ! echo "ALTER USER SYS IDENTIFIED BY \"$ORACLE_PASSWORD\";" | sqlplus -s SYSTEM/oracle ; then
echo "Error setting SYS password."
exit 1;
fi

echo "Setting SYSTEM password... "

if ! echo "ALTER USER SYSTEM IDENTIFIED BY \"$ORACLE_PASSWORD\";" | sqlplus -s SYSTEM/oracle ; then
echo "Error setting SYSTEM password."
exit 1;
fi
fi

touch "/u01/app/oracle/initialized.id"
fi



if [ "$ORACLE_ENABLE_XDB" = true ]; then
echo "ALTER USER XDB ACCOUNT UNLOCK;" | sqlplus -s SYSTEM/oracle
echo "ALTER USER XDB IDENTIFIED BY xdb;" | sqlplus -s SYSTEM/oracle
fi

if [ "$ORACLE_ALLOW_REMOTE" = true ]; then
echo "alter system disable restricted session;" | sqlplus -s SYSTEM/oracle
echo "alter system disable restricted session;" | sqlplus -s "SYSTEM/$ORACLE_PASSWORD"
fi

if [ "$ORACLE_DISABLE_ASYNCH_IO" = true ]; then
echo "ALTER SYSTEM SET disk_asynch_io = FALSE SCOPE = SPFILE;" | sqlplus -s SYSTEM/oracle
service oracle-xe restart
fi

echo "Running startup scripts ..."

for f in /docker-entrypoint-initdb.d/*; do
[ -f "$f" ] || continue
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*.sql) echo "$0: running $f"; echo "exit" | /u01/app/oracle/product/11.2.0/xe/bin/sqlplus "SYS/oracle" AS SYSDBA @"$f"; echo ;;
*.sql) echo "$0: running $f"; echo "exit" | /u01/app/oracle/product/11.2.0/xe/bin/sqlplus "SYS/$ORACLE_PASSWORD" AS SYSDBA @"$f"; echo ;;
*) echo "$0: ignoring $f" ;;
esac
echo
Expand All @@ -42,3 +139,13 @@ done
echo "#########################"
echo "DATABASE IS READY TO USE!"
echo "#########################"


echo -e "\n\n Bring it on!! \n\n"

tail -fn 0 /u01/app/oracle/diag/rdbms/xe/XE/trace/alert_XE.log

echo -e '\n\nShutting down...\n\n'
service oracle-xe stop

echo -e "\nbye\n"