Optimized Docker Image for Oracle XE 18c (18.4.0) including Archivelog

Posted by Dirk Nachbar on Wednesday, May 01, 2019
In my current project I am mainly working with Oracle XE 18c (18.4.0) under Docker.

One pain point is size of the Docker Image for Oracle XE 18c, in case you will use the Scripts from https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance for the build of Oracle XE 18c you will have an image size of 8.7 GB, which is not quite handy :-)

So I invested some time and have done some modifications on the Dockerfile.xe from the Oracle GitHub Repository, which is mainly to adopt multi stage and to remove some unnecessary directories from the $ORACLE_HOME, so that I finally come to an image size of 5.41 GB instead of 8.7 GB.

On top I have added some volumes to the Dockerfile.xe for fast recovery area and some tools (which are containing RMAN backup scripts) and a post setup script which will turn on the archivelog mode and flashback.

The full showcase you can find in my GitHub Repository https://github.com/DirkNachbar/Docker/tree/master/OracleXE

Just clone my above mentioned GitHub Repo, download the Oracle XE 18c rpm file from Oracle Technology Network https://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html and place it in the subdirectory 18.4.0.

On top you will need to create 4 directories on your Docker host, which will be the target directories for the following volume mapping:

  • /opt/oracle/oradata
  • /opt/oracle/diag
  • /opt/oracle/fast_recovery_area
  • /opt/oracle/tools

$ groupadd -g 54321 oinstall
$ useradd -d /home/oracle -m -g oinstall [-G docker] -u 54321 oracle
# Depending on your disk layout you will need to create 4 directories
# e.g. you have one mount point called u01, create the following 4 directories below and switch the ownership to the oracle user
$ mkdir -p /u01/diag
$ mkdir -p /u01/oradata
$ mkdir -p /u01/fast_recovery_area
$ mkdir -p /u01/tools
$ chown -R oracle:oinstall /u01/diag
$ chown -R oracle:oinstall /u01/oradata
$ chown -R oracle:oinstall /u01/fast_recovery_area
$ chown -R oracle:oinstall /u01/tools

Now you can execute the build of your Docker Image for Oracle XE 18c

$ ./buildDockerImage.sh -v 18.4.0 -x
. . .
Successfully built ac71812fa9d3
Successfully tagged oracle/database:18.4.0-xe


  Oracle Database Docker Image for 'xe' version 18.4.0 is ready to be extended: 
    
    --> oracle/database:18.4.0-xe

  Build completed in 697 seconds.

$ docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
oracle/database      18.4.0-xe           ac71812fa9d3        About an hour ago   5.41GB

Finally create your Docker Container:

docker run -d --name oraxe18c \
              -p 1521:1521
              -e ORACLE_PWD=[your password] \
              -e ORACLE_CHARACTERSET=[your characterset] \
              -e TZ=[your timezone] \
              -v [host directory for oradata]:/opt/oracle/oradata \
              -v [host directory for diag]:/opt/oracle/diag \
              -v [host directory for fast_recovery_area]:/opt/oracle/fast_recovery_area \
              -v [host directory for tools]:/opt/oracle/tools \
              [--network [your bridged network] \
              oracle/database:18.4.0-xe

# For Example
docker run -d --name oraxe18c \
              -p 1521:1521
              -e ORACLE_PWD=Oracle18c \
              -e ORACLE_CHARACTERSET=AL32UTF8 \
              -e TZ=Europe/Zurich \
              -v /u01/oradata:/opt/oracle/oradata \
              -v /u01/diag:/opt/oracle/diag \
              -v /u01/fast_recovery_area:/opt/oracle/fast_recovery_area \
              -v /u01/tools:/opt/oracle/tools \
              --network mynet \
              oracle/database:18.4.0-xe

Now you have a running Oracle XE 18c Container, your oradata, diag, fast_recovery_area and tools directories are mounted on your Docker Host and you can perform standard backups with RMAN against your Oracle XE 18c.

vi /u01/tools/full_bkp.rman

connect target sys/[your password]
run {
    backup database plus archivelog;
}

# For Example
connect target sys/Oracle18c
run {
    backup database plus archivelog;
}

# Now perform your RMAN Backup
docker exec -it oraxe18c rman @/opt/oracle/tools/full_bkp.rman