oracle docker - ghdrako/doc_snipets GitHub Wiki
Oracle Container Registry site at https://container-registry.oracle.com.
docker login container-registry.oracle.com
# Docker will ask for a username and password; these are your Oracle SSO credentials.
# Copy the docker pull command from the registry page and paste it into your shell.
docker search nazwa_obrazu
docker pull container-registry.oracle.com/database/enterprise:19.3.0.0
docker images
The image 19.3.0.0 tag is 3GB, but that’s the compressed download size. The proper size of the 19c image, 7.87GB.
In Oracle database images, database configuration and datafiles are located at /opt/ oracle/oradata
. Mapping this directory to the local machine allows the database to
utilize high-performance storage, external redundancy, and persistence.
On Linux and Linux guests in Windows WSL environments, the target directory on the
host must be owned by the oracle
user or have permissions that permit the oracle user
to write the directory.
docker volume create oradata
docker volume create --opt type=none --opt o=bind --opt device=/oradata/
Despite the additional effort needed to create the volume and source directory before running containers, bind-mounted volumes are the best option for databases. Data on the volumes are accessible from the OS, and we can back up the data using either operating system commands or Docker’s volume management tools.
docker run ... \-v oradata_ORA19C:/opt/oracle/oradata \
...
The Docker daemon runs as root
so volumes directory will be owned by root
.
Database Configuration Assistant ran inside the container as the oracle user,10 it attempted to write files to directories on the container’s volume. Still, it’s mapped to a directory on the local filesystem the oracle user can’t access. Unable to create the necessary directories or write files in, DBCA fails.
Option for avoiding this is adding the oracle user and oinstall group in the Linux system:
sudo groupadd -g 54321 oinstall
sudo useradd -u 54321 -g oinstall oracle
Precreate directories to be mapped to volumes and set their ownership to oracle:oinstall
:
sudo mkdir -p $HOME/oradata/MYDB
sudo chown -R oracle:oinstall $HOME/oradata/MYDB
When a container runs for the first time, a startup script checks to see if a database exists and,
if not, creates one based on these values. We can override the defaults to customize the
database name with the -e
or --env
flags, followed by a variable-value pair. For example,
-e ORACLE_SID=TEST -e ORACLE_PDB=TESTPDB
overrides the default database names
and creates a database called TEST with a pluggable database named TESTPDB
docker run -d --name MYDB \
-p 10000:1521 \
-v $HOME/oradata/mydb/data:/opt/oracle/oradata \
-v $HOME/oradata/mydb/diag:/opt/oracle/diag \
-e ORACLE_SID=MYDB \
-e ORACLE_PDB=MYPDB \
oracle/database:19.3.0-ee
docker run -d --name ORCL1 \
--hostname dbhost1 \
-e ORACLE_SID=ORA1 \
-e ORACLE_PDB=PDB1 \
-v $HOME/oradata/mydb/data:/opt/oracle/oradata \
-v $HOME/oradata/mydb/diag:/opt/oracle/diag \
-e ORACLE_SID=ORA1 \
-e ORACLE_PDB=PDB1 \
-v /oradata/ORCL1:/opt/oracle/oradata \
When running this command on a Linux system or from a Linux shell on a Windows WSL host, be sure to create the necessary directories first:
sudo mkdir -p $HOME/oradata/mydb/{data,diag}
sudo chown -R oracle:oinstall $HOME/oradata/mydb
docker logs -f MYDB
#########################
DATABASE IS READY TO USE!
#########################
Datafiles are already patched. Skipping datapatch run.
The following output is now a tail of the alert.log:
ORCLPDB1(3):
ORCLPDB1(3):XDB initialized.
2021-03-01T17:32:38.353181+00:00
ALTER SYSTEM SET control_files='/opt/oracle/oradata/MYDB/control01.ctl'
SCOPE=SPFILE;
Access shell
docker exec -it ORCL bash
sqlplus / as sysdba
docker exec -it MYDB sqlplus / as sysdb
Inspect env variables
docker container inspect --format='{{json .Config.Env}}' ORCL | jq
docker container inspect --format '{{range .Config.Env}}{{printf "%s\n" .}}{{end}}' ORCL
Castomizing
docker run ... -e ORACLE_SID=TEST ...
docker run ... --env ORACLE_PDB=TESTPDB1 ...
Using file
$ cat db.env
ORACLE_SID=TEST
ORACLE_PDB=TESTPDB1
ORACLE_EDITION=EE
ENABLE_ARCHIVELOG=true
docker run ... --env-file db.env ...
Environment Options in Oracle Images
Oracle’s container image repository has extensive documentation at https://github.com/oracle/docker-images/tree/main/OracleDatabase/SingleInstance, including environment options for customizing database startup and creation. Environment options for customizing Oracle database creation in containers (defaults shown in brackets [])
ORACLE_SID
: The Oracle Database SID [ORCLCDB]ORACLE_PDB
: The Oracle Database PDB name [ORCLPDB1]ORACLE_EDITION
: The Oracle Database Edition7,8ORACLE_CHARACTERSET
: The database character set [AL32UTF8]ORACLE_PWD
: The Oracle Database SYS, SYSTEM, and PDB_ADMIN password [randomly generated during database creation]ENABLE_ARCHIVELOG
: Enable archive logging [False]
Optional environment options available for managing memory in Oracle database containers.
INIT_SGA_SIZE
: The total memory, in MB, for the SGA components.INIT_PGA_SIZE
: The target aggregate PGA size, in MB.7AUTO_MEM_CALCULATION
: Calculates total memory allocation based on the container’s available memory during database creation. When set to false, the total memory allocation is 2GB. This option is ignored when eitherINIT_SGA_SIZE
orINIT_PGA_SIZE
are set.
Using
To perform operations on the database that require the restart of the database, use the maintenance shutdown/startup scripts, /home/oracle/shutDown.sh
and /home/oracle/startUp.sh
instead of issuing shutdown immediate
and startup
commands respectively as the latter would lead to exiting of the container.
sqlplus / as sysdba;
$ startup force nomount;
$ select status from v$instance;