Oracle SQL*Plus in a “Small” Docker Container

Table of Contents

Introduction

Some time back I wrote a blog post about SQL*Plus commands. To run those commands, I would use a 15 GiB image of Oracle XE (Express Edition) just to be able to use a command-line tool. Today I stumbled upon Oracle’s Docker images, that are a whole lot smaller.

How to Build Your Own Image

Oracle provides Dockerfiles on its GitHub page. I’m interested in just SQL*Plus so I can change my password on an Oracle database and maybe execute some simple queries. I took a look at this Dockerfile, and modified it slightly to include only what I need:

FROM oraclelinux:7-slim

ARG release=19
ARG update=6

RUN  yum -y install oracle-release-el7 && \
     yum-config-manager --enable ol7_oracle_instantclient && \
     yum -y install oracle-instantclient${release}.${update}-basic \
        oracle-instantclient${release}.${update}-sqlplus && \
     rm -rf /var/cache/yum

CMD ["sqlplus", "-v"]

Build the image and tag it as sqlplus:

$ docker build -t sqlplus .

The image it generates is pretty small, weighing around 370 MB.

(OK, an image based on Alpine should be smaller, but Oracle requires glibc and not musl libc.)

You can create a container and run a SQL*Plus command with:

$ docker run -it sqlplus user/password@db.domain.tld:1521/FOO

Optional: Add tnsnames.ora to the Image

In Oracle, a file name tnsnames.ora contains the connection strings for databases. They allow you to connect to a database using sqlplus without specifying the hostname:

$ sqlplus user/passsword@FOO

Add the tnsnames.ora to the image by putting the following between the RUN and CMD directive in the Dockerfile:

COPY ./tnsnames.ora /root
ENV TNS_ADMIN=/root

Leave a Reply

Your email address will not be published. Required fields are marked *