Oracle Sean

View Original

Oracle 19c on Docker: Install Oracle via RPM (Part I)

This is the first in a multi-part series on building Docker images for Oracle 19c. In this first part I show how to create a Dockerfile to build images that use the Oracle 19c RPM instead of the “traditional” method where the Oracle Home is unzipped into a target directory. I’ll also demonstrate how to apply a Release Update (RU) to the Oracle Home during the image build to produce a native Oracle 19.7 or 19.8 database.

In the next installment I cover some of the other unique requirements for running Docker images that use the RPM-based installation. In the third part I describe a method to merge multiple images together, creating containers with a low-version Oracle home and database (11g, 12c, 18c) running alongside a preconfigured 19c database home, ready for testing and practicing upgrades to Oracle 19c!

Building images that take advantage of the RPM installer requires a departure from the builds offered in Oracle’s Docker repository. Installing and creating a database is handled differently. Database creation, for example, is addressed in an init script installed as part of the RPM itself, so there’s no need for createDB.sh. The installation response files and template response file aren’t needed, nor is a script to install the database binaries (at least the way I do it).

Let’s dig in, shall we?

For my builds I manage the environment in the Dockerfile a little differently. I prefer a clean environment for containers so I take advantage of Docker’s ARG to set values within the build instead of persisting them in the container’s environment. Using ARG also allows users to pass values when running a container to provide more flexibility and customization in the resulting environment.

See this content in the original post

If you’re not already familiar with multi-stage builds, the FROM / as syntax tells Docker to create an intermediate image called base that will be used in subsequent steps. Creating a base image provides greater freedom to manipulate things later and also helps reduce image size. (An Oracle 19.7 image, built without multiple stages, is around 13GB. Using multiple stages it’s 9.3GB. Oracle 19.8 is 16.3GB and 9.5GB respectively.)

Note that I’m using ARG to set a default value for ORACLE_BASE, ORACLE_HOME and ORACLE_SID, then using these in the ENV setup. When building an image I can pass a custom value for any of these variables using the -build-arg option.

The RPM installation expects some values including ORACLE_VERSION and ORACLE_DOCKER_INSTALL. Customizing the database means I also need to manipulate the configuration and initialization files set in CONFIG_FILE and INIT_FILE.

For those worried that all these extra lines will add layers to the image, don’t fret. They do create steps but not layers and add nothing to the size of the image itself.

Next I’m copying files to the ORACLE_BASE:

See this content in the original post

There’s nothing remarkable happening here, besides a much smaller file count!

The next step does nearly all of the OS configuration. I also add some packages I like:

See this content in the original post

The 19c preinstallation RPM adds the oracle user and groups, after which I create directories and set ownership.

The most interesting thing is probably adding oracle to the sudoers list. With an RPM installation the configuration and initialization is performed by the root user. Giving oracle unlimited sudo privileges is simpler than narrowing things to specific commands and it’s convenient for containers I use in my personal environment.

The preceding stage in this multi-stage build created the base image. The next stage installs Oracle, updates OPatch, and applies a Release Update. As before, it begins with a FROM and sets some ARG values:

See this content in the original post

The RPM and patch files are copied to the image:

See this content in the original post

Next, root installs Oracle from the RPM and sets ownership and permissions for two files:

See this content in the original post

As noted above, the configuration and initialization files are special files needed for this installation method. The configuration file is just that—configuration information used during database creation. The initialization file is used by the Linux init process to start the database and listener.

With the database software installed we can proceed to update OPatch and apply the Release Update:

See this content in the original post

It’s not technically necessary to remove the contents of the installation directory but old habits, as they say!

This concludes the second stage. At this point the build has created two images, base and builder, that will be combined to create the final image. As you might expect, this begins by starting with the base image and setting some environment variables:

See this content in the original post

This is followed by copying the ORACLE_BASE directory from the builder image and setting its ownership to oracle:oinstall, the /etc directory that includes the init and config files added by the RPM installation, and copying a database configuration template into the DBCA template directory under the ORACLE_HOME:

See this content in the original post

This template replaces the response file you may be familiar with from running DBCA “normally.” More on that in the second part of this blog.

The final section should be familiar and remains effectively the same as the builds provided in the Oracle Docker repo:

See this content in the original post

This sets the working directory, exposes container resources (ports and mount point), initiates the health check, and executes the run file.

In the next installment I cover the remaining files and tweaks needed to run an RPM build. All files for this build are available in my GitHub repository.