A Dockerfile for Oracle and perl

I didn’f find a dockerfile for oracle and perl. So I did one by myself.

Quick Instructions: Create dir; Create Dockerfile (above); create oracle_test.pl (above), download the oracle files.

Build it:

docker build -t perl-oracle .

Run it:

docker run -it --rm perl-oracle

I took http://www.ecliptik.com/Containerizing-a-Perl-Script/ as the base and added the information from here: http://www.aboutmonitoring.com/install-dbd-oracle-perl-modules-in-linux/ . To get the 3 Oracle files, you need an Oracle Account and download manualy and put it in your directory.

Your directory should look like this is:

$ ls
Dockerfile
oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm
oracle_test.pl*

with the Dockerfile:

FROM ubuntu:14.04
MAINTAINER Micheal Waltz <ecliptik@gmail.com>
# see http://www.ecliptik.com/Containerizing-a-Perl-Script/

# Dockerfile by Johannes Eiseler 6/2017
# 
# How to build:
# docker build -t perl-oracle .

# How to run:
# docker run -it --rm perl-oracle
# docker run -v /c/Users/myuser/directory/you/like/to/share:/host/directory -it --rm perl-oracle

ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=C.UTF-8 LANGUAGE=en_US.UTF-8

RUN [ "apt-get", "-q", "update" ]
RUN [ "apt-get", "-qy", "--force-yes", "upgrade" ]
RUN [ "apt-get", "-qy", "--force-yes", "dist-upgrade" ]
RUN [ "apt-get", "install", "-qy", "--force-yes", \
      "perl", \
      "build-essential", \
      "cpanminus" ]
RUN [ "apt-get", "clean" ]
RUN [ "rm", "-rf", "/var/lib/apt/lists/*", "/tmp/*", "/var/tmp/*" ]

#RUN ["cpanm", "Proc::ProcessTable", "Data::Dumper" ]

COPY [ "./oracle_test.pl", "/app/oracle_test.pl" ]
RUN [ "chmod", "+x",  "/app/oracle_test.pl" ]

# now Oracle
# see http://www.aboutmonitoring.com/install-dbd-oracle-perl-modules-in-linux/

COPY [ "./*.rpm", "/app/" ]

WORKDIR /app
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "libaio-dev", "libaio1" ]
RUN ["apt-get", "install", "-qy", "--force-yes", "alien" ]

RUN alien --scripts /app/oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
RUN alien --scripts /app/oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm
RUN alien --scripts /app/oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm

RUN dpkg -i /app/oracle-instantclient12.2-basic_12.2.0.1.0-2_amd64.deb
RUN dpkg -i /app/oracle-instantclient12.2-devel_12.2.0.1.0-2_amd64.deb
RUN dpkg -i /app/oracle-instantclient12.2-sqlplus_12.2.0.1.0-2_amd64.deb

ENV PATH $PATH:$HOME/bin:/usr/lib/oracle/12.2/client64/bin
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/lib/oracle/12.2/client64/lib
ENV ORACLE_HOME /usr/lib/oracle/12.2/client64/lib
ENV TNS_ADMIN $ORACLE_HOME/network/admin

# now perl oracle
RUN ["apt-get", "install", "-qy", "--force-yes", "libdbi-perl" ]
RUN ["cpan", "DBD::Oracle"]

# if you wan't to use it interactivly comment the next line
ENTRYPOINT [ "/app/oracle_test.pl" ]

And the perl script oracle_test.pl:

#!/usr/bin/perl

use strict;
use DBI;

#Take Env Variable
my $workdir = $ENV{'MYWORKINGDIR'};  #Takes the variables

print "Hello World\n";

#database

my $db = DBI->connect("dbi:Oracle:host=your.database.host;sid=yoursid;port=yourport","youruser/yourpassword", "") || die( $DBI::errstr . "\n" );

$db->{AutoCommit}    = 0;
$db->{RaiseError}    = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize}  = 16;

my $SEL = "SELECT * FROM dual";
my $sth = $db->prepare($SEL);
$sth->execute();
 
while ( my @row = $sth->fetchrow_array() ) {
    foreach (@row) {
        $_ = "\t" if !defined($_);
        print "$_\t";
    }
    print "\n";
}
 
END {
    $db->disconnect if defined($db);
}


print "----- End of perl file ------\n"

Keywords: Dockerfile, Oracle, Perl, Running perl script connect to oracle

How to use Docker for sqlplus on an Oracle Database

You need a docker installation and a user/password at store.docker.com.

If you got this you can establish a sqlplus session with this docker command:


docker run -ti --rm store/oracle/database-instantclient:12.2.0.1 sqlplus "user/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=your.host.site)(Port=yourport))(CONNECT_DATA=(SID=yoursid)))"

Keywords: docker, oracle, sqlplus, easy