Update: I’ve moved my setup process to Dockerize Oracle and APEX to Github. It will be maintained with the latest steps I’m using it. The repository is docker-oracle-setup.
Last week I needed to test an Oracle 12.2 feature and got hooked on Docker. I wrote an article on how to setup an Oracle DB 12.2 Docker container. This solved my goal to test the 12.2 feature. Roel Hartman then wrote a followup article about how to setup an Oracle database in a Docker container but preserve the data on his laptop. I.e. if the container was deleted or needed to be rebuilt his database data wouldn’t be lost.
Roel’s article inspired me to setup an entire Dockerized Oracle and APEX environment, thus replacing my current local VM infrastructure. I took a lot of notes about the process. The result is this blog post which contains everything I did to create my containers and link them together. To get it all working I used the following articles and all my scripts are a result of a combination of the code found in the links.
- APEX and ORDS up and running in….2 steps! by Joel Kallman
- Dockerize your APEX development environment by Roel Hartman
- Oracle Database 12c now available on Docker by Maria Colgan
- ORDS Docker Setup by Lucas Souza
Background
A few things to keep in mind that will help when reading the rest of this article:
- All my scripts are Linux / MacOS focused. If you use a Windows machine you’ll need to translate
- I specifically made reference to “your laptop” to emphasize what was run “on your machine” vs “in a docker container”
The following key configurations were used for the containers:
Port Mapping
Container | Port | Description |
---|---|---|
oracle |
32712 |
TNS listener |
ords |
32713 |
ORDS |
Passwords
Container | Username | Password | Description |
---|---|---|---|
oracle |
sys |
Oradoc_db1 |
|
oracle |
admin |
oracle |
Workspace Internal for APEX admin |
Download Files
Due to licensing restrictions I can’t host/provide these files in Github or elsewhere. As such you’ll need to download them manually. Download the following files and store them in your Downloads
folder
- Docker Images: github.com/oracle/docker-images. This will be saved as
docker-images-master.zip
- Oracle 12.2 Database: Go to www.oracle.com/technetwork/database/enterprise-edition/downloads and download
linuxx64_12201_database.zip
- APEX: Go to www.oracle.com/technetwork/developer-tools/apex/downloads and download latest version of APEX. For this blog it was
5.1.3
- ORDS: Go to www.oracle.com/technetwork/developer-tools/rest-data-services/downloads and download latest version of ORDS. For this blog it was
3.0.12
Laptop Folder Structure
The following script will create a folder structure that looks like:
Path | Description |
---|---|
~/docker |
root |
~/docker/apex |
To host APEX installation and images for each version |
~/docker/apex/5.1.3 |
APEX 5.1.3 installation files |
~/docker/oracle |
Hold Oracle 12.2 data files |
~/docker/ords |
ORDS Dockerfile (to build ORDS image) |
~/docker/tmp |
Temp folder |
1 | mkdir ~/docker |
Move Downloaded Files
1 | # ORDS (done in ORDS section) |
Docker
Build Oracle Docker Image
This will be a different setup then I previously blogged about in that this docker container will separate the data from the app. I.e. we can remove the container and rebuild it while keeping all the data in place. This allows for us to
1 | cd ~/docker/tmp |
Setup Docker Network
In order for the containers to “talk” to each other we need to setup a Docker network and associate all the containers on this network. Containers can reference each other by their respective container names. When referencing another container on the same Docker network the port used is the container’s native port not the mapped port on your laptop.
1 | docker network create oracle_network |
Create Oracle Docker Container
The following command will create and run the Oracle Docker container. It’s TNS listener will be accesible via port 32712
on your laptop. The reference to the APEX installation files are necessary only whe installing APEX.
Adding the -e TZ
will set the appropriate timezine for the OS and the database. A full list of timezones can be found here. If excluded it will default to UTC.
1 | docker run \ |
In another terminal tab, set the sys
password to Oradoc_db1
and install APEX
1 | docker exec oracle ./setPassword.sh Oradoc_db1 |
Install APEX
In a terminal tab on your laptop run:
1 | # Install and configure APEX |
The above command will open a SQL
prompt. Run the following scripts:
1 | -- Install APEX |
Now exit bash:
1 | # Exit bash |
Create ORDS Container
The following assumes that you’ve downloaded ORDS 3.0.12
. Referencing the ORDS version so that can create ORDS images for each ORDS release.
The scripts below will first create the ORDS Docker image then create the containers.
1 | # Uses https://github.com/martindsouza/docker-ords Dockerfile |
You should now be able to go to localhost:32713/ords/ on your laptop to run APEX
Useful Commands
Docker Start/Stop Containers
1 | docker stop -t 200 oracle |
Connect to DB from laptop
sqlcl
is my alias for SQLcl. More information on how to install SQLcl on MacOS here.
1 | # CDB (not usually required) |
Create New DB User
1 | define new_user = 'martin' |