Hi everyone, in a very short post I’ll show how to bring up Oracle in a Docker container.
Following the DevOps wave, this week I’m taking a course and getting to know some tools, and Docker is one of them.
So far I haven’t found a use for it in the database world, but I still know too little to have an opinion about it.
What the article is about:
This article shows how to use a ready-made Oracle Database 11g XE image and run it in Docker.
When the topic is useful:
This feature is useful for learning the technology in Docker. Consider this article an introduction to the technology in question; I won’t give an opinion on it or recommend its use.

Installing Docker
The first step is to install Docker in your environment. In my case I’m using Ubuntu 16.04:
root@devops:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
To install Docker, run:
root@devops:~# apt install docker.io
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
bridge-utils cgroupfs-mount containerd runc ubuntu-fan
Suggested packages:
mountall aufs-tools debootstrap docker-doc rinse zfs-fuse | zfsutils
The following NEW packages will be installed:
bridge-utils cgroupfs-mount containerd docker.io runc ubuntu-fan
0 upgraded, 6 newly installed, 0 to remove and 133 not upgraded.
Need to get 16.4 MB of archives.
After this operation, 83.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 bridge-utils amd64 1.5-9ubuntu1 [28.6 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial/universe amd64 cgroupfs-mount all 1.2 [4,970 B]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 runc amd64 1.0.0~rc2+docker1.12.6-0ubuntu1~16.04.1 [1,479 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 containerd amd64 0.2.5-0ubuntu1~16.04.1 [4,041 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 docker.io amd64 1.12.6-0ubuntu1~16.04.1 [10.8 MB]
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 ubuntu-fan all 0.9.2 [30.7 kB]
Fetched 16.4 MB in 1min 6s (247 kB/s)
Selecting previously unselected package bridge-utils.
(Reading database ... 65486 files and directories currently installed.)
Preparing to unpack .../bridge-utils_1.5-9ubuntu1_amd64.deb ...
Unpacking bridge-utils (1.5-9ubuntu1) ...
Selecting previously unselected package cgroupfs-mount.
Preparing to unpack .../cgroupfs-mount_1.2_all.deb ...
Unpacking cgroupfs-mount (1.2) ...
Selecting previously unselected package runc.
Preparing to unpack .../runc_1.0.0~rc2+docker1.12.6-0ubuntu1~16.04.1_amd64.deb ...
Unpacking runc (1.0.0~rc2+docker1.12.6-0ubuntu1~16.04.1) ...
Selecting previously unselected package containerd.
Preparing to unpack .../containerd_0.2.5-0ubuntu1~16.04.1_amd64.deb ...
Unpacking containerd (0.2.5-0ubuntu1~16.04.1) ...
Selecting previously unselected package docker.io.
Preparing to unpack .../docker.io_1.12.6-0ubuntu1~16.04.1_amd64.deb ...
Unpacking docker.io (1.12.6-0ubuntu1~16.04.1) ...
Selecting previously unselected package ubuntu-fan.
Preparing to unpack .../ubuntu-fan_0.9.2_all.deb ...
Unpacking ubuntu-fan (0.9.2) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu16) ...
Setting up bridge-utils (1.5-9ubuntu1) ...
Setting up cgroupfs-mount (1.2) ...
Setting up runc (1.0.0~rc2+docker1.12.6-0ubuntu1~16.04.1) ...
Setting up containerd (0.2.5-0ubuntu1~16.04.1) ...
Setting up docker.io (1.12.6-0ubuntu1~16.04.1) ...
Adding group `docker' (GID 120) ...
Done.
Setting up ubuntu-fan (0.9.2) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
Downloading the Oracle image from the Docker Store
Now let’s look for an Oracle image available on the Docker Store:
root@devops:~# docker search oracle
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
wnameless/oracle-xe-11g Oracle Express 11g R2 on Ubuntu 16.04 LTS 493 [OK]
oraclelinux Oracle Linux is an open-source operating s... 369 [OK]
frolvlad/alpine-oraclejdk8 The smallest Docker image with OracleJDK 8... 250 [OK]
alexeiled/docker-oracle-xe-11g This is a working (hopefully) Oracle XE 11... 209 [OK]
sath89/oracle-12c Oracle Standard Edition 12c Release 1 with... 163 [OK]
sath89/oracle-xe-11g Oracle xe 11g with database files mount su... 111 [OK]
isuper/java-oracle This repository contains all java releases... 56 [OK]
jaspeen/oracle-11g Docker image for Oracle 11g database 45 [OK]
oracle/openjdk Docker images containing OpenJDK Oracle Linux 22 [OK]
ingensi/oracle-jdk Official Oracle JDK installed on centos. 21 [OK]
oracle/glassfish GlassFish Java EE Application Server on Or... 21 [OK]
airdock/oracle-jdk Docker Image for Oracle Java SDK (8 and 7)... 20 [OK]
cogniteev/oracle-java Oracle JDK 6, 7, 8, and 9 based on Ubuntu ... 19 [OK]
n3ziniuka5/ubuntu-oracle-jdk Ubuntu with Oracle JDK. Check tags for ver... 13 [OK]
oracle/nosql Oracle NoSQL on a Docker Image with Oracle... 12 [OK]
bofm/oracle12c Docker image for Oracle Database 11 [OK]
andreptb/oracle-java Debian Jessie based image with Oracle JDK ... 8 [OK]
openweb/oracle-tomcat A fork off of Official tomcat image with O... 6 [OK]
flurdy/oracle-java7 Base image containing Oracle's Java 7 JDK 4 [OK]
davidcaste/debian-oracle-java Oracle Java 8 (and 7) over Debian Jessie 3 [OK]
teradatalabs/centos6-java8-oracle Docker image of CentOS 6 with Oracle JDK 8... 2
publicisworldwide/oracle-core This is the core image based on Oracle Lin... 1 [OK]
sigma/nimbus-lock-oracle 0 [OK]
spansari/nodejs-oracledb nodejs with oracledb installed globally on... 0
trollin/oraclelinux 0
Let’s download the wnameless/oracle-xe-11g image to use in our container:
root@devops:~# docker pull wnameless/oracle-xe-11g
Using default tag: latest
latest: Pulling from wnameless/oracle-xe-11g
d5c6f90da05d: Already exists
1300883d87d5: Already exists
c220aa3cfc1b: Already exists
2e9398f099dc: Already exists
dc27a084064f: Already exists
5e23a3a5b6f7: Downloading [==============================> ] 167.8MB/275.8MB
efb2b214660e: Downloading [==============================> ] 220MB/364.2MB
The download is done in small parts with the “docker pull” command.
When the download finishes, you can list the downloaded image:
root@devops:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wnameless/oracle-xe-11g latest 5201119f4c27 2 days ago 2.23GB
ubuntu latest ccc7a11d65b1 2 weeks ago 120MB
Starting the oracle container
Now let’s start our container using the wnameless/oracle-xe-11g image:
root@devops:~# docker run -idt --name oracle wnameless/oracle-xe-11g /bin/bash
0125ab1cf799db05acaea00914647612cf70d1f28a454e68bebc64b5e964e325
See that the container is “Up”:
root@devops:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0125ab1cf799 wnameless/oracle-xe-11g "/bin/bash" 43 seconds ago Up 42 seconds 22/tcp, 1521/tcp, 8080/tcp oracle
Working in the oracle container
To switch your session to the oracle container, do:
root@devops:~# docker attach oracle
root@0125ab1cf799:/#
See that the prompt changed to the hostname of the oracle container.
Check that the hosts file is configured with the hostname in question:
root@0125ab1cf799:/# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 0125ab1cf799
Check the IP of the container:
root@0125ab1cf799:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:02
inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:648 (648.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Switch your session to the container’s oracle user:
root@0125ab1cf799:/# su - oracle
oracle@0125ab1cf799:~$
Start the Listener:
oracle@0125ab1cf799:~$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 30-AUG-2017 13:18:24
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.2.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/0125ab1cf799/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=8089fe031125)(PORT=1521)))
TNS-12545: Connect failed because target host or object does not exist
TNS-12560: TNS:protocol adapter error
TNS-00515: Connect failed because target host or object does not exist
Linux Error: 99: Cannot assign requested address
Listener failed to start. See the error message(s) above...
The Listener didn’t start because the listener.ora file is not properly configured for the container’s hostname. See:
oracle@0125ab1cf799:~$ cat /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
# listener.ora Network Configuration File:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
(ADDRESS = (PROTOCOL = TCP)(HOST = 8089fe031125)(PORT = 1521))
)
)
DEFAULT_SERVICE_LISTENER = (XE)
Let’s change it, replacing it with the correct hostname:
oracle@0125ab1cf799:~$ hostname
0125ab1cf799
oracle@0125ab1cf799:~$ sed -i -e 's/8089fe031125/0125ab1cf799/g' \
/u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Try to start it again:
oracle@0125ab1cf799:~$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 30-AUG-2017 13:26:01
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/xe/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.2.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/0125ab1cf799/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0125ab1cf799)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date 30-AUG-2017 13:26:01
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Default Service XE
Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/0125ab1cf799/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0125ab1cf799)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
Finally, open SQL*Plus and start Oracle Database:
oracle@0125ab1cf799:~$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Wed Aug 30 13:27:43 2017
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup;
ORACLE instance started.
Total System Global Area 601272320 bytes
Fixed Size 2228848 bytes
Variable Size 180358544 bytes
Database Buffers 415236096 bytes
Redo Buffers 3448832 bytes
Database mounted.
Database opened.
Well, that’s what I had to show today. The tests are up to you.
To remove the container and the image, run the following commands:
root@devops:~# docker stop oracle
root@devops:~# docker rm oracle
root@devops:~# docker rmi wnameless/oracle-xe-11g
Hugs,
Franky Weber Faust

Pooo eu ia escrever sobre isso, mas vc foi mais rapido kkkkk! Muito bom o/