Skip to content

Instantly share code, notes, and snippets.

@bountin
Last active March 14, 2022 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bountin/43c663f682cb88b1bda9bc569a1a6c5a to your computer and use it in GitHub Desktop.
Save bountin/43c663f682cb88b1bda9bc569a1a6c5a to your computer and use it in GitHub Desktop.
Pre-Building Oracle Docker Image for Testcontainers

Pre-Building Oracle Docker Image for Testcontainers

This description is based on Oracle's guide to prebuild images in combination with Oracle's guide build Oracle Database.

If one builds an Oracle Database image according to the main guide, the container will take minutes to boot due to database initialization. By baking an own image that has the initialized database incorporated, the startup time reduces drastically to roughly 10 to 20 seconds.

Building a Plain Oracle Database Image

This step consists of following the guide at https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/README.md:

  1. Clone Oracle's git repository
  2. Download database installation tarball from Oracle's website (Oracle account and licence acceptance required)
  3. Build image by executing ./buildDockerImage.sh -v 19.3.0 -e

Initialize and Augument own Image

First start the container from Oracle's image. This will take several coffees to complete.

# Start container from oracle's image. This will take several coffees to complete.
docker run -it --name ora-prebuilt  -p 1521:1521 -p 5500:5500  oracle/database:19.3.0-ee

After database has started up, start another shell and continue there.

docker exec -it ora-prebuilt bash

# In the container's shell, set a password for SYS, SYSTEM and PDB_ADMIN to have "root" access via SQL
> ./setPassword.sh george

In SQL (e.g. Datagrip connected to machine, or in sqlplus)

CREATE USER c##george IDENTIFIED BY george;
GRANT ALL PRIVILEGES TO c##george;

Finally stop the running container to snapshot all the done work.

docker stop ora-prebuilt
docker commit -m "Image with prebuilt database" ora-prebuilt oracle/db-prebuilt:19.3.0-ee
docker rm ora-prebuilt

The resulting image oracle/db-prebuilt:19.3.0-ee can then be retagged to individual use.

Misc

Optionally, the resulting image can be squashed but the size gain is just a mere 3.5%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment