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

Introduce new images #10

Merged
merged 48 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f7e115c
Build full image
gvenzl Jan 24, 2021
50246c2
Introduce password reset (ER #2)
gvenzl Jan 25, 2021
ab6e8c2
Introduce healthcheck (ER #1)
gvenzl Jan 25, 2021
7492dec
Shutdown listener before database
gvenzl Jan 25, 2021
5c3726c
Fix healthcheck typo
gvenzl Jan 25, 2021
5f03d32
Update description header
gvenzl Jan 25, 2021
bc7f413
Use build args for Dockerfile
gvenzl Jan 26, 2021
c7cf9b4
Update Description
gvenzl Jan 26, 2021
75da139
Add password profile, restructure db file sizes
gvenzl Jan 28, 2021
8612ea4
Transition to OL8 slim
gvenzl Jan 28, 2021
ca4e81b
Introducing a image build script
gvenzl Jan 30, 2021
ed85a1b
Full completed, normal and slim TBD
gvenzl Jan 31, 2021
411a4d4
Update ReadMe
gvenzl Jan 31, 2021
fc1138f
Add test scripts
gvenzl Jan 31, 2021
2829308
Add .gitignore
gvenzl Jan 31, 2021
66bc38c
Merge branch 'main' into development
gvenzl Jan 31, 2021
76a9406
Print DATABASE IS READY TO USE only after healthcheck succeeded (ER #6)
gvenzl Jan 31, 2021
1ee4ac1
18c Dockerfile
gvenzl Feb 1, 2021
dcfb11d
Full install DB configured
gvenzl Feb 7, 2021
dc7b9d5
Add checksum verification for 18c
gvenzl Feb 7, 2021
554dc76
Add parameter to ignore checksum
gvenzl Feb 8, 2021
11cc396
18c full install
gvenzl Feb 13, 2021
31d697c
Remove recovery_dest
gvenzl Feb 13, 2021
c4f640b
Merge branch 'development' into 18c-full
gvenzl Feb 13, 2021
70a9c51
Remove install log files
gvenzl Feb 13, 2021
639466d
Remove installation phase only dependencies
gvenzl Feb 14, 2021
3f763bc
Update ORACLE_HOME in .bash_profile
gvenzl Feb 14, 2021
199e723
Resize redo logs
gvenzl Feb 19, 2021
0bec3bb
Include network files
gvenzl Feb 20, 2021
827a8e8
ER #8: Set password only at initialization
gvenzl Feb 20, 2021
62e3b94
Use entrypoint rather cmd
gvenzl Feb 20, 2021
aaf9364
Add build duration to build script
gvenzl Feb 21, 2021
6391ef4
Compress data files in image
gvenzl Feb 21, 2021
93b19c1
Implemented ORACLE_RANDOM_PASSWORD ER #9
gvenzl Feb 21, 2021
e6bdd36
Update .gitignore
gvenzl Feb 28, 2021
0c25e31
rename entrypoint script
gvenzl Mar 1, 2021
3d91eeb
Implement ER #4 - _FILE variable support
gvenzl Mar 1, 2021
dd6914b
Make zip and gzip a runtime requirement
gvenzl Mar 6, 2021
c9a5616
Make sure PWD is treated as a string
gvenzl Mar 6, 2021
449aec1
Add support for custom scripts ER #3
gvenzl Mar 7, 2021
9aa33e8
Update ReadMe (WIP)
gvenzl Mar 7, 2021
7d8513e
reformat indent
gvenzl Mar 7, 2021
3bd3a0e
Reorg
gvenzl Mar 14, 2021
0cc71f6
Build and container tests for 11g and 18c
gvenzl Mar 21, 2021
7ec10e2
Update UNDO size
gvenzl Mar 27, 2021
5e6a366
Update ReadMe
gvenzl Mar 27, 2021
a0ead78
Introduce tags
gvenzl Mar 27, 2021
5d10073
Add slim builds for 11g
gvenzl Mar 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.rpm
*.zip
rpm/
assets/
22 changes: 20 additions & 2 deletions Dockerfile.11202
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
# Author: gvenzl
# Name: Dockerfile.11202
# Description: Dockerfile to build Oracle DB XE 11.2.0.2.
# The Dockerfile supports building different flavors of images.
# These flavors can be controlled via the build argument "BUILD_MODE" which
# supports three modes, as follows:
#
# FULL: No database functionality is removed, just log and trace files from the
# database installation itself.
# Additional required packages, such as 'gcc' and 'make' are installed
# (needed for native PL/SQL execution, etc.)
# Database configuration is as per default installation, except for the
# location of the fast_recovery_area and redo logs.
#
# NORMAL: Following functionalities have been removed:
# * gcc & make (needed for native PL/SQL execution, etc.)
# * APEX
#
# SLIM: Following functionalities have been removed:
# * Everything that has been removed in the NORMAL image, plus:
# * Oracle Text
#
# Copyright 2021 Gerald Venzl
#
Expand All @@ -27,7 +45,7 @@ ENV ORACLE_BASE=/u01/app/oracle \
ORACLE_SID=XE \
PATH=${PATH}:/u01/app/oracle/product/11.2.0/xe/bin:/u01/app/oracle

COPY oracle-xe-11.2.0-1.0.x86_64.rpm xe.11202.rsp install.11202.sh runDB.sh resetPassword healthcheck.sh /install/
COPY oracle-xe-11.2.0-1.0.x86_64.rpm xe.11202.rsp install.11202.sh container-entrypoint.sh resetPassword healthcheck.sh /install/

RUN /install/install.11202.sh "${BUILD_MODE}"

Expand All @@ -36,4 +54,4 @@ WORKDIR ${ORACLE_BASE}

HEALTHCHECK CMD "${ORACLE_BASE}"/healthcheck.sh >/dev/null || exit 1

CMD exec ${ORACLE_BASE}/runDB.sh
ENTRYPOINT ["container-entrypoint.sh"]
39 changes: 39 additions & 0 deletions Dockerfile.1840
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Since: January, 2021
# Author: gvenzl
# Name: Dockerfile.1840
# Description: Dockerfile to build Oracle DB XE 18.4.0
#
# Copyright 2021 Gerald Venzl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM oraclelinux:8-slim

ARG BUILD_MODE

ENV ORACLE_BASE=/opt/oracle \
ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE \
ORACLE_SID=XE \
PATH=${PATH}:/opt/oracle/product/18c/dbhomeXE/bin:/opt/oracle

COPY oracle-database-xe-18c-1.0-1.x86_64.rpm install.1840.sh container-entrypoint.sh resetPassword healthcheck.sh /install/

RUN /install/install.1840.sh "${BUILD_MODE}"

USER oracle
WORKDIR ${ORACLE_BASE}

HEALTHCHECK CMD "${ORACLE_BASE}"/healthcheck.sh >/dev/null || exit 1

ENTRYPOINT ["container-entrypoint.sh"]
262 changes: 228 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,261 @@
# oci-oracle-xe
Oracle Database Express Edition Container / Docker images.

The images are compatible with `podman` and `docker`.
You can use `podman` or `docker` interchangeably.
**The images are compatible with `podman` and `docker`. You can use `podman` or `docker` interchangeably.**

## Image flavors
# Supported tags and respective `Dockerfile` links

| Flavor | Description | Use cases |
| ------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| 11.2.0.2-slim | An image focussed on smallest possible image size sacrificing on additional functionality. | Best for where small images sizes are important but advanced functionality of Oracle Database is not needed. |
| 11.2.0.2 | A well-balanced image between image size and functionality. Recommended for most use cases. | Recommended for most use cases. |
| 11.2.0.2-full | An image containing all functionality as provided by the Oracle Database installation. | Best for extensions or customizations. |
* [`18.4.0`, `18`, `latest`](https://github.com/gvenzl/oci-oracle-xe/blob/main/Dockerfile.1840)
* [`18.4.0-full`, `18-full`, `full`](https://github.com/gvenzl/oci-oracle-xe/blob/main/Dockerfile.1840)
* [`11.2.0.2`, `11`](https://github.com/gvenzl/oci-oracle-xe/blob/main/Dockerfile.11202)
* [`11.2.0.2-slim`, `11-slim`](https://github.com/gvenzl/oci-oracle-xe/blob/main/Dockerfile.11202)
* [`11.2.0.2-full`, `11-full`](https://github.com/gvenzl/oci-oracle-xe/blob/main/Dockerfile.11202)

For more information, see [Image flavor details](#image-flavor-details).
# Quick Start

## Quick start
Run a new database container:

### Reset passwords
```shell
docker run -d -p 1521:1521 -e ORACLE_PASSWORD=<your password> gvenzl/oracle-xe
```
docker exec <image name|id> resetPassword <your password>

Run a new persistent database container:

```shell
docker run -d -p 1521:1521 -e ORACLE_PASSWORD=<your password> -v oracle-volume:/opt/oracle/oradata gvenzl/oracle-xe
```

Run a new database container with OEM Express expose:

```shell
docker run -d -p 1521:1521 -e ORACLE_PASSWORD=<your password> -p 5500:5500 gvenzl/oracle-xe
```

Reset database `SYS` and `SYSTEM` passwords:

```shell
docker exec <container name|id> resetPassword <your password>
```

# How to use this image

## Subtle differences between versions

The 11gR2 (11.2.0.2) Oracle Database version stores the database data files under `/u01/app/oracle/oradata/XE`.
**A volume for 11gR2 has to be pointed at `/u01/app/oradata`!**

## Environment variables

### `ORACLE_PASSWORD`
This variable is mandatory for the first container startup and specifies the password for the Oracle Database `SYS` and `SYSTEM` users.

### `ORACLE_RANDOM_PASSWORD`
This is an optional variable. Set this variable to a non-empty value, like `yes`, to generate a random initial password for the `SYS` and `SYSTEM` users. The generated password will be printed to stdout (`ORACLE PASSWORD FOR SYS AND SYSTEM: ...`).

## Container secrets

As an alternative to passing sensitive information via environment variables, `_FILE` may be appended to some of the previously listed environment variables, causing the initialization script to load the values for those variables from files present in the container. In particular, this can be used to load passwords from Container/Docker secrets stored in `/run/secrets/<secret_name>` files. For example:

```shell
docker run --name some-oracle -e ORACLE_PASSWORD_FILE=/run/secrets/oracle-passwd -d gvenzl/oracle-xe
```

## Image flavor details
Currently, this is only supported for `ORACLE_PASSWORD`.

## Initialization scripts
If you would like to perform additional initialization of the database running in a container, you can add one or more `*.sql`, `*.sql.gz`, `*.sql.zip` or `*.sh` files under `/container-entrypoint-initdb.d` (creating the directory if necessary). After the database setup is completed, these files will be executed automatically in alphabetical order.

The `*.sql`, `*.sql.gz` and `*.sql.zip` files will be executed in Sql*Plus as the `SYS` user connected to the Oracle instance (`XE`). Compressed files will be uncompressed on the fly, allowing for e.g. bigger data loading scripts to save space.

Executable `*.sh` files will be run in a new shell process while non-executable `*.sh` files (files that do not have the Linux e`x`ecutable permission set) will be sourced into the current shell process. The main difference between these methods is that sourced shell scripts can influence the environment of the current process and should generally be avoided. However, sourcing scripts allows for execution of these scripts even if the executable flag is not set for the files containing them. This basically avoids the "why did my script not get executed" confusion.

***Note:*** scripts in `/container-entrypoint-initdb.d` are only run the first time the database is initialized; any pre-existing database will be left untouched on container startup.

***Note:*** you can also put files under the `/docker-entrypoint-initdb.d` directory. This is kept for backwards compatibility with other widely used container images but should generally be avoided. Do not put files under `/container-entrypoint-initdb.d` **and** `/docker-entrypoint-initdb.d` as this would cause the same files to be executed twice!

***Warning:*** if a command within the sourced `/container-entrypoint-initdb.d` scripts fails, it will cause the main entrypoint script to exit and stop the container. It also may leave the database in an incomplete initialized state. Make sure that shell scripts handle error situations gracefully and ideally do not source them!

***Warning:*** do not exit executable `/container-entrypoint-initdb.d` scripts with a non-zero value (using e.g. `exit 1;`) unless it is desired for a container to be stopped! A non-zero return value will tell the main entrypoint script that something has gone wrong and that the container should be stopped.

### Example

The following example installs the [countries, cities and currencies sample data set](https://github.com/gvenzl/sample-data/tree/master/countries-cities-currencies) under a new user `TEST` into the database:

```shell
[gvenzl@localhost init_scripts]$ pwd
/home/gvenzl/init_scripts

[gvenzl@localhost init_scripts]$ ls -al
total 12
drwxrwxr-x 2 gvenzl gvenzl 61 Mar 7 11:51 .
drwx------. 19 gvenzl gvenzl 4096 Mar 7 11:51 ..
-rw-rw-r-- 1 gvenzl gvenzl 134 Mar 7 11:50 1_create_user.sql
-rwxrwxr-x 1 gvenzl gvenzl 164 Mar 7 11:51 2_create_data_model.sh

[gvenzl@localhost init_scripts]$ cat 1_create_user.sql
ALTER SESSION SET CONTAINER=XEPDB1;

CREATE USER TEST IDENTIFIED BY test QUOTA UNLIMITED ON USERS;

GRANT CONNECT, RESOURCE TO TEST;

[gvenzl@localhost init_scripts]$ cat 2_create_data_model.sh
curl -LJO https://raw.githubusercontent.com/gvenzl/sample-data/master/countries-cities-currencies/install.sql

sqlplus -s test/test@//localhost/XEPDB1 @install.sql

rm install.sql

```

As the execution happens in alphabetical order, numbering the files will guarantee the execution order. A new container started up with `/home/gvenzl/init_scripts` pointing to `/container-entrypoint-initdb.d` will then execute the files above:

```shell
podman run --name test \
> -p 1521:1521 \
> -e ORACLE_RANDOM_PASSWORD="y" \
> -v /home/gvenzl/init_scripts:/container-entrypoint-initdb.d \
> gvenzl/oracle-xe:18.4.0-full
CONTAINER: starting up...
CONTAINER: first database startup, initializing...
...
CONTAINER: Executing user defined scripts...
CONTAINER: running /container-entrypoint-initdb.d/1_create_user.sql ...

There are three flavors of the image:
* FULL (`-full` tag appended)
* NORMAL (no tag appended)
* SLIM (`-slim` tag appended)
Session altered.

### Full image flavor

User created.


Grant succeeded.

CONTAINER: DONE: running /container-entrypoint-initdb.d/1_create_user.sql

CONTAINER: running /container-entrypoint-initdb.d/2_create_data_model.sh ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 115k 100 115k 0 0 460k 0 --:--:-- --:--:-- --:--:-- 460k

Table created.
...
Table provided actual
-------------------- ---------- ----------
regions 7 7
countries 196 196
cities 204 204
currencies 146 146
currencies_countries 203 203


Thank you!
--------------------------------------------------------------------------------
The installation is finished, please check the verification output above!
If the 'provided' and 'actual' row counts match, the installation was successful
.

If the row counts do not match, please check the above output for error messages
.


CONTAINER: DONE: running /container-entrypoint-initdb.d/2_create_data_model.sh

CONTAINER: DONE: Executing user defined scripts.


#########################
DATABASE IS READY TO USE!
#########################
...
```

As a result, one can then connect to the new schema directly:

```shell
[gvenzl@localhost init_scripts]$ sql test/test@//localhost/XEPDB1

SQLcl: Release 20.3 Production on Sun Mar 07 12:05:06 2021

Copyright (c) 1982, 2021, Oracle. All rights reserved.

Connected to:
Oracle Database 18c Express Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0


SQL> select * from countries where name = 'Austria';

COUNTRY_ID COUNTRY_CODE NAME OFFICIAL_NAME POPULATION AREA_SQ_KM LATITUDE LONGITUDE TIMEZONE REGION_ID
---------- ------------ ------- ------------------- ---------- ---------- -------- --------- ------------- ---------
AUT AT Austria Republic of Austria 8793000 83871 47.33333 13.33333 Europe/Vienna EU

SQL>
```

## Startup scripts

If you would like to perform additional action after the database running in a container has been started, you can add one or more `*.sql`, `*.sql.gz`, `*.sql.zip` or `*.sh` files under `/container-entrypoint-startdb.d` (creating the directory if necessary). After the database is up and ready for requests, these files will be executed automatically in alphabetical order.

The execution order and implications are the same as with the [Initialization scripts](#initialization-scripts) described above.

***Note:*** you can also put files under the `/docker-entrypoint-startdb.d` directory. This is kept for backwards compatibility with other widely used container images but should generally be avoided. Do not put files under `/container-entrypoint-startdb.d` **and** `/docker-entrypoint-startdb.d` as this would cause the same files to be executed twice!

***Note:*** if the database inside the container is initialized (started for the first time), startup scripts are executed after the setup scripts.

***Warning:*** files placed in `/container-entrypoint-startdb.d` are always executed after the database in a container is started, including pre-created databases. Use this mechanism only if you wish to perform a certain task always after the database has been (re)started by the container.

# Image flavors

| Flavor | Extension | Description | Use cases |
| -------| --------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------|
| Slim | `-slim` | An image focussed on smallest possible image size instead of additional functionality. | Wherever small images sizes are important but advanced functionality of Oracle Database is not needed. |
| Normal | [None] | A well-balanced image between image size and functionality. Recommended for most use cases. | Recommended for most use cases. |
| Full | `-full` | An image containing all functionality as provided by the Oracle Database installation. | Best for extensions and/or customizations. |

## Full image flavor

The full image provides an Oracle Database XE installation "as is", meaning as provided by the RPM install file.
A couple of modifications have been performed to make the installation more suitable for running inside a container:

* The `REDO` logs have been relocated into `$ORACLE_BASE/oradata/$ORACLE_SID/`
* The fast recovery area has been relocated into `$ORACLE_BASE/oradata/$ORACLE_SID/`
* `DBMS_XDB.SETLISTENERLOCALACCESS()` has been set to `FALSE`
* An `OPS$ORACLE` externally identified user has been created and granted `CONNECT` and `SELECT_CATALOG_ROLE` (this is used for health check and other operations)

### Normal image flavor
### 18c specific

* `LOCAL_LISTENER` is set to `NULL` (18c)
* `COMMON_USER_PREFIX` is set to `NULL` (18c)

### 11g R2 specific

* The `REDO` logs have been located into `$ORACLE_BASE/oradata/$ORACLE_SID/` (11gR2 image)
* The fast recovery area has been removed (11gR2 images)

## Normal image flavor

The normal image has all customizations that the full image has.
Additionally, it also includes the following changes:

#### Database components
* Oracle APEX has been removed (you can download and install the latest and greatest from [apex.oracle.com](https://apex.oracle.com))
### Database components
* Oracle APEX has been removed (you can download and install the latest and greatest from [apex.oracle.com](https://apex.oracle.com), 11gR2 image)
* The `HR` schema and folder have been removed
* The jdbc drivers have been removed

#### Operating system
### Operating system

* The following Linux packages are not installed: `binutils`, `gcc`, `glibc`, `make`
* The following Linux packages are not installed: `binutils`, `gcc`, `glibc`, `make` (11g R2)
* The jdbc drivers have been removed (`$ORACLE_HOME/jdbc`, `$ORACLE_HOME/jlib`)

#### Data files
### Data files

| Tablespace | Size | Autoextend | Max size |
| ---------- | -----: | ---------: | ----------- |
| `REDO` | 20 MB | `N/A` | `N/A` |
| `TEMP` | 2 MB | 10 MB | `UNLIMITED` |
| `UNDO` | 10 MB | 10 MB | `UNLIMITED` |
| `USERS` | 10 MB | 10 MB | `UNLIMITED` |
| Tablespace | 18c Size | 11g Size | Autoextend | Max size |
| ---------- | --------:| -------: | ---------: | ----------- |
| `REDO` | 20 MB | 20 MB | `N/A` | `N/A` |
| `SYSAUX` | 480 MB (CDB) <br> 342 MB (PDB) | 610 MB | 10 MB | `UNLIMITED` |
| `SYSTEM` | 353 MB (CDB) <br> 255 MB (PDB) | 353 MB | 10 MB | `UNLIMITED` |
| `TEMP` | 2 MB (CDB) <br> 2 MB (PDB) | 2 MB | 10 MB | `UNLIMITED` |
| `UNDO` | 70 MB (CDB) <br> 40 MB (PDB) | 10 MB | 10 MB | `UNLIMITED` |
| `USERS` | 10 MB | 10 MB | 10 MB | `UNLIMITED` |

#### Others
### Others

* The `DEFAULT` profile has the following set:
* `FAILED_LOGIN_ATTEMPTS=UNLIMITED`
Expand Down
Loading