In this video, we'll look at how to set up an Oracle database using Docker.
Let's get started.
Here are the high level steps we need to do.
First, we download the Docker application.
Next, we set up an account on Docker Hub.
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.
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. These images are available on a website called Docker Hub.
There are a whole range of images there, but the one we're looking for is for Oracle Database.
So, we'll need to visit the Docker Hub website, set up an account,
find the right image, and then start using it. Let's see how we can do that.
First, visit the Docker Hub website at hub.docker.com.
You'll need an account to access the Docker images, so click on the Sign Up button.
Enter your details on the Sign Up page.
Remember the password you enter here as you'll need it later.
The next page is the Choose Your Plan page. There are a couple of options,
but for now you can select the Free plan. This is enough for our purposes.
Follow the steps to verify your email address. You now have an account on Docker Hub.
Now we've logged in to Docker Hub, it's time to find the image for the Oracle database.
We're going to get the URL for the image,
and then use this URL as part of a command we'll run on the command line.
To find the image, enter the term "oracle database" into the search bar at the top
of the page. We enter this because there are a range of Oracle images,
like WebLogic and Fusion Middleware, and we only want the database.
Click on the Oracle Database Enterprise Edition, and you'll be taken to this page.
At the moment, the only database version here is 12c.
It's an old version, but I understand Oracle is working on making more recent versions available
as Docker images for the developer community.
In order to use the image, we need to accept the terms and conditions of the license.
Click Proceed to Checkout, accept the terms, and select Get Content.
You'll be presented with a screen that shows a command, in the black box on the right.
It says "Copy and paste to pull this image". It then shows a command of "docker pull" then a URL.
We'll use this to download the image shortly.
Before we do this, we need to open a command line or terminal. 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 getting our Docker image.
We're going to do three things: log in, then download the image, then run it.
We need to log in to the Docker Hub account first. This is done using the docker login command.
Enter "docker login" at the command line and press enter. You'll be asked to enter
your username and password, which is what you provided when you created the Docker Hub account.
Now we have logged in, we can download the image. This is done using the "docker pull" command,
which is the command in the black box we saw on the Docker Hub page.
So, copy the command from that page, and paste it here in the terminal window.
Before you run the command, there is another option.
This will download the full 12c version of Oracle. There's also another version,
called the Slim version. It has a reduced file size and faster startup time,
but does not come with some Oracle features such as Application Express and Analytics. If you only
want the database, you can use the Slim version. If you want everything, use the normal version.
To use this Slim version, which is what I'll use, add the word "-slim" to the end of the image name,
without adding a space to the end. It should look like this.
Then, press Enter to run the command.
The image will start downloading. It's a few gigabytes so may take some time.
If you get this error about "pull access denied",
then you'll have to log in to your Docker Hub account and accept the
agreement for the Oracle Database. This was demonstrated a little earlier in the video.
Once the image is downloaded, we can run it. We can run another command called "docker run".
Here's the command to use.
We type docker run. The "-d" stands for detached, which means it runs in the background. The "-p"
stands for port, which is the port that is used for connecting to the container.
We specify 1521 then : then 1521,
which is the port to use. This means that port 1521 is available for us to connect.
We specify "—name" to give a name to our container, which is the word "oracle".
We then specify the path to the image, which is the one we just downloaded.
This command says "assign this image to the name oracle and run it".
Once you run the command, the image will start up. This can take a minute or two.
If you get an error about the name already being used, then it's likely because you have run this
command in the past and the container name of "oracle" is already created.
If so, you can start the existing container. To do this, type "docker start oracle".
After a moment, the image will start 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 "starting" to indicate the container
is starting up. Run the docker ps command again in a minute or two and you should see
"healthy". 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 image page on Docker Hub for the Oracle Database,
and we'll enter them here.
For the host, enter localhost.
For the SID, enter ORCLCDB. This is the container database.
For the user, enter SYS.
For the password, enter Oradoc_db1
Select AS SYSDBA.
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.
If you want to connect to the pluggable database,
you can enter different information into this connection window.
The difference is that you should select Service Name instead of SID,
and enter a Service Name value of "ORCLPDB1.localdomain"
Pluggable and Container databases are a complex topic, in my opinion,
and I'll create another video to explain them in more detail.
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 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", where oracle 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.
That brings us to the end of this tutorial. I'll create some other
videos to cover things like persisting data and automatically running scripts.
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.