In this video, we'll look at how to set up an Oracle database using Docker.
However, we’ll be getting the Docker image from Oracle’s official registry,
rather than Docker Hub. I’ll explain why in this video.
Let's get started.
Here are the high-level steps we need to do.
First, we download the Docker application.
Then, we login to the Oracle container registry and accept the license agreement.
Then, we run Docker and download the Oracle image.
Then, we run the Oracle image.
Finally, we connect to the database and run some SQL.
This video is demonstrated on a Mac but should work in a similar way on Windows.
Also, if you’re running an M1 Mac, which is any of the Macs released in the last couple of years,
then unfortunately this process won’t work. You can install Docker and the image,
but you’ll get errors connecting. This is because the image created by Oracle is not supported on
these M1 CPUs, but they have said they’re working on this and should have something later this year.
If you’re on an M1 Mac, I’ve got a video here on how to set up a free Oracle Cloud database,
which works on M1 Mac. The database is on the cloud, which is why it works,
but it’s the easiest way that I know of to use an Oracle database on the M1 Mac.
To get started, we need to download the Docker application.
This is freely available from the Docker website, at www.docker.com.
Once the website has loaded, click on Get Started.
On the Get Started page, there are several options. Click on Docker Desktop. The other
two options, Docker Hub and Play with Docker, are not needed for our process.
Select the right version for your computer,
which is either of the two Mac versions or a Windows version.
The Docker setup file will then begin downloading.
It's about 580 MB which could take a few minutes to download.
Once the download is complete, install it. This can be done by opening the file on MacOs
and dragging it to the Applications folder, or following the installation steps on Windows.
It takes a couple of minutes to install.
Once it is installed, you can run it. This will cause the Docker service to start.
I believe you can also run it from the command line or from elsewhere in Mac,
but this is the approach that has worked for me and will hopefully work for you.
Now we've got Docker running, it's time to get our database files.
The files that Docker uses to run applications are called images, which are a pre-built
collection of files. Normally, these images are available on a website called Docker Hub.
However, Oracle has recently removed their image from Docker Hub and has added it to
their own container registry. Let’s look at how we can get the image from there.
Go to the container registry URL, which is container-registry.oracle.com. If you enter
this into the URL bar, it will get translated to this one with a bunch of characters at the end.
On this page, click on Database on the right here.
On this Database page, you can select one of many services that Oracle offers.
For this example, we’ll use the Standard database, so click on the standard link here.
The next page shows the details of the image, including the limitations,
connection details, and commands.
In order to use the image, we need to accept the license agreement. And to do this,
we need to login using our Oracle account. You can create an account if you don’t have one.
Click the Sign In button on this section on the right. If you have an account,
enter your username and password. If not, you can create one using the Create Account at the bottom.
Once you log in, you’ll see the information section on the right
updated. Select your language from the list, and click Continue.
A popup appears with the license agreement. Read it and scroll to the bottom and click Accept.
The main page will reload and will display that the agreement is accepted.
So, we’re now ready to download and run the image. We’ll do this in three steps.
First, we create a file called an “environment file” that stores our connection settings.
Second, we’ll open a command line and log in to the container registry.
Finally, we’ll run the docker run command that uses this file to download the image.
For the first step, there’s an example of the environment file on this page here.
We can copy all of this, and paste it into a new file in a text editor.
I’m using Atom, but you can use TextEdit or Notepad or anything else.
Now, we don’t need to change anything in this file. We can just save it how it is.
So, save the file. I’ll save this file in the Documents folder, and call it ora_db_env.dat.
The second step is to log in to the Oracle container registry using the command line.
Let’s open a terminal or command line. I'll open the Terminal app as I'm on a Mac,
but I believe the Command Line on Windows will work in the same way.
Once the Terminal app is open, we can start the process of logging in. If we don’t log in,
and try to use docker pull or docker run, we’ll get an error message of “head unauthorised
authentication required”. So, we’ll login first, which means we won’t get this message.
At the terminal, enter docker login container-registry.oracle.com.
You’ll be asked for a username, then a password. These are the login details for your Oracle
account, the same one you used to log in on the website and accept the license agreement.
Enter your username, press Enter, then your password and press Enter.
You should then see Login Succeeded.
So, that’s step 2 done. The third step is to download and run the image.
We can do this using the “docker pull” command,
which is shown on the right of the Image page on the container website.
Copy this command into the Terminal and press Enter to run it. The container image will start
downloading. It’s a few gigabytes so may take some time depending on your download speeds.
Once it is complete, we can run the image, which will then let us connect to the Oracle database.
Once the image is downloaded, we can run it. We can run another command called "docker run".
Here's the command to use. I’ll put this in the video description
so you can copy and paste it and make adjustments.
There are a few things to notice in this command and one thing to change.
docker run will run the container. The -d runs it in detached mode,
meaning you can use the terminal while the container is running.
The two dashes then env file specifies the path to the environment file we created earlier.
This is the path relative to where you are currently in the Terminal.
In my Terminal, I’m currently in the BB folder. The environment file I created was saved in the
Users/BB/Documents folder, so this path refers to Documents and then the environment file.
After that, we have a -p then the port number to share between the
container and our main operating system outside of the container.
The two dashes then name will give a name to the container, which I’ve called oracle-std.
The shm-size is for the shared memory size and we need at least 4 GB for this container,
as mentioned on the Oracle web page. I’ve used the value that was mentioned
on that example page of 8g or 8 GB. Finally, we have the container to run,
which is the same as the one we pulled from the Oracle container registry.
We can run this command in our terminal. If it’s successful,
you’ll get a long alphanumeric string here which is an ID number.
If you get an error, I would suggest checking that you have the right single dash or double dash in
the right places, as I’ve gotten this wrong before, or the double dash has been converted
to a long em dash. You can also Google the error which is what I did several times setting this up.
To check the status of your containers, you can run the command "docker ps".
This shows a list of all images that are running.
In the status column, you'll see something like
“up 1 minute". This means the container is running.
Awesome! We now have a Docker container running with our Oracle database.
Let's connect to it and run some SQL.
We'll use SQL Developer to connect, which is Oracle's freely available IDE, but you
can use whatever IDE you want. I've got separate videos on how to download and use SQL Developer.
For now, I'll assume you have SQL Developer set up, so open SQL Developer now.
Click Create a new connection and you'll see this window here.
The connection details are available on the page on the Oracle container registry that we saw,
and are also in the environment file we created, and we'll enter them here.
For the user, enter SYS.
Select AS SYSDBA.
For the password, enter MyPasswd123 from the file.
For the host, enter my.domain.com.
For the SID, enter OraDoc.
Click Test Connection, and it should be successful. If you get an error, take a look
at the description and comments below this video where I'll list some common causes and solutions.
Click Save and you'll then be connected to the database and see a new SQL Editor window.
Enter a simple query, such as SELECT SYSDATE FROM dual, and run it.
You'll see the output on the screen.
This is the result of the query on the Oracle Database inside the container.
Congratulations! You've successfully set up an Oracle database inside a Docker container,
using the Oracle container registry, and connected to it!
If you have any errors, let me know in the comments below.
I'll put some resources in the Description for some common issues as well.
To stop the database, you can run the Docker Stop command. Go back to the terminal,
and enter "docker stop oracle-std", where oracle-std is the name of your container.
This will stop the container and the Oracle database.
To start it again, use the docker run command we saw earlier.
If you want to learn more about using SQL Developer, check out my tutorial here on
SQL Developer where I go into more detail on connections and the features of the IDE.
If you want to set up an Oracle database on Oracle’s free cloud service, check out this video.
If you learned something new from this video, make sure to subscribe to my channel.
If you want to learn more about database design and development,
visit databasestar.com. That’s where I share my best database-related content.
Which part of this Docker tutorial was the most helpful for you? Was it the command to actually
run the container? Or the steps to connect to the database using your IDE? Or something else?
Thanks for watching.