This article provides information about how to install oracle database in docker and oracle usage in docker.
For detailed information about Docker before installation, please refer to my article “What is Docker? Docker Installation and Usage“.
Install Oracle Database in Docker
To install oracle in the docker environment, first you need to register at “hub.docker.com”.
After the registration operation, the required oracle database must be found with search and the required usage agreement must be accepted.
After the required registration and contract operations are done, log in to the user account from the command interpreter as follows.
1 | docker login |
Download Oracle Database Docker Image
After login, download the image.
1 | docker pull store/oracle/database-enterprise:12.2.0.1 |
You can copy the above code from the below screen.
The Oracle database also has a slim version that does not include tools such as APEX.
1 | docker pull store/oracle/database-enterprise:12.2.0.1-slim |
At least 20GB of free space is required to install oracle in the Docker environment.
Create Oracle Database Container From Docker Image
Create the container using the downloaded image.
1 | docker run -d -p 1521:1521 --name oracle store/oracle/database-enterprise:12.2.0.1 |
It is important for later use to give the appropriate name with the -name parameter.
To use the Oracle APEX tool, the APEX port must also be allowed.
1 | docker run -d -p 8080:8080 -p 1521:1521 --name oracle store/oracle/database-enterprise:12.2.0.1 |
Oracle Usage in Docker Environment
After the installation is complete, you can connect to the Oracle SQL Plus tool to create users and grant the necessary permissions as follows.
1 | docker exec -it oracle bash -c "source /home/oracle/.bashrc; sqlplus /nolog" |
Connect to Oracle as sysdba in Docker
1 | connect sys as sysdba; |
Create Oracle User in Docker
1 | create user YOUR_USER_NAME identified by YOUR_USER_PASSWORD; |
Grant Permission to User in Docker
1 | GRANT ALL PRIVILEGES TO YOUR_USER_NAME; |
NOTE: You can grant permissions for certain privileges such as SELECT, INSERT, UPDATE, CREATE TABLE instead of ALL PRIVILEGES.
Connect To SQL Developer in Docker
1 2 3 4 5 | Username: YOUR_USER_NAME Password: YOUR_USER_PASSWORD Hostname: localhost Port: 1521 Service name: ORCLCDB.localdomain |
Find Oracle Service Name From SQL Plus
You can execute the following query in SQL Plus to find the Oracle service name value.
1 | select value from v$parameter where name='service_names'; |
Start and Stop Oracle in Docker
Oracle restarts at the start of each operating system using the container name that you provided with the -name parameter during installation.
1 | docker start oracle |
1 | docker stop oracle |
NOTE: We assumed that we set the -name parameter as oracle.
After Oracle installation and user creation process, Oracle database can be managed through Oracle SQL Developer tool according to user permission.
Have a good day.
1
docker pull store/oracle/database-enterprise:12.2.0.1-slim
SQL> create user mxnf6_13_5 identified by password;
create user mxnf6_13_5 identified by password
*
ERROR at line 1:
ORA-65096: invalid common user or role name.
*
ERROR at line 1:
ORA-65049: Creation of local user or role is not allowed in this container.
seems like one cannot created local user when they use oracle slim
you can just type: alter session set “_ORACLE_SCRIPT”=true;
I followed this tutorial but did little bit differently and it worked:
$ docker search oracle /* Not necessary actually */
$ docker pull oracleinanutshell/oracle-xe-11g:latest
$ docker run -d -p 1521:1521 –name oracle oracleinanutshell/oracle-xe-11g:latest
#—————————————————————
$ docker ps
$ docker exec -it oracle bash
# sqlplus nolog
Thank you for your contribution.
Hi,
I found I had to switch to the included pluggable DB before I could create a new user using
alter session set container=ORCLPDB1;
(found using select CON_ID, NAME, OPEN_MODE, TOTAL_SIZE from v$containers; from https://techgoeasy.com/oracle-12c-pluggable-database-commands/)
otherwise I had the same error mentioned by mano
Hi,
I want to import new schema file.dmp.
how to copy to dump?
how to allow permission?
thanks.