Pular para o conteúdo

Rodando o Oracle no Docker

Rodando o Oracle no Docker

Instalação do Docker

O primeiro passo é instalar o Docker no seu ambiente. No meu caso estou usando o Ubuntu 16.04:

root@docker:~# 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@docker:~# 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@docker:~# docker search oracle

Vamos baixar a imagem wnameless/oracle-xe-11g para utilizá-la no nosso container:

root@docker:~# 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@docker:~# 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@docker:~# docker run -idt --name oracle wnameless/oracle-xe-11g /bin/bash

0125ab1cf799db05acaea00914647612cf70d1f28a454e68bebc64b5e964e325

Veja que o container está “Up”:

root@docker:~# 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@docker:~# 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 subi-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 ISTENER
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 
Redo Buffers 3448832 bytes

Database mounted.
Database opened.

Bom, era isso 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

Franky Weber Faust

atua como consultor Oracle, MySQL e SQL Server na NVL IT Agility onde presta serviços para grandes empresas da região sul, tem 25 anos, é graduado em Tecnologia em Bancos de Dados e iniciou sua carreira trabalhando num projeto internacional da Volkswagen com os bancos de dados DB2 da IBM, SQL Server da Microsoft e também com o Oracle e desde o início direcionou seus estudos para as tecnologias Oracle. É especialista em tecnologias de Alta Disponibilidade como RAC, Dataguard e GoldenGate e compartilha seus conhecimentos no blog loredata.com.br. Possui as certificações OCE SQL, OCA 11g, OCP 12c e OCS Linux 6.

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

plugins premium WordPress