For later creation of containers as needed in the deployment process we have first to build docker images whenever we do not find suitable one in docker hub.
For most of my development I need a oracle database. On the internet you can find a lot of Dockerfile’s for this, but no ready image. This is because for running a database you have to accept a license and this happens when you download the installation software. For private testing this license often is free.
The basic cycle for all of this images is the same on my side:
- Find a Docker image
- If not found download required Software and build a Docker image
- Build the Docker image
- Push the images to private docker registry or the public registry DockerHub
Following you find an example for building Oracle XE 22.214.171.124 Image.
First you have to clone the git repository to a directory of you choice, I choose C:\shared\scmlocal\docker-images.
Put the downloaded installation source oracle-xe-11.2.0-1.0.x86_64.rpm.zip in the subdirectory C:\shared\scmlocal\docker-images\OracleDatabase\dockerfiles\126.96.36.199 as described in GitHub.
Next we have to map this directory to our virtualbox via following vagrant instructions. Additional we prepare port forwarding for accessing later the database from our host system.
... # Port Forwardings for: # - Oracle database port config.vm.network "forwarded_port", guest: 1521, host: 1521 # Oracle Application Express (APEX) config.vm.network "forwarded_port", guest: 8080, host: 8080 ... # map Oracle Docker Images installation path config.vm.synced_folder "C:\\shared\\scmlocal\\docker-images", "/docker-images", :mount_options => ["dmode=777","fmode=777"] ...
After that restart the virtualbox and connect to it via
vagrant halt vagrant up vagrant ssh
In the output you can see this mapping.
... default: 1521 (guest) => 1521 (host) (adapter 1) default: 5000 (guest) => 5000 (host) (adapter 1) default: 8080 (guest) => 8080 (host) (adapter 1) ... default: /docker-images => C:/shared/scmlocal/docker-images ...
Now you create build the image with the Oracle XE (-x) database version (-v) 188.8.131.52 via the provided scripts from oracle. -i skips the MD5 checksum check, as the checksums are not checked in as UNIX text format and so does not work in our vagrant on windows / oel virtualbox combination.
cd /docker-images/OracleDatabase/dockerfiles ./buildDockerImage.sh -v 184.108.40.206 -x -i
Now you have to wait some time. When the process is ready, you get at the time of this writing an image with the binaries installed.
docker images REPOSITORY TAG IMAGE ID CREATED SIZE oracle/database 220.127.116.11-xe 624d78c89ccb About a minute ago 1.203 GB registry latest c6c14b3960bd 5 weeks ago 33.28 MB oraclelinux latest 1988eb5b3fc6 6 weeks ago 278.2 MB
Next we tag this image for pushing to the local docker repository, which we have created in the first blog of this series and is up with every vagrant up of our virtualbox. After that we push it to the registry.
docker tag oracle/database:18.104.22.168-xe localhost:5000/oracle/database:22.214.171.124-xe docker push localhost:5000/oracle/database:126.96.36.199-xe
In the output we see the succesful push.
The push refers to a repository [localhost:5000/oracle/database] 345dfbce8859: Pushed dd4b46d40894: Pushed 11327e04fac0: Pushed 188.8.131.52-xe: digest: sha256:82058ca2c5c201ff46471a8db4d9569da9869d420727595884050f94dad0ec85 size: 955
Now we will check, if we can create a Docker container from our image in the registry and the database is working in it. Therefore at first we delete the oracle/database and oraclelinux images from our virtualbox. Then we create the container.
docker rmi 624d78c89ccb -f docker rmi 1988eb5b3fc6 sudo docker run --shm-size=1g -p 1521:1521 -p 8080:8080 --name="db184.108.40.206-xe" --restart unless-stopped localhost:5000/oracle/database:220.127.116.11-xe
In line 3 we pull the image from the local registry, start a container, open the ports 1521 and 8080 to the virtualbox and give the container a name.
Unable to find image 'localhost:5000/oracle/database:18.104.22.168-xe' locally 22.214.171.124-xe: Pulling from oracle/database 10ec637c060c: Pull complete 1902f66bc90b: Pull complete dd8942200fe1: Pull complete Digest: sha256:41ce1015c8f68ce063e855e7afa96000ededeef1e197e2181bc04c9577d73a1b Status: Downloaded newer image for localhost:5000/oracle/database:126.96.36.199-xe ORACLE AUTO GENERATED PASSWORD FOR SYS AND SYSTEM: 9f4e9a733e7983bc Oracle Database 11g Express Edition Configuration ------------------------------------------------- This will configure on-boot properties of Oracle Database 11g Express Edition. The following questions will determine whether the database should be starting upon system boot, the ports it will use, and the passwords that will be used for database accounts. Press <Enter> to accept the defaults. Ctrl-C will abort. Specify the HTTP port that will be used for Oracle Application Express : Specify a port that will be used for the database listener : Specify a password to be used for database accounts. Note that the same password will be used for SYS and SYSTEM. Oracle recommends the use of different passwords for each database account. This can be done after initial configuration: Confirm the password: Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]: Starting Oracle Net Listener...Done Configuring database...Done Starting Oracle Database 11g Express Edition instance...Done Installation completed successfully. SQL*Plus: Release 188.8.131.52.0 Production on Tue Sep 6 09:41:22 2016 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 184.108.40.206.0 - 64bit Production SQL> PL/SQL procedure successfully completed. SQL> Disconnected from Oracle Database 11g Express Edition Release 220.127.116.11.0 - 64bit Production ######################### DATABASE IS READY TO USE! ######################### db_recovery_file_dest_size of 10240 MB is 0.98% used. This is a user-specified limit on the amount of space that will be used by this database for recovery-related files, and does not reflect the amount of space available in the underlying filesystem or ASM diskgroup. Starting background process CJQ0 Tue Sep 06 09:41:19 2016 CJQ0 started with pid=26, OS id=759 Tue Sep 06 09:41:24 2016 XDB installed. XDB initialized.
In line 9 you can see the autogenerated passwords.
When line 46 appears, you can connect to the database.
With following command you can change the passwords of SYS and SYSTEM:
sudo docker exec db18.104.22.168-xe /u01/app/oracle/setPassword.sh LetsDocker
You see following output:
SQL*Plus: Release 22.214.171.124.0 Production on Tue Sep 6 15:49:34 2016 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Express Edition Release 126.96.36.199.0 - 64bit Production SQL> User altered. SQL> User altered.
As long as you not remove or manually stop the container, it restarts with the virtualbox now via:
vagrant halt vagrant up
At the moment you cannot make your database instance data persistent for this container, I have opened an issue for this, but Gerald Venzl has promised to to implement this later.
Here you find the source code for this blog.
Here you find more about the topic “Virtual Development Server”.