Skip to content

Failing to adapt the image to run in Openshift (k8s) as non-default (not oracle) user #2995

@dpanassoll

Description

@dpanassoll

We have oracle db 19c container with some preloaded data in CI pipeline. It runs fine in VMs with docker and in AKS. But we have to migrate whole CI setup to openshift. Openshift runs all containers with random uid which must be between [1001220000, 1001229999] and, as its written here, this users group is root (gid 0).
https://docs.redhat.com/en/documentation/openshift_container_platform/3.11/html/creating_images/creating-images-guidelines#openshift-specific-guidelines

Which is a problem because default user for container is oracle with UID 54321 and the same GID. So database container fails to start.

We can replicate this problem with simple docker compose

services:
  database:
    environment:
      - DB_SERVICE_NAME=myservice
      - TZ=Europe/Warsaw
    image: myregistry/mydb:3.31.0.0.d
    container_name: oracledb19
    ports:
      - 1521:1521
    user: 1001220000:0

And error

e trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 11-JUL-2025 10:43:01

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/c1a8382da7e7/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                11-JUL-2025 10:43:01
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/c1a8382da7e7/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jul 11 10:43:01 2025
Version 19.3.0.0.0

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

ERROR:
ORA-12547: TNS:lost contact

Enter user-name: Enter password:
ERROR:
ORA-12547: TNS:lost contact

Enter user-name: SP2-0306: Invalid option.
Usage: CONN[ECT] [{logon|/|proxy} [AS {SYSDBA|SYSOPER|SYSASM|SYSBACKUP|SYSDG|SYSKM|SYSRAC}] [edition=value]]
where <logon> ::= <username>[/<password>][@<connect_identifier>]
      <proxy> ::= <proxyuser>[<username>][/<password>][@<connect_identifier>]
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
The following output is now a tail of the alert.log:
2025-07-09T15:24:23.996671+00:00
PKOUR12(3):Resize operation completed for file# 11, old size 378880K, new size 384000K
2025-07-09T15:25:14.877105+00:00
Thread 1 advanced to log sequence 24 (LGWR switch)
  Current log# 3 seq# 24 mem# 0: /opt/oracle/oradata/MYPROJECT/redo03.log
2025-07-09T15:28:00.734204+00:00
Resize operation completed for file# 1, old size 921600K, new size 931840K
2025-07-09T15:30:12.421623+00:00
Thread 1 advanced to log sequence 25 (LGWR switch)
  Current log# 1 seq# 25 mem# 0: /opt/oracle/oradata/MYPROJECT/redo01.log

We tried various things, adding user to 0 guid and setting this group as /opt group, chmod 777 on /opt , but all failed the same way (as above).

The only solution which moved us a little bit further was creating oracle2 user with specific UID, adding it to the same groups as original oracle and setting it as owner of /opt

Dockerfile

# docker buildx build -t test_db:1.0 .
FROM myregistry/mydb:3.31.0.0.d

USER root
# we separated these to separate steps for debugging purposes
RUN chmod 777 -R /opt && chmod -R 777 /home/oracle && chmod -R 777 /tmp
RUN useradd -u 1001220000 -g oinstall -l -m -s /bin/bash oracle2
RUN usermod -a -G oinstall,dba,oper,backupdba,dgdba,kmdba,racdba oracle2
RUN chown -R oracle2:oinstall /opt
RUN echo 'oracle2 ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers
USER oracle2

Which still gives us some error. We need some assistance here ...

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 11-JUL-2025 13:02:11

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 19.0.0.0.0 - Production
System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Log messages written to /opt/oracle/diag/tnslsnr/b4fd48830f05/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date                11-JUL-2025 13:02:11
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/b4fd48830f05/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
The listener supports no services
The command completed successfully

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jul 11 13:02:12 2025
Version 19.3.0.0.0

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

Connected to an idle instance.

SQL> ORACLE instance started.

Total System Global Area 1610609928 bytes
Fixed Size                  9135368 bytes
Variable Size             822083584 bytes
Database Buffers          771751936 bytes
Redo Buffers                7639040 bytes
Database mounted.
Database opened.
SQL>
System altered.

SQL>
System altered.

SQL>
PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
The following output is now a tail of the alert.log:
2025-07-11T13:03:41.439665+02:00
ALTER SYSTEM SET audit_sys_operations=FALSE SCOPE=SPFILE;
2025-07-11T13:03:41.450997+02:00
ALTER SYSTEM SET audit_trail='NONE' SCOPE=SPFILE;
2025-07-11T13:03:42.067475+02:00
===========================================================
Dumping current patch information
===========================================================
No patches have been applied
===========================================================
2025-07-11T13:03:44.640935+02:00
TABLE SYS.WRP$_REPORTS: ADDED INTERVAL PARTITION SYS_P221 (5671) VALUES LESS THAN (TO_DATE(' 2025-07-12 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLE SYS.WRP$_REPORTS_DETAILS: ADDED INTERVAL PARTITION SYS_P222 (5671) VALUES LESS THAN (TO_DATE(' 2025-07-12 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLE SYS.WRP$_REPORTS_TIME_BANDS: ADDED INTERVAL PARTITION SYS_P225 (5670) VALUES LESS THAN (TO_DATE(' 2025-07-11 01:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
2025-07-11T13:04:27.544971+02:00
Warning: VKTM detected a forward time drift.
Please see the VKTM trace file for more details:
/opt/oracle/diag/rdbms/MYPROJECT/MYPROJECT/trace/MYPROJECT_vktm_54.trc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions