By following this tutorial, you will be able to run an instance of Oracle Enterprise Database on Docker.
(01) On browser, login to your Docker Hub account and checkout to get the official Oracle Database (Enterprise Edition) image.
(02) On terminal, login to the same Docker Hub account again and pull Oracle Enterprise Database image.
$ docker login
$ docker pull store/oracle/database-enterprise:12.2.0.1
(03) Run the Oracle DB image as a container.
$ docker run -d --network="bridge" -p 1521:1521 -p 5500:5500 -it --name Oracle_DB_Container store/oracle/database-enterprise:12.2.0.1
(04) When the container gets created, Oracle DB will run setup scripts under the hood. Until this process gets completed, the container will stay in starting state.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82323h334093 store/oracle/database-enterprise:12.2.0.1 "/bin/sh -c '/bin/ba…" 16 seconds ago Up 16 seconds (starting) 0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp Oracle_DB_Container
(05) You can inspect these processes by accessing the Docker container itself.
$ docker exec -it Oracle_DB_Container /bin/bash
[oracle@82323h334093 /]$ ps -aux
[oracle@82323h334093 /]$ lsnrctl status
Also, you can run the setup scripts manually if you prefer.
[oracle@82323h334093 /]$ /bin/bash /home/oracle/setup/dockerInit.sh
(06) Once the container comes to healthy status after few minutes, you can login as the default DBA user and inspect default setup.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82323h334093 store/oracle/database-enterprise:12.2.0.1 "/bin/sh -c '/bin/ba…" 5 minutes ago Up 5 minutes (healthy) 0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp Oracle_DB_Container
$ docker exec -it Oracle_DB_Container /bin/bash
[oracle@82323h334093 /]$ sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Sun Dec 1 06:03:49 2019
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL>
(07) By default, you have 2 System users with default password: Oradoc_db1
. Make sure you change their passwords and keep them safe.
SQL> SELECT username, default_tablespace, profile, authentication_type FROM dba_users WHERE account_status = 'OPEN';
USERNAME DEFAULT_TABLESPACE PROFILE AUTHENTI
--------------------------------------------------------------------------------
SYS SYSTEM DEFAULT PASSWORD
USERNAME DEFAULT_TABLESPACE PROFILE AUTHENTI
--------------------------------------------------------------------------------
SYSTEM SYSTEM DEFAULT PASSWORD
SQL> password
Changing password for <user>
Old password:
New password:
Retype new password:
Password changed
SQL>
(08) It is not a good practice to use System users for DB manipulations. Therefore, create new users as necessary in the next steps.
SQL> ALTER SESSION SET "_ORACLE_SCRIPT"=true;
SQL> CREATE USER app_user IDENTIFIED BY pf123;
(09) To access DB externally, we exposed our DB container in port 1521 (default Oracle port). If your Oracle client runs in the same Docker network as your DB container, you can use the Docker IP of DB container. If the client connects from a different network, use the host server’s IP as usual (make sure the port and IP is visible to client machine).
// docker network IP
$ docker inspect Oracle_DB_Container | grep -i IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
// host IP
$ hostname -i
172.31.XX.XXX
(10) If you use a terminal client like SQL Plus on Oracle Instant Client, you can login with below commands directly. If you use a GUI client tool like Oracle SQL Developer or TOAD GUI, just enter the DB credentials, IP address, port (default: 1521) and try to connect.
bash-4.2# sqlplus <USERNAME>/<PASSWORD>@//<IP_ADDRESS>:1521/<DB_NAME>
bash-4.2# sqlplus <USERNAME>/<PASSWORD>@//<IP_ADDRESS>:1521/<SID>.<DOMAIN_NAME>
// when you use SYS user, you need to specify the user role as SYSDBA or SYSOPER
bash-4.2# sqlplus sys/Oradoc_db1@172.17.0.2:1521/ORCLCDB.localdomain as sysdba
// login as a regular user
bash-4.2# sqlplus app_user/pf123@172.17.0.2:1521/ORCLCDB.localdomain
NOTE: If you want to connect this database in Docker way using an Oracle DB client running on Docker, you can use Oracle DB Instant Client.
✅ Tested DB | : Oracle 12c |
---|---|
✅ Tested OS's | : RHEL 7+, CentOS 7+, Ubuntu 18.04+, Debian 8+ |
✅ Tested Gear | : Cloud (AWS EC2 T2), On-Prem (Bare Metal) |
Leave a comment