Docker Community Forums

Share and learn in the Docker community.

Oracle 19c - Add start-up script to dockerfile

So I found a past post that looked like my question too but its for Oracle. Below is the link to the past post.

Requirement is to have a docker image that a dev can pull and when spun up, it should have certain PDBs ready and users created. I found a way to do this by mounting a custom_script that runs at startup. Like so…

docker run --name DM -p 1523:1521 -e ORACLE_SID=DM -e ORACLE_PDB=DM1 -e ORACLE_PWD=Xyz1234 -e ORACLE_MEM=4000 -v /home/oracle/scripts:/opt/oracle/scripts/startup --shm-size=1g -d oracle/database:19.3.0-ee

But I’ll have to supply the custom_script to the dev and instruct on where to save it…

What I’m looking to do it to incorporate that into the image itself so I don’t have to supply the file separately. By modifying my dockerfile so it picks up the script and incorporates it into the image built. I don’t want to use the add changes and commit (create new image) route. Below is for mysql and I’m looking for an Oracle equivalent

FROM mysql
ADD sqldump.sql /docker-entrypoint-initdb.d/


thank you

The ARG instruction allows you to define “build arguments” for use by the Dockerfile. These are only visible during the build phase, not when the container based on the image is running. Arguments can have default values, which are overridden by --build-arg parameters from the build command. Each build using different build arguments will create a new image. This may not be what you want.

The ENV instruction allows you to define environment variables for use by the Dockerfile. These represent default values that can be overridden on the command line at runtime by passing -e parameters. The environment variables are persistent within the container when it is running.

In some cases, you want build arguments to be persisted, so their values are visible beyond the build phase. In this case you must set the default values of environment variables using build arguments, as shown below.

Overwrite the “Dockerfile” with the following contents. Notice the RUN is used to create two directories.


Dockerfile to build basic Oracle Linux container images

Based on Oracle Linux 7 - Slim


Set the base image to Oracle Linux 7 - Slim

FROM oraclelinux:7-slim

File Author / Maintainer

Use LABEL rather than deprecated MAINTAINER


LABEL maintainer=""


Define the build arguments, setting default values.

ARG ORACLE_HOME=/u01/app/oracle/product/
ARG DATA_LOCATION=/u02/oradata


Define the environment variables, setting default values using the arguments.



RUN mkdir -p {ORACLE_HOME} && \ mkdir -p {DATA_LOCATION}


Build the image, run a container based on it and check the root file system to see the extra directories.

docker build -t ol7_slim:latest . docker run -dit --name ol7_slim_con ol7_slim:latest
docker exec -it ol7_slim_con ls bin dev home lib64 mnt proc run srv tmp u02 var boot etc lib media opt root sbin sys u01 usr
Once you are happy the commands ran as expected remove the container.

$ docker rm -vf ol7_slim_con
Now build the image again, but alter the build arguments using the --build-arg parameter. Notice the “u03” and “u04” directories have now been created.

$ docker build -t ol7_slim:latest
–build-arg ORACLE_HOME=/u03/app/oracle/product/
–build-arg DATA_LOCATION=/u04/oradata

$ docker run -dit --name ol7_slim_con ol7_slim:latest

docker exec -it ol7_slim_con ls bin dev home lib64 mnt proc run srv tmp u04 var boot etc lib media opt root sbin sys u03 usr

Sorry but this either went over my head or not the solution I’m looking for. I need to customize the oracle 19c dockerfile so that when I build the image, it includes the contents of a sql file or link to it. When a dev spins up a container, he sees the multiple pluggable databases, users and grants, etc created and ready to use. I’m not looking to create directories. Kindly look at the mysql example I included.