Skip to content

Latest commit

 

History

History
102 lines (84 loc) · 6.83 KB

File metadata and controls

102 lines (84 loc) · 6.83 KB

docker-oracle-db

How to pull and use oracle db with Docker

Youtube : https://www.youtube.com/watch?v=56dSXI2PbCQ&t=148s

ORACLE REGISTRY

DOCKER STEPS

  • Go to Docker Terminal enter

    docker login container-registry.oracle.com

  • it'll ask for username and password (Credentials used to sign in to container-registry.oracle.com) - you'll see login succeeded
  • paste command

    docker pull container-registry.oracle.com/database/free:latest

  • wait for the pull to be successful and complete
  • Now youll see an image in DOcker Desktop with name "container-registry.oracle.com/database/free:latest"
  • Click on Run on that Image, and Give a container name(oracle-free-db), set host port(use same as it shows i.e 1521), In Environment Variables (enter ORACLE_PWD = password(or your own password))
  • More Details on the Oracle Database Free Docker Image : Oracle Database Free - Repository Detail
  • The Oracle Database 23ai Free Container Image contains a pre-built database, so the startup time is very fast. Fast startup can be helpful in CI/CD scenarios. To start an Oracle Database Free container, run the following command where, can be any custom name for the container:

    docker run -d --name oracle-free-db container-registry.oracle.com/database/free:latest

  • When the container is started, a random password is generated for the SYS, SYSTEM and PDBADMIN users. This is termed the default password.

To connect to the Oracle Database by running a SQL*Plus command from within the container using one of the following commands: (once you have started the Container)

This opens sqlplus in the terminal

  • docker exec -it sqlplus sys/<your_password>@FREE as sysdba
  • docker exec -it sqlplus system/<your_password>@FREE
  • docker exec -it sqlplus pdbadmin/<your_password>@FREEPDB1

To connect from outside of the container example SQLDeveloper, run the following connection string:

To connect to the database at the CDB$ROOT level as sysdba:

sqlplus sys/@//localhost:<port mapped to 1521>/FREE as sysdba

username: sys as SYSDBA, password: password, host: localhost, port: 1521. servicename: FREE

To connect as non sysdba at the CDB$ROOT level:

sqlplus system/@//localhost:<port mapped to 1521>/FREE

username: system, password: password, host: localhost, port: 1521. servicename: FREE

To connect to the default Pluggable Database (PDB) within the FREE Database:

sqlplus pdbadmin/@//localhost:<port mapped to 1521>/FREEPDB1

username: pdbadmin, password: password, host: localhost, port: 1521. servicename: FREEPDB1

  • In SQL Developer use, you can create individual connects for all 3

    username: sys as SYSDBA, password: password, host: localhost, port: 1521. servicename: FREE username: system, password: password, host: localhost, port: 1521. servicename: FREE username: pdbadmin, password: password, host: localhost, port: 1521. servicename: FREEPDB1

Example:

image Similarly, use above users SYSTEM / PDBADMIN to create connections in SQL Developer if needed.

TO CREATE TEST DATABASE / USERS

OT USER CREATION [ORDER TRANSACTIONS] image

  • Login to "sys as SYSDBA"
  • REFER : https://www.oracletutorial.com/getting-started/create-oracle-sample-database-for-practice/
  • Switch to Pluggable DB from SYSDBA:

    ALTER SESSION SET CONTAINER = FREEPDB1;

  • verify

    SHOW con_name; >>result is "FREEPDB1"

  • create user

    CREATE USER OT IDENTIFIED BY Orcl1234;

  • and grant priviliges

    GRANT CONNECT, RESOURCE, DBA TO OT;

    DONT FORGET TO COMMIT

  • Now create another connection in SQL Developer with

    username: OT, password: Orcl1234, host: localhost, port: 1521. servicename: FREEPDB1

  • Download the same Table and Data : Order Transactions Zip
  • And Run the sql files.
  • DONT FORGET TO COMMIT

HR USER CREATION [HUMAN RESOURCES]

  • Similarly, we can create HR
  • Login to "sys as SYSDBA"
  • Switch to Pluggable DB from SYSDBA:

    ALTER SESSION SET CONTAINER = FREEPDB1;

  • verify

    SHOW con_name; >>result is "FREEPDB1"

  • create user

    CREATE USER HR IDENTIFIED BY Orcl1234;

  • and grant priviliges

    GRANT CONNECT, RESOURCE, DBA TO HR;

    DONT FORGET TO COMMIT

  • Now create another connection in SQL Developer with

    username: HR, password: Orcl1234, host: localhost, port: 1521. servicename: FREEPDB1

  • Download the same Table and Data : https://www.oracletutorial.com/getting-started/oracle-sample-database/
  • And Run the sql files.
  • DONT FORGET TO COMMIT

SIMILARLY