Follow these instructions to set up the Oracle database to run in Docker, but the app itself in your native environment.
- Install Docker for Mac by running
brew cask install docker
- Sign up for a Docker Hub account at https://hub.docker.com/. If you already have a Docker Hub account, you can skip this step and use your existing account.
- Go to https://store.docker.com/images/oracle-database-enterprise-edition and click the button Proceed to Checkout. Complete and submit the form in order to get access to the free container that Oracle provides.
- In your terminal, make sure that you are logged in with your Docker Hub credentials by running
docker login
.
# Run the Oracle image as a container named oracle, storing data
# in the directory oracle/, which is ignored in git.
# When you run this for the first time, it will take a while to download
# the image and initialize the database.
#
# When the output in the terminal includes a line like:
#
# Done ! The database is ready for use .
#
# you can use the database
docker run \
--interactive \
--name oracle \
--publish 1521:1521 \
--tty \
--volume oracle:/ORCL \
store/oracle/database-enterprise:12.2.0.1
When you no longer need the database, in another terminal tab run:
docker stop oracle
The next time you need the database, start it just by running:
docker start --interactive oracle
- Enable the homebrew tap for Oracle Instant Client by running
brew tap InstantClientTap/instantclient
. - Run each of these commands, following the displayed instructions for how to download the appropriate .zip files from Oracle’s website. After you download the files and place them in Homebrew’s cache directory, brew will take care of the rest:
brew install instantclient-basic brew install instantclient-sqlplus brew install instantclient-sdk
- Add to
~/.profile
(bash) or~/.zprofile
(zsh)
# The Oracle adapter for ActiveRecord uses this password to connect as a
# system user, to be able to create and drop databases appropriately.
export ORACLE_SYSTEM_PASSWORD=Oradoc_db1
# This is used to specify the default language and encoding for Oracle clients
export NLS_LANG="AMERICAN_AMERICA.UTF8"
source ~/.profile
orsource ~/.zprofile
, to load the changes you just made
To connect to the Oracle server, run:
sqlplus "sys/Oradoc_db1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCLCDB.localdomain)))" as sysdba
Your output should show something like this:
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
SQL>
- Make sure you have the
activerecord-oracle_enhanced-adapter
andruby-oci8
gems enabled in yourGemfile
. - Copy the Oracle template for
database.yml
by runningcp config/database.yml.oracle.template config/database.yml
. - Run
bundle exec rake db:setup
. - Optionally, run
bundle exec rake demo:seed
if you want to populate the database with demo data.
-
Download from:
http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html
-
Install into
/Applications
-
Run
bundle exec rake db:drop db:create
. This will ensure that your database exists, and that it is empty. Without this step, the import may skip tables which already exist, and it may fail if the database does not exist. -
Copy the
.dmp
file tooracle/u01/app/oracle/admin/ORCL/dpdump/
(assuming you are usingoracle/
as the data directory, per above), so it is located in the server’s default data pump directory. -
Start a bash shell in the
oracle
container:docker exec \ --interactive \ --tty \ oracle \ bash
-
Run the following command to ensure that the file you copied is available in the
DATA_PUMP_LOCATION
configured on the server:ln -fsn /ORCL/u01/app/oracle/admin /u01/app/oracle/admin
This only needs to be done once, but if you’re having trouble, rerun it.
- Import the dump, replacing DUMPFILE with the name of your dump file, and REMAP_SCHEMA with your database’s username if necessary:
impdp \
system/Oradoc_db1 \
DIRECTORY=DATA_PUMP_DIR \
DUMPFILE=expdp_schema_COR1PRD_201810021913.dmp \
REMAP_SCHEMA=bc_nucore:nucore_open_development