Oracle has released Docker build files for the Oracle Database on Github. With those build files one can go ahead and build his or her own Docker image for the Oracle Database. If you don’t know what Docker is you should go and check it out. It’s a cool technology based on the Linux containers technology that allows you to containerize your application, whatever that application may be. Naturally, it didn’t take long for people to start looking at containerizing databases as well which makes a lot of sense, especially for, but not only, development and test environments. Here is a detailed blog post on how to containerize your Oracle Database by using those build files that Oracle has provided.
What you need
- The Oracle install zip files, you can download them from Oracle Technology Network
- The build files from Github, you can download or clone the repository
My environment is as follows:
- Oracle Linux 7.3 (4.1.12-94.3.8.el7uek.x86_64)
- Docker 17.03.1-ce (docker-engine.x86_64 17.03.1.ce-3.0.1.el7)
- Oracle Database 12.2.0.1 Enterprise Edition
The first thing, if not already done so, is to setup Docker on the environment. Luckily this is fairly straight forward. Docker is shipped as an addon with Oracle Linux 7 UEK4. As I’m running on such environment all I have to do is to is to enable the addons
yum repository and install the docker-engine
package. Note, this is done as the root
Linux user:
Enable OL7 addons repo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
Install docker-engine
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
And that’s it! Docker is now installed on the machine. Before I proceed with building an image I first have to configure my environment appropriately.
Enable non-root user
The first thing I want to do is to enable a non-root user to communicate with the Docker engine. Enabling a non-root user is fairly straight forward as well. When Docker was installed a new Unix group docker
was created along with it. If you want to allow a user to communicate with the Docker daemon directly, hence avoiding to run as the root
user, all you have to do is to add that user to the docker
group. In my case I want to add the oracle
user to that group:
1 2 3 4 5 | |
Increase base image size
Before I go ahead and run the image build I want to double check one important parameter: The default base image size for the Docker container. In the past Docker came with a maximum container size of 10 GB by default. While this is more than enough for running some applications inside Docker containers this needed to be increased for Oracle Database. The Oracle Database 12.2.0.1 image requires about 13GB of space for the image build.
Recently the default size has been increased to 25GB which will be more than enough for the Oracle Database image. The setting can be found and double checked in /etc/sysconfig/docker-storage
as the storage-opt dm.basesize
parameter:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Start and enable the Docker service
The final step is to start the docker
service and configure it to start at boot time. This is done via the systemctl
command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
As a last step you can verify the setup and the base image size (check for Base Device Size:
) via docker info
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
That concludes the installation of Docker itself.
Building the Oracle Database Docker imageNow that Docker is up and running I can start building the image. First I need to get the Docker build files and the Oracle install binaries, both are easy to obtain as shown below. Note that I use the oracle
Linux user for all the following steps, which I have enabled previously to communicate with the Docker daemon:
Obtaining the required files
Github build files
First I have to download the Docker build files. There are various ways to do this. I can for example clone the Git repository directly. But for simplicity and for the people who aren’t familiar with git I will just use the download option on Github itself. If you go to the main repository URL https://github.com/oracle/docker-images/ you will see a green button saying “Clone or download
” and by clicking on it you will have the option “Download ZIP
“. Alternatively you can also just download the repository directly via the static URL: https://github.com/oracle/docker-images/archive/master.zip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
Oracle installation binaries
For the Oracle binaries just download them from where you usually would download them. Oracle Technology Network is probably the place that most people go to. Once you have downloaded them you can proceed with building the image:
1 2 | |
Building the image
Now that I have all the files it’s time to build the Docker image. You will find a separate README.md in the docker-images-master/OracleDatabase/SingleInstance
directory which explains the build process in more details. Make sure that you always read that file as it will always reflect the latest changes in the build files! You will also find a buildDockerImage.sh
shell script in the docker-images-master/OracleDatabase/SingleInstance/dockerfiles
directory that does the legwork of the build for you. For the build it is essential that I copy the install files into the correct version directory. As I’m going to create an Oracle Database 12.2.0.1 image I need to copy the install zip file into docker-images-master/OracleDatabase/SingleInstance/dockerfiles/12.2.0.1
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
Now that the zip file is in place I am ready to invoke the buildDockerImage.sh
shell script in the dockerfiles
folder. The script takes a couple of parameters, -v
for the version and -e
for telling it that I want Enterprise Edition. Note: The build of the image will pull the Oracle Linux slim base image and execute a yum install
as well as a yum upgrade
inside the container. For it to success to have to have internet connectivity:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
Starting and connecting to the Oracle Database inside a Docker container
Once the build was successful I can now start and run the Oracle Database inside a Docker container. All I have to do is to issue the docker run
command and pass in the appropriate parameters. One important parameter is the -p
for the mapping of ports inside the container to the outside world. This is required so that I can also connect to the database from outside the Docker container. Another important parameter is the -v
parameter which allows me to keep the data files of the database in a location outside the Docker container. This is important as it will allow me to preserve my data even when the container is thrown away. You should always use the -v
parameter or create a named Docker volume! The last useful parameter that I’m going to use is the --name
parameter which specifies the name of the Docker container itself. If omitted a random name will be generated. However, passing on a name will allow me to refer to the container via that name later on:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
On the very first startup of the container a new database is being created. Subsequent startups of the same container or newly created containers pointing to the same volume will just start up the database again. Once the database is created and or started the container will run a tail -f
on the Oracle Database alert.log file. This is done for convenience so that issuing a docker logs
command will actually print the logs of the database running inside that container. Once the database is created or started up you will see the line DATABASE IS READY TO USE!
in the output. After that you can connect to the database.
Resetting the database admin accounts passwords
The startup script also generated a password for the database admin accounts. You can find the password next to the line ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN:
in the output. You can either use that password going forward or you can reset it to a password of your choice. The container provides a script called setPassword.sh
for resetting the password. In a new shell just execute following command against the running container:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Connecting to the Oracle Database
Now that the container is running and the port 1521 mapped to the outside world I can connect to the database inside the container:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Stopping the Oracle Database Docker container
If you wish to stop the Docker container you can just do so via the docker stop
command. All you will have to do is to issue the command and pass on the container name or id. This will trigger the container to issue a shutdown immediate
for the database inside the container. By default Docker will only allow 10 seconds for the container to shutdown before killing it. For applications that may be fine but for persistent containers such as the Oracle Database container you may want to give the container a bit more time to shutdown the database appropriately. You can do that via the -t
option that allows you to pass on a new timeout in seconds for the container to shutdown successfully. I will give the database 30 seconds to shutdown but it’s important to point out that it doesn’t really matter how long you give the container to shutdown. Once the database is shutdown the container will exit normal. It will not wait all the seconds that you have specified until returning control. So even if you give it 10 minutes (600 seconds) it will still return as soon as the database is shutdown. Just keep that in mind when specifying a timeout for busy database containers:
1 2 | |
Restarting the Oracle Database Docker container
A stopped container can always be restarted via the docker start
command:
1 2 | |
The docker start
command will put the container into background and return control immediately. You can check the status of the container via the docker logs
command which should print the same DATABASE IS READY TO USE!
line. You will also see that this time the database was just restarted rather than created. Note, a docker logs -f
will follow the log output, i.e. keep on printing new lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Now that the database is up and running again I can connect once more to the database inside:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Summary
This concludes how to containerize the Oracle Database using Docker. Note that Oracle has also provided build files for other Oracle Database versions and editions. The steps described above are largely the same but you should always refer to the README.md that comes with the build files. In there you will also find more options for how to run your Oracle Database containers.