Olá pessoal, aqui num post bem breve vou mostrar como subir o Oracle num container do Docker.
Seguindo a onda DevOps, essa semana estou fazendo um curso e conhecendo algumas ferramentas, o Docker é uma delas.
Até agora não achei utilidade para ele no mundo de banco de dados, mas ainda conheço pouco para opinar a respeito.
Do que se trata o artigo:
Neste artigo será apresentado como usar uma imagem já pronta do Oracle Database 11g XE e executá-la no Docker.
Em que situação o tema é útil:
Esta funcionalidade é útil para aprendizado da tecnologia no Docker. Considere este artigo como uma iniciação na tecnologia em questão, não vou opinar e nem recomendar o seu uso.
Instalação do Docker
O primeiro passo é instalar o Docker no seu ambiente. No meu caso estou usando o 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
Para instalar o Docker execute:
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) ...
Baixando a imagem do Oracle da Docker Store
Agora vamos procurar uma imagem do Oracle disponível na 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
Vamos baixar a imagem wnameless/oracle-xe-11g para utilizá-la no nosso 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
O download é feito em pequenas partes com o comando “docker pull”.
Quando o download concluir você pode listar a imagem baixada:
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
Subindo o container oracle
Agora vamos subir nosso container usando a imagem wnameless/oracle-xe-11g:
root@devops:~# docker run -idt --name oracle wnameless/oracle-xe-11g /bin/bash 0125ab1cf799db05acaea00914647612cf70d1f28a454e68bebc64b5e964e325
Veja que o container está “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
Trabalhando no container oracle
Para alternar sua sessão para o container oracle faça:
root@devops:~# docker attach oracle root@0125ab1cf799:/#
Veja que o prompt mudou para o hostname do container oracle.
Confira se o arquivo hosts está configurado com o hostname em questão:
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
Verifique o IP do 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)
Alterne sua sessão para o usuário oracle do container:
root@0125ab1cf799:/# su - oracle oracle@0125ab1cf799:~$
Inicie o 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...
O Listener não subiu, pois o arquivo listener.ora não está configurado devidamente para o hostname do container. Veja:
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)
Vamos alterá-lo substituindo com o hostname correto:
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
Tente subí-lo novamente:
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
Por fim, acesse o SQL*Plus e inicie o 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.
Bom, era isto que eu tinha para mostrar hoje. Os testes ficam por sua conta.
Para remover o container e a imagem execute os seguintes comandos:
root@devops:~# docker stop oracle root@devops:~# docker rm oracle root@devops:~# docker rmi wnameless/oracle-xe-11g
Abraços,
Franky Weber Faust