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.
This step consists of following the guide at https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/README.md:
- Clone Oracle's git repository
- Download database installation tarball from Oracle's website (Oracle account and licence acceptance required)
- Build image by executing
./buildDockerImage.sh -v 19.3.0 -e
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.
Optionally, the resulting image can be squashed but the size gain is just a mere 3.5%.