docker-images: Setup script ignored if using image container-registry.oracle.com/database/express:21.3.0-xe

Hello! I use a local Oracle Express DB run by docker-compose with this configuration

version: '3'
services:
  oracledb:
    image: container-registry.oracle.com/database/express:21.3.0-xe
    volumes:
      - oracle_data:/opt/oracle/oradata
      - ./local-dev-env/setup-database.sh:/opt/oracle/scripts/setup/setup-database.sh
    environment:
      - ORACLE_PWD=manager
    ports:
      - "1521:1521"
      - "5000:5000"
volumes:
  oracle_data:

Problem is that setup script is never run also if I drop all the volumes by docker-compose down -v As far as I can see the setup script is run in case there is no database created and that is checked by this condition in runOracle.sh

if [ -f "$ORACLE_BASE"/oradata/.${ORACLE_SID}"${CHECKPOINT_FILE_EXTN}" ] && [ -d "$ORACLE_BASE"/oradata/"${ORACLE_SID}" ]; then

So only data from /oradata used here and nothing else shall be mounted as volumes here As far as I can see all is done as it’s described here

https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md

What could be a problem? Why setup script is ignored?

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@usharik the problem here is that you are using docker volumes First keep in mind that 21.3.0-xe image comes with a pre-configured DB

So there are two types of volumes that can be used for database persistence with the image

  1. Docker Volume - When using docker volume; the prebuiltdb (already setup/configured) from the image is copied into the docker volume
  2. Host Directory - When using host directory for database persistence ; a new database is configured in the host directory

Right now you are creating a docker volume and mounting that to the /opt/oracle/oradata which results in copying of database files from image to the docker volume and no new db is setup hence setup scripts are not called. So you can create a host directory and give is write permission instead and then try docker compose

mkdir -p <host_dir_loc>
chmod 777 <host_dir_loc>

and then change the docker compose file to

version: '3'
services:
  oracledb:
    image: container-registry.oracle.com/database/express:21.3.0-xe
    volumes:
      - <host_dir_loc>:/opt/oracle/oradata
      - ./local-dev-env/setup-database.sh:/opt/oracle/scripts/setup/setup-database.sh
    environment:
      - ORACLE_PWD=manager
    ports:
      - "1521:1521"
      - "5000:5000"

This is start configuring/setting up a new database and will execute the setup scripts

P.S - This is also covered in the documentation under “Mounting Docker volume/host directory for database persistence”