Oracle Database 21c XE, setting up a demo environment using Vagrant and Oracle VirtualBox (part 4)

Marc Lameriks

I wanted to set up a demo environment with Apache Kafka (an open-source distributed event streaming platform) and an Oracle Database, all within containers. For my purpose I opted for Oracle Database XE.
[https://kafka.apache.org/]

As I did before, on my Windows laptop, I wanted to use a demo environment within an Oracle VirtualBox appliance, with the help of Vagrant.

I am going to use Linux, and at the time I started writing this series of articles, the general availability of Oracle Database 21c Express Edition (XE) on Linux was announced!
[https://blogs.oracle.com/database/post/oracle-database-21c-xe-generally-available]

In a series of articles, I will take you with me on my path to set everything up.

As I mentioned in my previous article, sometime, when you are writing a blog article, at the time the article is about to be published, the things you used and are writing about get changed during that time. This is what happened to me.
[Oracle Database 21c XE, setting up a demo environment using Vagrant and Oracle VirtualBox (part 3)]

First let me recap briefly on what I did so far. To build a Linux Docker image I used the Dockerfiles provided under https://github.com/oracle/docker-images. So, at the time I started writing this series of articles the most recent container image for XE was: Oracle Database 18c (18.4.0) Express Edition (XE). I used that one (article part 1) and later on I changed the existing 18.4.0 scripts so they would work for 21c. After fixing some problems, I came across (article part 2), I got it working and also about that time (article part 3) a more recent container image for XE came available. As I mentioned in that article, the README.md changed and now there is also support for 21c XE.
[https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/README.md]

I wanted to use the official 21c Docker image instead of the one I created myself.

So, in this article (part 4), I will share with you the steps I took, to set up a demo environment with Oracle Database 21c XE (21.3.0).

Using the newly available Oracle Database 21c Express Edition (XE) docker image

The README.md changed and now there is also support for 21c XE.

Next, I more or less repeated the steps, I described in a previous article (part 1), when I installed version 18.4.0.
[Oracle Database 21c XE, setting up a demo environment using Vagrant and Oracle VirtualBox (part 1)]

From https://github.com/oracle/docker-images, I downloaded the docker-images-main.zip from github. Next, I extracted directory OracleDatabase\SingleInstance\dockerfiles\21.3.0 to directory C:\My\AMIS\env\oraclexedatabase\dockerfiles\21.3.0 on my Windows laptop.

I also extracted file buildContainerImage.sh to directory C:\My\AMIS\env\oraclexedatabase\dockerfiles
[https://github.com/oracle/docker-images/blob/main/OracleDatabase/SingleInstance/dockerfiles/buildContainerImage.sh]

Remark about shared folder:

Mounting shared folders...
    ubuntu_docker: /vagrant => C:/My/AMIS/env

Remember, via the shared folder, the copied files are also available from within the Oracle VirtualBox appliance.

I could keep my Vagrantfile as it was:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/focal64"
  
  config.vm.define "ubuntu_docker" do |ubuntu_docker|
  
    config.vm.network "forwarded_port",
      guest: 1521,
      host:  1521,
      auto_correct: true
      
   config.vm.network "forwarded_port",
      guest: 5500,
      host:  5500,
      auto_correct: true
      
    config.vm.provider "virtualbox" do |vb|
        vb.name = "Ubuntu Docker"
        vb.memory = "8192"
        vb.cpus = "1"
      
      args = []
      config.vm.provision "docker shell script", type: "shell",
          path: "scripts/docker.sh",
          args: args
          
      args = []
      config.vm.provision "oracle-database-xe-21c shell script", type: "shell",
          path: "scripts/oracle-database-xe-21c.sh",
          args: args
          
    end
    
  end

end

Building and running Oracle Database container image for Oracle Database 21.3.0 XE

In order to build and run the new docker image file, I simply changed the content of file oracle-database-xe-21c.sh:
[in bold, I highlighted the changes]

#!/bin/bash
echo "**** Begin installing oracle-database-xe-21c"

#Install
#https://docs.oracle.com/en/database/oracle/oracle-database/21/xeinl/installing-oracle-database-xe.html

cd /vagrant/oraclexedatabase/dockerfiles
./buildContainerImage.sh -v 21.3.0 -x

sudo mkdir -p /opt/oracle/oradata
sudo chmod -R o+w /opt/oracle/oradata

docker run --name oracle_database_21.3.0-xe \
-p 1521:1521 -p 5500:5500 \
-e ORACLE_PWD=manager \
-e ORACLE_CHARACTERSET=AL32UTF8 \
-v /opt/oracle/oradata:/opt/oracle/oradata \
oracle/database:21.3.0-xe

echo "**** End installing oracle-database-xe-21c"

In order to test this new set up, I used vagrant destroy and vagrant up.

Remark:
There are some steps in the building image process that take a long time, it seems like the process is hanging, but you have to be patience. The whole process can take more than 5 minutes.

With the following output:

ubuntu_docker: **** Begin installing oracle-database-xe-21c
ubuntu_docker: WARNING: No swap limit support
ubuntu_docker: Checking Docker version.
ubuntu_docker: Ignored MD5 checksum
....
ubuntu_docker: Building image 'oracle/database:21.3.0-xe' ...
ubuntu_docker: Sending build context to Docker daemon  75.26kB
ubuntu_docker: Step 1/11 : FROM oraclelinux:7-slim
ubuntu_docker: 7-slim: Pulling from library/oraclelinux
ubuntu_docker: f09c1d3b7e7b: Pulling fs layer
ubuntu_docker: f09c1d3b7e7b: Verifying Checksum
ubuntu_docker: f09c1d3b7e7b: Download complete
ubuntu_docker: f09c1d3b7e7b: Pull complete
...
ubuntu_docker: Complete!
ubuntu_docker: Loaded plugins: ovl
...
ubuntu_docker: Transaction test succeeded
ubuntu_docker: Running transaction
  Installing : file-5.11-37.el7.x86_64                                      1/2
  Installing : oracle-database-xe-21c-1.0-1.x86_64                          2/2 [INFO]     ubuntu_docker: [INFO] Executing post installation scripts...
...

ubuntu_docker: Successfully built 3932f6652d47
ubuntu_docker: Successfully tagged oracle/database:21.3.0-xe
ubuntu_docker:
ubuntu_docker:
    ubuntu_docker:   Oracle Database container image for 'xe' version 21.3.0 is ready to be extended:
ubuntu_docker:
ubuntu_docker:     --> oracle/database:21.3.0-xe
ubuntu_docker:
ubuntu_docker:   Build completed in 771 seconds.
ubuntu_docker:
ubuntu_docker: Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:
ubuntu_docker: Confirm the password:
ubuntu_docker: Configuring Oracle Listener.
ubuntu_docker: Listener configuration succeeded.
ubuntu_docker: Configuring Oracle Database XE.
ubuntu_docker: Enter SYS user password:
ubuntu_docker: *******
ubuntu_docker: Enter SYSTEM user password:
ubuntu_docker: ********
ubuntu_docker: Enter PDBADMIN User Password:
ubuntu_docker: *******
ubuntu_docker: Prepare for db operation
ubuntu_docker: 7% complete
ubuntu_docker: Copying database files
ubuntu_docker: 29% complete
ubuntu_docker: Creating and starting Oracle instance
ubuntu_docker: 30% complete
ubuntu_docker: 33% complete
ubuntu_docker: 37% complete
ubuntu_docker: 40% complete
ubuntu_docker: 43% complete
ubuntu_docker: Completing Database Creation
ubuntu_docker: 47% complete
ubuntu_docker: 50% complete
ubuntu_docker: Creating Pluggable Databases
ubuntu_docker: 54% complete
ubuntu_docker: 71% complete
ubuntu_docker: Executing Post Configuration Actions
ubuntu_docker: 93% complete
ubuntu_docker: Running Custom Scripts
ubuntu_docker: 100% complete
ubuntu_docker: Database creation complete. For details check the logfiles at:
ubuntu_docker:  /opt/oracle/cfgtoollogs/dbca/XE.
ubuntu_docker: Database Information:
ubuntu_docker: Global Database Name:XE
ubuntu_docker: System Identifier(SID):XE
ubuntu_docker: Look at the log file "/opt/oracle/cfgtoollogs/dbca/XE/XE.log" for further details.
ubuntu_docker:
ubuntu_docker: Connect to Oracle Database using one of the connect strings:
ubuntu_docker:      Pluggable database: 6abbf2ad44d4/XEPDB1
ubuntu_docker:      Multitenant container database: 6abbf2ad44d4
ubuntu_docker: Use https://localhost:5500/em to access Oracle Enterprise Manager for Oracle Database XE
ubuntu_docker:
ubuntu_docker: SQL*Plus: Release 21.0.0.0.0 - Production on Sat Jan 1 18:34:03 2022
ubuntu_docker: Version 21.3.0.0.0
ubuntu_docker:
ubuntu_docker: Copyright (c) 1982, 2021, Oracle.  All rights reserved.
ubuntu_docker:
ubuntu_docker:
ubuntu_docker: Connected to:
ubuntu_docker: Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
ubuntu_docker: Version 21.3.0.0.0
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: System altered.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: System altered.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: Pluggable database altered.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: PL/SQL procedure successfully completed.
ubuntu_docker:
ubuntu_docker: SQL> SQL>
ubuntu_docker: Session altered.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: User created.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: Grant succeeded.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: Grant succeeded.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: Grant succeeded.
ubuntu_docker:
ubuntu_docker: SQL>
ubuntu_docker: User altered.
ubuntu_docker:
ubuntu_docker: SQL> SQL> Disconnected from Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
ubuntu_docker: Version 21.3.0.0.0
ubuntu_docker: The Oracle base remains unchanged with value /opt/oracle
ubuntu_docker: The Oracle base remains unchanged with value /opt/oracle
ubuntu_docker: #########################
ubuntu_docker: DATABASE IS READY TO USE!
ubuntu_docker: #########################
ubuntu_docker: The following output is now a tail of the alert.log:
ubuntu_docker: XEPDB1(3):Completed: ALTER DATABASE DEFAULT TABLESPACE "USERS"
ubuntu_docker: 2022-01-01T18:34:02.840786+00:00
ubuntu_docker: ALTER PLUGGABLE DATABASE XEPDB1 SAVE STATE
ubuntu_docker: Completed: ALTER PLUGGABLE DATABASE XEPDB1 SAVE STATE
ubuntu_docker: 2022-01-01T18:34:03.345775+00:00
ubuntu_docker: ALTER SYSTEM SET control_files='/opt/oracle/oradata/XE/control01.ctl' SCOPE=SPFILE;
ubuntu_docker: 2022-01-01T18:34:03.371015+00:00
ubuntu_docker: ALTER SYSTEM SET local_listener='' SCOPE=BOTH;
ubuntu_docker: ALTER PLUGGABLE DATABASE XEPDB1 SAVE STATE
ubuntu_docker: Completed: ALTER PLUGGABLE DATABASE XEPDB1 SAVE STATE

So, building the image and running it was successful.
Next, I closed the Windows Command Prompt.

Running SQL*Plus

I used vagrant ssh to connect into the running VM.

In order to get a list of all the docker images, I used the following command on the Linux Command Prompt:

docker image ls

With the following output:

REPOSITORY        TAG         IMAGE ID       CREATED          SIZE
oracle/database   21.3.0-xe   3932f6652d47   15 minutes ago   6.53GB
oraclelinux       7-slim      5ca608cbbc7a   4 weeks ago      132MB
hello-world       latest      feb5d9fea6a5   3 months ago     13.3kB

Next, I checked the list of all the docker containers:

docker container ls -a

With the following output:

CONTAINER ID   IMAGE                       COMMAND                  CREATED          STATUS                      PORTS                                                                                  NAMES
6abbf2ad44d4   oracle/database:21.3.0-xe   "/bin/sh -c 'exec $O…"   18 minutes ago   Up 18 minutes (healthy)     0.0.0.0:1521->1521/tcp, :::1521->1521/tcp, 0.0.0.0:5500->5500/tcp, :::5500->5500/tcp   oracle_database_21.3.0-xe
41ea57f79a1e   hello-world                 "/hello"                 31 minutes ago   Exited (0) 31 minutes ago                                                                                          charming_almeida

Then, in order to check the database via SQL*Plus, I used the following command on the Linux Command:

docker exec -ti oracle_database_21.3.0-xe sqlplus system/manager@//localhost:1521/XE

With the following output:

SQL*Plus: Release 21.0.0.0.0 – Production on Sat Jan 1 18:47:26 2022
Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle. All rights reserved.

Last Successful login time: Sat Jan 01 2022 18:34:47 +00:00

Connected to:
Oracle Database 21c Express Edition Release 21.0.0.0.0 – Production
Version 21.3.0.0.0

SQL>

I issued the following SQL command:

SQL> select count(*) from user_tables;

With the following output:

  COUNT(*)
----------
       134

Next, I used exit to close SQL*Plus.

With the following output:

Disconnected from Oracle Database 21c Express Edition Release 21.0.0.0.0 – Production
Version 21.3.0.0.0

So, the database was working and I could use SQL statements. Great!

With exit I closed the ssh Windows Command Prompt.

IntelliJ IDEA Community Edition and the Database Navigator

I also checked the created Oracle Database 21c Express Edition (XE) docker container by using IntelliJ IDEA Community Edition and the Database Navigator on my Windows laptop.

I navigated to connection “OracleXE_system_Connection”.

Next, I navigated to Schemas | SYSTEM.

And as you can see, the number of tables for this user is 134, the same as the counting result when I used SQL*Plus as I described before.

In the next part of this series of articles the focus is on installing Apache Kafka.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Next Post

Did I really just commit and push a file with a password in it?–Remove all traces of pushed Git commit

Surely I would never be so stupid as to commit a file that contains sensitive information – say my Oracle Cloud account’s private key. And even if I did, I would not push that change to a public git repo on GitHub, would I? It turns out that I did […]
%d bloggers like this: