Skip to content

Instantly share code, notes, and snippets.

@kekru
Last active October 21, 2023 17:19
Show Gist options
  • Save kekru/b19cbf521e0aba9b539cb1677cb9a797 to your computer and use it in GitHub Desktop.
Save kekru/b19cbf521e0aba9b539cb1677cb9a797 to your computer and use it in GitHub Desktop.
Run Oracle XE DB on localhost via Virtual Machine, Vagrant, Docker

This is how to easily setup an Oracle XE DB in a Virtual Machine that is accessible via localhost:1521. So you don't have to install Oracle XE locally, but inside a VM.
We use VirtualBox, Vagrant and Docker for that.

First install VirtualBox https://www.virtualbox.org/wiki/Downloads
and Vagrant https://www.vagrantup.com/downloads.html

Run vagrant version to check that vagrant is correctly installed.

Save the Vagrantfile from this gist to a local directory.
Go inside the directory and run vagrant up. The first startup will take a few minutes to download everything.
Then you have a ready to use Oracle XE DB on localhost:1521 :)

Your connection settings are

hostname: localhost
port: 1521
sid: xe
username: system
password: system

and default timezone is Europe/Berlin.

To change these defaults you have to edit the line starting with inline: "docker run -d in the Vagrantfile.
See https://github.com/kekru/docker-oracle-xe-11g-extra-tablespace for more information.

Stop Oracle VM

To STOP, but not delete the VM run vagrant suspend.
To DELETE the VM run vagrant destroy.

Restart VM

Restart the VM with vagrant up

Reload VM

To reload/reprovision the Oracle comment in the lines

#config.vm.provision "shell",
#  inline: "sh -c 'docker stop $(docker ps -aq) && docker rm $(docker ps -aq) && docker rmi myapp ; true'"

in the Vagrantfile and run vagrant provision or vagrant up --provision.

This will DESTROY YOUR DATABASE DATA.

Work with Oracle on terminal

Run vagrant ssh to login to your VM.
On Windows you might have to put ssh.exe to your %PATH%. If you have installed git, you can use C:\Program Files\Git\usr\bin
You can also login via Putty on host: "localhost", Port "2222", login: "vagrant", password: "vagrant".

Now run docker exec -it oracledb /bin/bash to get into the Docker Container where the Oracle DB is installed.
See https://github.com/kekru/docker-oracle-xe-11g-extra-tablespace for more information.

Vagrant.configure(2) do |config|
#The Virtual Machine runs with Ubuntu 14.04 (Trusty Tahr) 64 Bit
config.vm.box = "ubuntu/trusty64"
#Wait max 10 minutes (600 seconds) to start VM without provisioning
config.vm.boot_timeout = 600
#VM internal ports (guest) are conencted to host's ports (host)
config.vm.network :forwarded_port, guest: 1521, host: 1521
#1GB RAM for VM
config.vm.provider :virtualbox do |p|
p.customize ["modifyvm", :id, "--memory", 1024]
end
#Include this to delete Oracle on provisioning
#config.vm.provision "shell",
# inline: "sh -c 'docker stop $(docker ps -aq) && docker rm $(docker ps -aq) && docker rmi myapp ; true'"
#Install Docker
config.vm.provision "docker" do |d|
end
#Run Oracle XE DB in Docker Container
config.vm.provision "shell",
inline: "docker run -d --name oracledb -p 1521:1521 -e syspasswd=system -e ORACLE_ALLOW_REMOTE=true -e timezone=Europe/Berlin -v /vagrant/orabackup:/data/backup whiledo/oracle-xe-11g-extra-tablespace"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment