title | subtitle | author | date | tvddocversion | papersize | listings-disable-line-numbers | titlepage | toc | toc-own-page | toc-depth | linkcolor | numbersections | mainfont | monofont | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SOUG Day May 2019 - Oracle and Docker |
Demos and examples from the lecture |
|
22 May 2019 |
1.0 |
a4 |
true |
true |
true |
true |
2 |
blue |
true |
Nunito Sans SemiBold |
Courier New |
All demos are done on Docker Desktop Community Edition 2.0.4.1 for MacOS which is based on Docker Engine 19.03. The examples are supposed to run on all Docker environments either on Linux, MacOS or Window. Below we provide the steps to setup the demo environment on MacOS. For other OS the setup as to be adjusted accordingly.
- Install Docker Desktop for Mac
- Clone the Git repository oehrlis/docker
git clone https://github.com/oehrlis/docker
this may require as well a Git installation. Alternatively you can just download the ZIP of the repository. - Download the Oracle software used to build the Oracle database images
- Oracle Database 18c (18.3) for (Linux x86-64)
- Oracle Database Release Update 18.6.0.0.0 (Patch 29301631)
- Oracle OJVM Release Update 18.6.0.0.190416 (Patch 29249584)
- OPatch 12.2.0.1.17 for DB 18.x releases (APR 2019) (Patch 6880880)
- Download the Docker base image.
Step 1: Clone the Oracle vagrantbox respoistory
Install Docker for your OS.
Step 2: Clone the Oracle vagrantbox respoistory
git clone https://github.com/oehrlis/docker docker
Step 3: Download and store the Oracle binary package in the build context
cd docker/OracleDatabase/18.6.0.0
cp ~/Downloads/LINUX.X64_180000_db_home.zip software/
cp ~/Downloads/p29301631_180000_Linux-x86-64.zip software/
cp ~/Downloads/p29249584_180000_Linux-x86-64.zip software/
cp ~/Downloads/p6880880_180000_Linux-x86-64.zip software/
Step 4: Download the Docker base image.
docker pull oraclelinux:7-slim
Remove existing builds and cache to make sure we do start on a greenfield. Not absolutely necessary.
docker rmi oracle/database:18.6.0.0
docker system prune
docker images
Build the Docker image for Oracle 18c with latest RU using local software in the build context.
cd docker/OracleDatabase/18.6.0.0
#docker build -t oracle/database:18.6.0.0 .
docker build -t oracle/database:18.6.0.0_soug .
Takes about 2m26.629s with and 12m25.145s without cache.
check the volumen folder
ls -al /data/docker/volumes/tdb186s
Manually create a database container using docker run
. Takes about 15min with creating the DB.
docker run --detach \
--hostname tdb186s --name tdb186s \
--volume /data/docker/volumes/tdb186s:/u01 \
-p 1521:1521 -p 5500:5500 \
-e ORACLE_SID=TDB186S \
oracle/database:18.6.0.0
Check what happens during startup using docker logs
.
docker logs -f tdb186s
DB Container is ready as soon as the following me
The Oracle base remains unchanged with value /u00/app/oracle
---------------------------------------------------------------
- DATABASE TDB186S IS READY TO USE!
---------------------------------------------------------------
---------------------------------------------------------------
Tail output of alert log from TDB186S:
---------------------------------------------------------------
Open a bash shell to the database conntainer using docker exec
.
docker exec -it tdb186s bash --login
Open a sqlplus on database conntainer using docker exec
.
docker exec -it tdb186s sqlplus / as sysdba
Or tail the alert log
docker exec -it tdb186s tail -f $ORACLE_BASE/diag/rdbms/tdb186s/TDB186S/trace/alert_TDB186S.log
Check the running container
docker ps
docker logs -f tdb186s
docker inspect tdb186s
Stop the container
docker stop tdb186s
Remove the container
docker rm tdb186s
Verify the volume path to see that we still have the DB files.
ls -al ${DOCKER_VOLUME_BASE}/tdb186s
Review the docker compose file.
## single tenant database
tdb186s:
image: ${DOCKER_USER}/${DOCKER_REPO}:18.6.0.0
container_name: tdb186s
hostname: tdb186s
restart: unless-stopped
network_mode: bridge
volumes:
- ${DOCKER_VOLUME_BASE}/tdb186s:/u01
- ./config:/u01/config
ports:
- "1521"
environment:
CONTAINER: 'FALSE'
INSTANCE_INIT: /u01/config
ORACLE_SID: TDB186S
Start the services using docker-compose
. This will create the container and network as specified in the compose file.
docker-compose up -d
Check the log output for this container.
docker-compose logs -f
Check the running container
docker-compose ps
Stop and remove the service
docker-compose down
The possibility to specify custom setup and startup scripts brings quite some flexibility to setup custom database environments. There are a couple of examples in the GitHub repository see oehrlis/docker/samples.
The EUS example provides the scripts and compose file to create an Oracle database container as well an Oracle Unified Directory server container. The custom config file will do the following steps during initial startup.
OUD container eusoud:
- Create a OUD instance oud_eus
- Configure OUD instance to support EUS
- Setup EUS context
- Create root user and provide accessibility for DB container (eg. store password in text file)
- Create a test organisation with user Trivadis LAB organisation
DB container eusdb:
- Create a test database TEUS01
- Install the SCOTT schema
- Install the Trivadis HR schema TVD_HR including VPD
- Register the database in the EUS context of the OUD server
- Create some global user and roles in the database
- Configure EUS mapping
- Configure keystore for LDAPS support in EUSM utility.
Review the docker compose file with multiple services for a Oracle database container and an Oracle Unified Directory Server container. See also docker-compose.yml
version: '3'
services:
# Database service
db:
image: ${DOCKER_USER}/${DOCKER_REPO}:${DOCKER_DB_VERSION}
container_name: eusdb
hostname: db
restart: unless-stopped
depends_on:
- oud
cap_add:
- SYS_PTRACE
- SYS_ADMIN
volumes:
- ${DOCKER_VOLUME_BASE}/eus/db:/u01
- ./db:/u01/config
- ./oud:/u01/oud
ports:
- "6521:1521"
environment:
INSTANCE_INIT: /u01/config
ORACLE_SID: TEUS01
# OUD LDAP service
oud:
image: oracle/oud:${DOCKER_OUD_VERSION}
container_name: eusoud
hostname: oud
cap_add:
- SYS_PTRACE
- SYS_ADMIN
restart: unless-stopped
volumes:
- ${DOCKER_VOLUME_BASE}/eus/oud:/u01
- ./oud:/u01/config
ports:
- "6389:1389"
- "6636:1636"
- "6444:4444"
environment:
OUD_CUSTOM: 'TRUE'
INSTANCE_INIT: /u01/config
BASEDN: dc=trivadislabs,dc=com
OUD_INSTANCE: oud_eus
Check the volume folder
ls -al ${DOCKER_VOLUME_BASE}/eus/
Startup the services using docker-compose
. Takes about 15min with creating the DB and the OUD instance.
docker-compose up -d
Review the compose log files.
docker-compose logs -f
Start a bash shell on the DB container
docker exec -it eusdb bash --login
Do some EUS via sqlplus
sqh
connect king/LAB01schulung
show user
@sousrinf
select * from session_roles;
select EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,DEPARTMENT_ID from tvd_hr.employees;
connect blofeld/LAB01schulung
show user
@sousrinf
select * from session_roles;
select EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,DEPARTMENT_ID from tvd_hr.employees;
connect bond/LAB01schulung
show user
@sousrinf
select * from session_roles;
select EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,DEPARTMENT_ID from tvd_hr.employees;
connect lynd/LAB01schulung
show user
@sousrinf
select * from session_roles;
select EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,DEPARTMENT_ID from tvd_hr.employees;
Stop and remove the service
docker-compose down
Alternatively the software can also be downloaded from a local HTTP server during build. For this simple HTTP is required eg. a Docker container with busy box. Using this method it is not necessary to copy the software in the build context. The setup script will get the software from the HTTP server. The following Docker compose file will create a Docker container with a HTTP server based on busy box. All software in the folder ${DOCKER_VOLUME_BASE}/orarepo
is now available via (http://localhost)
version: '3'
services:
orarepo:
image: busybox
container_name: orarepo
hostname: orarepo
restart: unless-stopped
network_mode: bridge
volumes:
- ${DOCKER_VOLUME_BASE}/orarepo:/www
ports:
- "80:80"
command: httpd -fvvv -h /www
Startup the Docker container:
docker-compose up -d
Get the IP address of the local HTTP server:
orarepo_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' orarepo)
Build the docker image using docker build
and provide the IP of the HTTP server.
docker build --add-host=orarepo:${orarepo_ip} -t oracle/database:18.6.0.0 .
The RUN command respectively the script 10_setup_db_18.6.sh
in the Dockerfile will check if the software is part of the build context. If not, it will use the host orarepo to download the software.
Create PDF out of markdown file using pandoc and trivadis template
docker run --rm -v "$PWD":/workdir:z oehrlis/pandoc \ --template trivadis --listings --pdf-engine=xelatex \ -o SOUG_1905_Oracle_and_Docker_demo_soe.pdf SOUG_1905_Oracle_and_Docker_demo_soe.md